cloudroam
2025-03-28 cef2bb0eeeb91a22860cf5d23c7348af1ba921dc
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<template>
  <el-bus-crud ref="crud" v-bind="tableConfig" />
</template>
 
<script>
export default {
  data() {
    return {
      tableConfig: {
        url: 'flower/api/banner/page',
        dialogNeedRequest: true,
        persistSelection: true,
        columns: [
          { type: 'selection' },
          { label: 'banner名称', prop: 'name' },
          { label: '图片', formatter: this.formatterImage },
          { label: '应用模块', prop: 'moduleStr' },
          { label: '编辑日期', prop: 'updateTime' },
          { label: '状态', prop: 'statusStr' },
        ],
        searchForm: [
          {
            type: 'row',
            items: [{ label: 'banner名称', id: 'name', type: 'input' }],
          },
        ],
        form: [
          {
            label: 'banner名称:',
            id: 'name',
            type: 'input',
            rules: {
              required: true,
              message: '请输入banner名称',
              trigger: 'blur',
            },
          },
          {
            label: '应用模块:',
            id: 'module',
            type: 'bus-select-dict',
            el: {
              code: 'COMMON_MODULE',
              style: 'width:100%',
            },
            rules: { required: true, message: '请选择应用模块' },
            str: true,
          },
          {
            label: '图片:',
            id: 'url',
            type: 'bus-upload',
            el: {
              listType: 'picture-card',
              limitSize: 2,
              tipText: '大小不超过2M',
            },
            inputFormat: (row) => {
              if ('url' in row) {
                if (row.url) {
                  const url = JSON.parse(row.url)
                  return url.map((item) => ({ url: item }))
                } else {
                  return []
                }
              }
            },
            outputFormat: (val) => {
              return val?.length
                ? JSON.stringify(val.map((item) => item.url))
                : null
            },
            forceDisabled: true,
            rules: { required: true, message: '请上传图片' },
          },
          {
            label: '内容:',
            id: 'content',
            component: 'base-editor',
            richText: true,
            rules: { required: true, message: '请输入内容', trigger: 'blur' },
          },
        ],
        extraButtons: [
          {
            text: (row) => (row.status === 'unpublished' ? '发布' : '下架'),
            atClick: async (row) => {
              const action = row.status === 'unpublished' ? '发布' : '下架'
              try {
                await this.$elBusUtil.confirm(`确定要${action}吗?`)
                const { code } = await this.$elBusHttp.request(
                  'flower/api/banner/page/changeStatus',
                  { params: { id: row.id } }
                )
                if (code === 0) {
                  this.$message.success(`${action}成功`)
                }
              } catch (e) {
                return false
              }
            },
          },
        ],
        headerButtons: [
          {
            text: '批量发布',
            type: 'primary',
            disabled: (selected) =>
              selected.filter((item) => item.status === 'unpublished')
                .length === 0,
            atClick: async (selected) => {
              const selectedNotice = selected.filter(
                (item) => item.status === 'unpublished'
              )
              try {
                await this.$elBusUtil.confirm(
                  `确定要批量发布这${selectedNotice.length}个banner吗?`
                )
                const { code } = await this.$elBusHttp.request(
                  'flower/api/banner/page/publish/batch',
                  {
                    method: 'post',
                    data: {
                      ids: selected.map((item) => item.id),
                    },
                  }
                )
                if (code === 0) {
                  this.$message.success('操作成功')
                  this.$refs.crud.clearSelection()
                }
              } catch (e) {
                return false
              }
            },
          },
          {
            text: '批量删除',
            type: 'danger',
            disabled: (selected) => selected.length === 0,
            atClick: async (selected) => {
              try {
                await this.$elBusUtil.confirm(
                  `确定要批量删除这${selected.length}个banner吗?`
                )
                const { code } = await this.$elBusHttp.request(
                  'flower/api/banner/page/delete/batch',
                  {
                    method: 'post',
                    data: {
                      ids: selected.map((item) => item.id),
                    },
                  }
                )
                if (code === 0) {
                  this.$message.success('操作成功')
                  this.$refs.crud.clearSelection()
                }
              } catch (e) {
                return false
              }
            },
          },
        ],
      },
    }
  },
  head() {
    return {
      title: 'banner管理',
    }
  },
  methods: {
    formatterImage(row) {
      if (row.url) {
        try {
          const url = JSON.parse(row.url)
          if (Array.isArray(url) && url.length > 0) {
            return <el-bus-image src={url[0]} style="width:150px" lazy={true} />
          }
        } catch (e) {
          return null
        }
      }
      return null
    },
  },
}
</script>
 
<style lang="scss" scoped>
::v-deep {
  .el-upload {
    &-list__item {
      width: 345px;
      height: 128px;
    }
    &.el-upload--picture-card {
      width: 345px;
      height: 128px;
    }
  }
}
</style>