Blame view
src/views/prod/list.vue
17 KB
5cb375940 auto commit the c... |
1 2 |
<template> <div class="app-container"> |
8a0e4eede 产品列表页 |
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
<div class="filter-container"> <!-- 搜索input --> <el-input v-model="listQuery.title" :placeholder="$t('table.title')" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" /> <!-- type选择 --> <el-select v-model="listQuery.type" :placeholder="$t('table.type')" clearable class="filter-item" style="width: 110px" > <el-option v-for="item in calendarTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" /> </el-select> <!-- imp选择 --> <el-select v-model="listQuery.importance" :placeholder="$t('table.importance')" clearable filterable style="width: 130px" class="filter-item" > <!-- 分组tag筛选 --> <el-option-group v-for="group in importanceOptions" :key="group.label" :label="group.label" > <el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item.value" /> </el-option-group> </el-select> <!-- 排序 --> <el-select v-model="listQuery.sort" style="width: 140px" class="filter-item" @change="handleFilter" > <el-option v-for="item in sortOptions" :key="item.key" :label="item.label" :value="item.key" /> </el-select> <!-- search按钮 --> <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter" > {{ $t('table.search') }} </el-button> <!-- add按钮 --> <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate" > {{ $t('table.add') }} </el-button> <!-- 导出为excel按钮 --> <el-button v-waves :loading="downloadLoading" class="filter-item" type="primary" icon="el-icon-download" @click="handleDownload" > {{ $t('table.export') }} </el-button> <!-- 是否显示审核人 --> <el-checkbox v-model="showReviewer" class="filter-item" style="margin-left:15px;" @change="tableKey=tableKey+1" > {{ $t('table.reviewer') }} </el-checkbox> </div> <!-- 表格 --> |
5cb375940 auto commit the c... |
108 |
<el-table |
8a0e4eede 产品列表页 |
109 |
:key="tableKey" |
5cb375940 auto commit the c... |
110 111 |
v-loading="listLoading" :data="list" |
5cb375940 auto commit the c... |
112 113 114 |
border fit highlight-current-row |
8a0e4eede 产品列表页 |
115 116 |
style="width: 100%;" @sort-change="sortChange" |
5cb375940 auto commit the c... |
117 |
> |
8a0e4eede 产品列表页 |
118 |
<!-- id列 --> |
5cb375940 auto commit the c... |
119 |
<el-table-column |
8a0e4eede 产品列表页 |
120 121 122 |
:label="$t('table.id')" prop="id" sortable="custom" |
5cb375940 auto commit the c... |
123 |
align="center" |
04e55fcfe auto commit the c... |
124 |
width="80" |
8a0e4eede 产品列表页 |
125 |
:class-name="getSortClass('id')" |
5cb375940 auto commit the c... |
126 |
> |
8a0e4eede 产品列表页 |
127 128 |
<template slot-scope="{row}"> <span>{{ row.id }}</span> |
5cb375940 auto commit the c... |
129 130 |
</template> </el-table-column> |
8a0e4eede 产品列表页 |
131 |
<!-- date列 --> |
5cb375940 auto commit the c... |
132 |
<el-table-column |
8a0e4eede 产品列表页 |
133 134 |
:label="$t('table.date')" width="150px" |
5cb375940 auto commit the c... |
135 |
align="center" |
5cb375940 auto commit the c... |
136 |
> |
8a0e4eede 产品列表页 |
137 138 |
<template slot-scope="{row}"> <span>{{ row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span> |
5cb375940 auto commit the c... |
139 140 |
</template> </el-table-column> |
8a0e4eede 产品列表页 |
141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
<!-- title列 --> <el-table-column :label="$t('table.title')" min-width="150px" > <template slot-scope="{row}"> <span class="link-type" @click="handleUpdate(row)" >{{ row.title }}</span> <el-tag>{{ row.type | typeFilter }}</el-tag> </template> </el-table-column> <!-- author列 --> |
5cb375940 auto commit the c... |
155 |
<el-table-column |
8a0e4eede 产品列表页 |
156 157 |
:label="$t('table.author')" width="110px" |
5cb375940 auto commit the c... |
158 |
align="center" |
5cb375940 auto commit the c... |
159 |
> |
8a0e4eede 产品列表页 |
160 161 162 163 164 165 166 167 168 169 170 171 172 |
<template slot-scope="{row}"> <span>{{ row.author }}</span> </template> </el-table-column> <!-- reviewer列 --> <el-table-column v-if="showReviewer" :label="$t('table.reviewer')" width="110px" align="center" > <template slot-scope="{row}"> <span style="color:red;">{{ row.reviewer }}</span> |
5cb375940 auto commit the c... |
173 174 |
</template> </el-table-column> |
5cb375940 auto commit the c... |
175 |
<el-table-column |
8a0e4eede 产品列表页 |
176 177 |
:label="$t('table.importance')" width="80px" |
5cb375940 auto commit the c... |
178 |
> |
8a0e4eede 产品列表页 |
179 |
<template slot-scope="{row}"> |
5cb375940 auto commit the c... |
180 |
<svg-icon |
8a0e4eede 产品列表页 |
181 |
v-for="n in +row.importance" |
5cb375940 auto commit the c... |
182 183 |
:key="n" icon-class="star" |
04e55fcfe auto commit the c... |
184 |
class="meta-item__icon" |
5cb375940 auto commit the c... |
185 186 187 |
/> </template> </el-table-column> |
8a0e4eede 产品列表页 |
188 |
<!-- 阅读数列 --> |
5cb375940 auto commit the c... |
189 |
<el-table-column |
8a0e4eede 产品列表页 |
190 191 192 |
:label="$t('table.readings')" align="center" width="95" |
5cb375940 auto commit the c... |
193 194 |
> <template slot-scope="{row}"> |
8a0e4eede 产品列表页 |
195 196 197 198 199 200 |
<span v-if="row.pageviews" class="link-type" @click="handleFetchPv(row.pageviews)" >{{ row.pageviews }}</span> <span v-else>0</span> |
5cb375940 auto commit the c... |
201 202 |
</template> </el-table-column> |
8a0e4eede 产品列表页 |
203 |
<!-- 状态列 --> |
5cb375940 auto commit the c... |
204 |
<el-table-column |
8a0e4eede 产品列表页 |
205 206 207 |
:label="$t('table.status')" class-name="status-col" width="100" |
04e55fcfe auto commit the c... |
208 209 |
> <template slot-scope="{row}"> |
8a0e4eede 产品列表页 |
210 211 212 |
<el-tag :type="row.status | statusFilter"> {{ row.status }} </el-tag> |
04e55fcfe auto commit the c... |
213 214 |
</template> </el-table-column> |
8a0e4eede 产品列表页 |
215 |
<!-- 操作列 --> |
04e55fcfe auto commit the c... |
216 |
<el-table-column |
8a0e4eede 产品列表页 |
217 |
:label="$t('table.actions')" |
5cb375940 auto commit the c... |
218 |
align="center" |
8a0e4eede 产品列表页 |
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
width="230" class-name="small-padding fixed-width" > <template slot-scope="{row,$index}"> <el-button type="primary" size="mini" @click="handleUpdate(row)" > {{ $t('table.edit') }} </el-button> <el-button v-if="row.status!='published'" size="mini" type="success" @click="handleModifyStatus(row,'published')" > {{ $t('table.publish') }} </el-button> <el-button v-if="row.status!='draft'" size="mini" @click="handleModifyStatus(row,'draft')" > {{ $t('table.draft') }} </el-button> <el-button v-if="row.status!='deleted'" size="mini" type="danger" @click="handleDelete(row,$index)" > {{ $t('table.delete') }} </el-button> |
5cb375940 auto commit the c... |
253 254 255 |
</template> </el-table-column> </el-table> |
04e55fcfe auto commit the c... |
256 |
|
8a0e4eede 产品列表页 |
257 |
<!-- 分页器 --> |
04e55fcfe auto commit the c... |
258 259 260 261 262 263 264 |
<pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" /> |
8a0e4eede 产品列表页 |
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
<el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" > <el-form ref="dataForm" :rules="rules" :model="temp" label-position="left" label-width="70px" style="width: 400px; margin-left:50px;" > <el-form-item :label="$t('table.type')" prop="type" > <el-select v-model="temp.type" class="filter-item" placeholder="Please select" > <el-option v-for="item in calendarTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" /> </el-select> </el-form-item> <el-form-item :label="$t('table.date')" prop="timestamp" > <el-date-picker v-model="temp.timestamp" type="datetime" placeholder="Please pick a date" /> </el-form-item> <el-form-item :label="$t('table.title')" prop="title" > <el-input v-model="temp.title" /> </el-form-item> <el-form-item :label="$t('table.status')"> <el-select v-model="temp.status" class="filter-item" placeholder="Please select" > <el-option v-for="item in statusOptions" :key="item" :label="item" :value="item" /> </el-select> </el-form-item> <el-form-item :label="$t('table.importance')"> <el-rate v-model="temp.importance" :colors="['#99A9BF', '#F7BA2A', '#FF9900']" :max="3" style="margin-top:8px;" /> </el-form-item> <el-form-item :label="$t('table.remark')"> <el-input v-model="temp.remark" :autosize="{ minRows: 2, maxRows: 4}" type="textarea" placeholder="Please input" /> </el-form-item> </el-form> <div slot="footer" class="dialog-footer" > <el-button @click="dialogFormVisible = false"> {{ $t('table.cancel') }} </el-button> <el-button type="primary" @click="dialogStatus==='create'?createData():updateData()" > {{ $t('table.confirm') }} </el-button> </div> </el-dialog> <el-dialog :visible.sync="dialogPvVisible" title="Reading statistics" > <el-table :data="pvData" border fit highlight-current-row style="width: 100%" > <el-table-column prop="key" label="Channel" /> <el-table-column prop="pv" label="Pv" /> </el-table> <span slot="footer" class="dialog-footer" > <el-button type="primary" @click="dialogPvVisible = false" >{{ $t('table.confirm') }}</el-button> </span> </el-dialog> |
5cb375940 auto commit the c... |
388 389 390 391 |
</div> </template> <script> |
8a0e4eede 产品列表页 |
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
import { fetchList, fetchPv, createArticle, updateArticle } from '@/api/article' import waves from '@/directive/waves' // waves directive import { parseTime } from '@/utils' import Pagination from '@/components/Pagination' // secondary package based on el-pagination const calendarTypeOptions = [ { key: 'CN', display_name: '成镜' }, { key: 'US', display_name: '镜片' }, { key: 'JP', display_name: '隐形眼镜' }, { key: 'EU', display_name: '特种镜' } ] // arr to obj, such as { CN : "China", US : "USA" } const calendarTypeKeyValue = calendarTypeOptions.reduce((acc, cur) => { acc[cur.key] = cur.display_name return acc }, {}) |
5cb375940 auto commit the c... |
414 415 |
export default { |
8a0e4eede 产品列表页 |
416 |
name: 'ComplexTable', |
04e55fcfe auto commit the c... |
417 |
components: { Pagination }, |
8a0e4eede 产品列表页 |
418 |
directives: { waves }, |
5cb375940 auto commit the c... |
419 420 421 422 423 424 425 426 |
filters: { statusFilter(status) { const statusMap = { published: 'success', draft: 'info', deleted: 'danger' } return statusMap[status] |
8a0e4eede 产品列表页 |
427 428 429 |
}, typeFilter(type) { return calendarTypeKeyValue[type] |
5cb375940 auto commit the c... |
430 431 432 433 |
} }, data() { return { |
8a0e4eede 产品列表页 |
434 |
tableKey: 0, |
5cb375940 auto commit the c... |
435 |
list: null, |
04e55fcfe auto commit the c... |
436 |
total: 0, |
5cb375940 auto commit the c... |
437 438 439 |
listLoading: true, listQuery: { page: 1, |
8a0e4eede 产品列表页 |
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
limit: 20, importance: undefined, title: undefined, type: undefined, sort: '+id' }, importanceOptions: [{ label: '款式索引', options: [{ value: 'young', label: '青春学子风' }, { value: 'leisure', label: '休闲' }, { value: 'business', label: '商务' }, { value: 'Retro', label: '复古' }, { value: 'fashion', label: '时尚' }] }, { label: '颜色', options: [{ value: 'golden', label: '金色' }, { value: 'silver', label: '银色' }, { value: 'black', label: '黑色' }, { value: 'multicolour', label: '彩色' }, { value: 'gun', label: '枪色' }] }], calendarTypeOptions, sortOptions: [ { label: 'ID Ascending', key: '+id' }, { label: 'ID Descending', key: '-id' } ], statusOptions: ['published', 'draft', 'deleted'], showReviewer: false, temp: { id: undefined, importance: 1, remark: '', timestamp: new Date(), title: '', type: '', status: 'published' }, dialogFormVisible: false, dialogStatus: '', textMap: { update: 'Edit', create: 'Create' }, dialogPvVisible: false, pvData: [], rules: { type: [ { required: true, message: 'type is required', trigger: 'change' } ], timestamp: [ { type: 'date', required: true, message: 'timestamp is required', trigger: 'change' } ], title: [ { required: true, message: 'title is required', trigger: 'blur' } ] }, downloadLoading: false |
5cb375940 auto commit the c... |
524 525 526 527 528 529 |
} }, created() { this.getList() }, methods: { |
04e55fcfe auto commit the c... |
530 |
getList() { |
5cb375940 auto commit the c... |
531 |
this.listLoading = true |
04e55fcfe auto commit the c... |
532 533 534 |
fetchList(this.listQuery).then(response => { this.list = response.data.items this.total = response.data.total |
8a0e4eede 产品列表页 |
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 |
// Just to simulate the time of the request setTimeout(() => { this.listLoading = false }, 1.5 * 1000) }) }, handleFilter() { this.listQuery.page = 1 this.getList() }, handleModifyStatus(row, status) { this.$message({ message: '操作成功', type: 'success' }) row.status = status }, sortChange(data) { const { prop, order } = data if (prop === 'id') { this.sortByID(order) } }, sortByID(order) { if (order === 'ascending') { this.listQuery.sort = '+id' } else { this.listQuery.sort = '-id' } this.handleFilter() }, resetTemp() { this.temp = { id: undefined, importance: 1, remark: '', timestamp: new Date(), title: '', status: 'published', type: '' } }, handleCreate() { this.resetTemp() this.dialogStatus = 'create' this.dialogFormVisible = true this.$nextTick(() => { this.$refs['dataForm'].clearValidate() |
5cb375940 auto commit the c... |
584 |
}) |
8a0e4eede 产品列表页 |
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
}, createData() { this.$refs['dataForm'].validate(valid => { if (valid) { this.temp.id = parseInt(Math.random() * 100) + 1024 // mock a id this.temp.author = '秀野堂主' createArticle(this.temp).then(() => { this.list.unshift(this.temp) this.dialogFormVisible = false this.$notify({ title: '成功', message: '创建成功', type: 'success', duration: 2000 }) }) } }) }, handleUpdate(row) { this.temp = Object.assign({}, row) // copy obj this.temp.timestamp = new Date(this.temp.timestamp) this.dialogStatus = 'update' this.dialogFormVisible = true this.$nextTick(() => { this.$refs['dataForm'].clearValidate() }) }, updateData() { this.$refs['dataForm'].validate(valid => { if (valid) { const tempData = Object.assign({}, this.temp) tempData.timestamp = +new Date(tempData.timestamp) // change Thu Nov 30 2017 16:41:05 GMT+0800 (CST) to 1512031311464 updateArticle(tempData).then(() => { const index = this.list.findIndex(v => v.id === this.temp.id) this.list.splice(index, 1, this.temp) this.dialogFormVisible = false this.$notify({ title: '成功', message: '更新成功', type: 'success', duration: 2000 }) }) } }) }, handleDelete(row, index) { this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 }) this.list.splice(index, 1) }, handleFetchPv(pv) { fetchPv(pv).then(response => { this.pvData = response.data.pvData this.dialogPvVisible = true }) }, handleDownload() { this.downloadLoading = true import('@/vendor/Export2Excel').then(excel => { const tHeader = ['timestamp', 'title', 'type', 'importance', 'status'] const filterVal = [ 'timestamp', 'title', 'type', 'importance', 'status' ] const data = this.formatJson(filterVal) excel.export_json_to_excel({ header: tHeader, data, filename: 'table-list' }) this.downloadLoading = false }) }, formatJson(filterVal) { return this.list.map(v => filterVal.map(j => { if (j === 'timestamp') { return parseTime(v[j]) } else { return v[j] } }) ) }, getSortClass: function(key) { const sort = this.listQuery.sort return sort === `+${key}` ? 'ascending' : 'descending' |
5cb375940 auto commit the c... |
681 682 683 684 |
} } } </script> |