1
2
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
| <template>
| <el-bus-crud ref="crud" v-bind="tableConfig" />
| </template>
|
| <script>
| import cloneDeep from 'lodash.clonedeep'
| import { getSortConfig } from '@/utils/form-item-config'
| export default {
| data() {
| return {
| originalList: [],
| expandIds: [],
| tableConfig: {
| url: 'flower/api/film/category/tree',
| hasPagination: false,
| saveQuery: false,
| isTree: true,
| hasView: false,
| canNewChild: (row) => !row.parentId,
| dialogAttrs: {
| width: '70%',
| },
| afterRequest: (list) => {
| this.originalList = cloneDeep(list)
| this.expandIds = this.expandIds.filter((i) =>
| list.find((item) => item.id === i)
| )
| return list.map((i) => ({
| ...i,
| childrenCount: Array.isArray(i.children) ? i.children.length : 0,
| children: this.expandIds.includes(i.id)
| ? i.children
| : i.children.slice(0, 1),
| }))
| },
| tableEventHandlers: {
| expandChange: (row, expand) => {
| if (expand) {
| if (!this.expandIds.includes(row.id)) {
| this.expandIds.push(row.id)
| }
| row.children =
| this.originalList.find((i) => i.id === row.id)?.children || []
| } else {
| const index = this.expandIds.indexOf(row.id)
| if (index !== -1) {
| this.expandIds.splice(index, 1)
| }
| }
| },
| },
| beforeOpen(row, isNew) {
| if (isNew && row.name) {
| row.parentName = row.name
| }
| if (!isNew && !row.parentId && row.parentName) {
| row.parentName = ''
| }
| },
| extraParentKeys: ['parentName', 'levelLimit'],
| tableAttrs: {
| rowKey: 'id',
| },
| columns: [
| { label: '板块名称', prop: 'name' },
| {
| label: '板块图片',
| formatter: (row) => (
| <el-bus-image
| style="width:50px;height:50px"
| lazy={true}
| src={row.imageUrl}
| />
| ),
| },
| { label: '排序', prop: 'sortBy' },
| { label: '子板块数量', formatter: (row) => row.childrenCount },
| {
| label: '是否显示',
| formatter: (row) => (
| <el-switch
| value={row.shown}
| onChange={this.onShownChange.bind(this, row)}
| ></el-switch>
| ),
| },
| ],
| searchForm: [
| {
| type: 'row',
| items: [{ label: '板块名称', id: 'name', type: 'input' }],
| },
| ],
| form: [
| {
| label: '上级板块:',
| id: 'parentName',
| type: 'input',
| readonly: true,
| hidden: (row) => !row.parentName,
| },
| {
| label: '板块名称:',
| id: 'name',
| type: 'input',
| rules: {
| required: true,
| message: '请输入板块名称',
| trigger: 'blur',
| },
| },
| {
| label: '板块图片:',
| id: 'imageUrl',
| type: 'bus-upload',
| el: {
| listType: 'picture-card',
| limit: 1,
| limitSize: 2,
| tipText: '建议上传164*164的图片,大小不超过2M',
| valueType: 'string',
| },
| rules: { required: false, message: '请上传板块图片' },
| },
| {
| ...getSortConfig(),
| },
| ],
| },
| }
| },
| head() {
| return {
| title: '片场板块管理',
| }
| },
| methods: {
| onShownChange(row, e) {
| const url = e
| ? 'flower/api/film/category/tree/shown'
| : 'film/api/film/category/tree/hidden'
| const text = e ? '显示' : '隐藏'
| this.$elBusUtil
| .confirm(`确定要${text}这个板块吗?`)
| .then(async () => {
| const { code } = await this.$elBusHttp.request(url, {
| params: {
| id: row.id,
| },
| })
| if (code === 0) {
| this.$message.success(`${text}成功`)
| this.$refs.crud.getList()
| }
| })
| .catch(() => {})
| },
| },
| }
| </script>
|
| <style lang="scss" scoped>
| .category-list {
| }
| </style>
|
|