Преглед на файлове

角色列表修改为接口获取

木星 преди 1 месец
родител
ревизия
99b98cfbff
променени са 2 файла, в които са добавени 447 реда и са изтрити 41 реда
  1. 27 41
      src/views/Authority/Role.vue
  2. 420 0
      src/views/Material/MaterialManage.vue

+ 27 - 41
src/views/Authority/Role.vue

@@ -218,48 +218,34 @@ const tianjiabox = () => {
218 218
 }
219 219
 const tianjia = async () => {
220 220
   let res = await getAuthTree()
221
-  console.log('kanjiiiiiiii', res)
222
-  //处理树状结构
223
-  const transformedData = [
224
-    {
225
-      label: '模板管理',
226
-      id: 1,
227
-      value: [2, 1]
228
-    },
229
-    {
230
-      label: '资源管理',
231
-      id: 2,
232
-      value: [4, 3]
233
-    },
234
-    {
235
-      label: '审核管理',
236
-      id: 3,
237
-      value: [6, 5]
238
-    },
239
-    {
240
-      label: '权限管理',
241
-      id: 4,
242
-      value: [7],
243
-      children: [
244
-        {
245
-          label: '用户管理',
246
-          id: 5,
247
-          value: 8
248
-        },
249
-        {
250
-          label: '角色管理',
251
-          id: 6,
252
-          value: 9
253
-        }
254
-      ]
255
-    },
256
-    {
257
-      label: '系统设置',
258
-      id: 7,
259
-      value: [11, 10]
260
-    }
261
-  ]
262 221
 
222
+  const transformedData: any = []
223
+
224
+  res.data.map((item, index) => {
225
+    if (item.children.length == 1) {
226
+      let a1 = {
227
+        label: item.name,
228
+        id: index,
229
+        value: [item.id, item.children.id]
230
+      }
231
+      transformedData.push(a1)
232
+    } else {
233
+      let a1 = {
234
+        label: item.name,
235
+        id: item.id,
236
+        value: item.id,
237
+        children: item.children.map((item2, index) => {
238
+          let a2 = {
239
+            label: item2.name,
240
+            id: index,
241
+            value: [item2.id]
242
+          }
243
+          return a2
244
+        })
245
+      }
246
+      transformedData.push(a1)
247
+    }
248
+  })
263 249
   data = transformedData
264 250
   isshow.value = false
265 251
 }

+ 420 - 0
src/views/Material/MaterialManage.vue

@@ -0,0 +1,420 @@
1
+<!--
2
+ * @Author: 半生瓜 1515706227@qq.com
3
+ * @Date: 2024-05-06 19:31:40
4
+ * @LastEditors: 半生瓜 1515706227@qq.com
5
+ * @LastEditTime: 2024-05-28 00:03:36
6
+ * @FilePath: \vue-element-plus-admin-mini\src\views\zy\Menu12.vue
7
+ * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
8
+-->
9
+<script setup lang="tsx">
10
+import { ElInput } from 'element-plus'
11
+import { ref } from 'vue'
12
+import { Dialog } from '@/components/Dialog'
13
+import { ContentWrap } from '@/components/ContentWrap'
14
+import { useI18n } from '@/hooks/web/useI18n'
15
+import { Table, TableColumn, TableSlotDefault } from '@/components/Table'
16
+import { upTemplate, saveTemplate } from '@/api/table'
17
+import { saveResource, getResource, deleteResource } from '@/api/resource'
18
+import { reactive, unref } from 'vue'
19
+import { ElButton, ElMessageBox, ElMessage, ElIcon } from 'element-plus'
20
+import { useTable } from '@/hooks/web/useTable'
21
+import { Search, Edit, Delete } from '@element-plus/icons-vue'
22
+import { useValidator } from '@/hooks/web/useValidator'
23
+import { Form, FormSchema } from '@/components/Form'
24
+import { useForm } from '@/hooks/web/useForm'
25
+import { BaseButton } from '@/components/Button'
26
+import { useUserStore } from '@/store/modules/user'
27
+import { log } from 'console'
28
+const PATH_URL = window.VITE_API_BASE_PATH
29
+
30
+const { required } = useValidator()
31
+const text = ref('')
32
+const userStore = useUserStore()
33
+defineOptions({
34
+  name: 'TemplateManage'
35
+})
36
+
37
+const compare = ref('')
38
+
39
+const { tableRegister, tableState, tableMethods } = useTable({
40
+  fetchDataApi: async () => {
41
+    const { currentPage, pageSize } = tableState
42
+    const res = await getResource({
43
+      page: unref(currentPage),
44
+      pageSize: unref(pageSize),
45
+      name: unref(text)
46
+    })
47
+    res.data.content.map((item) => {
48
+      console.log('opopopop', item)
49
+      item.icon = PATH_URL + item.icon
50
+    })
51
+    return {
52
+      list: res.data.content,
53
+      total: res.data.totalElements
54
+    }
55
+  }
56
+})
57
+
58
+const { loading, dataList, total, currentPage, pageSize } = tableState
59
+
60
+const { refresh, getElTableExpose } = tableMethods
61
+
62
+const { t } = useI18n()
63
+
64
+const columns = reactive<TableColumn[]>([
65
+  {
66
+    field: 'selection',
67
+    type: 'selection'
68
+  },
69
+  {
70
+    field: 'index',
71
+    label: t('tableDemo.index'),
72
+    type: 'index'
73
+  },
74
+  {
75
+    field: 'categoryName',
76
+    label: '资源库分类'
77
+  },
78
+  {
79
+    field: 'icon',
80
+    label: '图标'
81
+  },
82
+  {
83
+    field: 'modelCount',
84
+    label: '对象数量'
85
+  },
86
+
87
+  {
88
+    field: 'action',
89
+    label: t('tableDemo.action'),
90
+    slots: {
91
+      default: (data) => {
92
+        return (
93
+          <>
94
+            <ElButton type="primary" onClick={() => edittab(data)}>
95
+              {t('tableDemo.edit')}
96
+            </ElButton>
97
+            <ElButton type="danger" onClick={() => deletetab(data)}>
98
+              {t('tableDemo.delete')}
99
+            </ElButton>
100
+          </>
101
+        )
102
+      }
103
+    }
104
+  }
105
+])
106
+const imageUrl = ref('')
107
+const isedit = ref('添加')
108
+//删除
109
+const deletetab = async (data: TableSlotDefault) => {
110
+  ElMessageBox.confirm('确定删除该数据?')
111
+    .then(async () => {
112
+      let arr = {
113
+        categoryId: [data.row.categoryId]
114
+      }
115
+      const res = await deleteResource(arr)
116
+      refresh()
117
+      refresh()
118
+      if (res.code == 200) {
119
+        ElMessage.success('删除成功')
120
+      }
121
+      refresh()
122
+    })
123
+    .catch(() => {
124
+      // catch error
125
+    })
126
+}
127
+
128
+const dialogVisible = ref(false)
129
+
130
+const token = userStore.getToken
131
+const Authorization = `Bearer ${token}`
132
+const headers = ref({ Authorization: Authorization })
133
+
134
+const { formRegister, formMethods } = useForm()
135
+const { getElFormExpose, getFormData } = formMethods
136
+
137
+const schema = reactive<FormSchema[]>([
138
+  {
139
+    field: 'categoryName',
140
+    label: '资源分类',
141
+    component: 'Input',
142
+    colProps: {
143
+      span: 24
144
+    },
145
+    componentProps: {
146
+      style: {
147
+        width: '100%'
148
+      },
149
+      placeholder: '请输入资源名称'
150
+    },
151
+    formItemProps: {
152
+      rules: [required()]
153
+    }
154
+  },
155
+  {
156
+    field: 'icon',
157
+    component: 'Upload',
158
+    colProps: {
159
+      span: 24
160
+    },
161
+    label: '图标',
162
+    formItemProps: {
163
+      rules: [required()]
164
+    },
165
+    componentProps: {
166
+      action: PATH_URL + '/resource/manage/uploadImg',
167
+      headers: headers,
168
+      showFileList: false,
169
+      onSuccess: async (_response, uploadFile) => {
170
+        imageUrl.value = URL.createObjectURL(uploadFile.raw!)
171
+        const formData = await getFormData()
172
+        formData.icon = _response.data
173
+      },
174
+      beforeUpload: (rawFile) => {
175
+        console.log('kankangeshi', rawFile)
176
+        if (rawFile.type !== 'image/png' && rawFile.type !== 'image/jpeg') {
177
+          ElMessage.error('上传格式:png、jpg!')
178
+          return false
179
+        }
180
+        return true
181
+      },
182
+      slots: {
183
+        default: () => (
184
+          <>
185
+            {imageUrl.value ? <img src={imageUrl.value} class="avatar" /> : null}
186
+            {!imageUrl.value ? (
187
+              <ElIcon class="avatar-uploader-icon" size="large" style="font-size: 50px">
188
+                +
189
+              </ElIcon>
190
+            ) : null}
191
+          </>
192
+        ),
193
+        tip: () => <div class="el-upload__tip">上传格式:png、jpg,大小:56x56px;</div>
194
+      }
195
+    }
196
+  },
197
+  {
198
+    field: 'compressFilePath',
199
+    component: 'Upload',
200
+    label: '资源内容',
201
+    colProps: {
202
+      span: 24
203
+    },
204
+    componentProps: {
205
+      limit: 1,
206
+      action: PATH_URL + '/resource/manage/addModelCompress',
207
+      headers: headers,
208
+      fileList: [],
209
+      multiple: true,
210
+      onPreview: (uploadFile) => {
211
+        console.log(uploadFile)
212
+      },
213
+      onRemove: async (file) => {
214
+        const formData = await getFormData()
215
+        formData.compressFilePath = ''
216
+        formData.compressFileName = ''
217
+        formData.uploadCompress = false
218
+      },
219
+      onSuccess: async (_response, uploadFile) => {
220
+        console.log('kankan_response', uploadFile)
221
+        const formData = await getFormData()
222
+        formData.compressFilePath = _response.data
223
+        formData.compressFileName = uploadFile.name
224
+      },
225
+      beforeRemove: (uploadFile) => {},
226
+      onExceed: (files, uploadFiles) => {
227
+        ElMessage.warning('只能上传一个资源,请移除后重新上传')
228
+      },
229
+      beforeUpload: (rawFile) => {
230
+        console.log('kokokoko', rawFile)
231
+        if (rawFile.type !== 'application/x-zip-compressed' && rawFile.name.indexOf('.rar') == -1) {
232
+          ElMessage.error('只能上传RAR、ZIP文件')
233
+          return false
234
+        }
235
+        return true
236
+      },
237
+      slots: {
238
+        default: () => <BaseButton type="primary">点击上传</BaseButton>,
239
+        tip: () => <div class="el-upload__tip">文件类型:RAR\ZIP</div>
240
+      }
241
+    }
242
+  }
243
+])
244
+
245
+//编辑
246
+const edittab = async (data: TableSlotDefault) => {
247
+  console.log('shanchu', data)
248
+  isedit.value = '编辑'
249
+  dialogVisible.value = true
250
+  const formRef = await getElFormExpose()
251
+  const formData = await getFormData()
252
+  formData.categoryName = data.row.categoryName
253
+  formData.compressFileName = data.row.compressFileName
254
+  formData.compressFilePath = data.row.compressFilePath
255
+  compare.value = data.row.compressFilePath
256
+  formData.icon = data.row.icon.replace(PATH_URL, '')
257
+  imageUrl.value = data.row.icon
258
+  formData.categoryId = data.row.categoryId
259
+  schema[2].componentProps.fileList = [
260
+    {
261
+      name: data.row.compressFileName,
262
+      url: data.row.compressFilePath
263
+    }
264
+  ]
265
+}
266
+// 添加编辑模板管理
267
+const signIn = async () => {
268
+  const formRef = await getElFormExpose()
269
+  const formData = await getFormData()
270
+  console.log('lplplp', formData.compressFilePath)
271
+  if (
272
+    formData.compressFilePath !== compare.value &&
273
+    formData.compressFilePath !== '' &&
274
+    formData.compressFilePath
275
+  ) {
276
+    formData.uploadCompress = true
277
+  } else {
278
+    formData.uploadCompress = false
279
+  }
280
+  //如果是编辑去掉icon的拼接
281
+  console.log('kakkkkak', formData)
282
+  await formRef?.validate(async (isValid) => {
283
+    if (isValid) {
284
+      const res = await saveResource(formData)
285
+      if (res) {
286
+        dialogVisible.value = false
287
+        refresh()
288
+      }
289
+    }
290
+  })
291
+}
292
+
293
+//搜索
294
+const handersearch = function () {
295
+  tableState.currentPage.value = 1
296
+  refresh()
297
+}
298
+
299
+//多选删除
300
+const getSelections = async () => {
301
+  const elTableRef = await getElTableExpose()
302
+  const selections = elTableRef?.getSelectionRows()
303
+
304
+  let arr = {
305
+    categoryId: []
306
+  }
307
+  if (selections) {
308
+    arr.categoryId = selections.map((item) => {
309
+      return item.categoryId
310
+    })
311
+  }
312
+  if (arr.categoryId.length !== 0) {
313
+    ElMessageBox.confirm('确定删除所选数据?')
314
+      .then(async () => {
315
+        console.log('kankan', arr)
316
+        const res = await deleteResource(arr)
317
+        console.log('kkkkkkss', res)
318
+        if (res.code == 200) {
319
+          ElMessage.success('删除成功')
320
+        }
321
+        refresh()
322
+      })
323
+      .catch(() => {
324
+        // catch error
325
+      })
326
+  } else {
327
+    ElMessage.warning('请选择数据')
328
+  }
329
+}
330
+const tianjia = async () => {
331
+  imageUrl.value = ''
332
+  isedit.value = '添加'
333
+  schema[2].componentProps.fileList = []
334
+  dialogVisible.value = true
335
+  compare.value = ''
336
+}
337
+</script>
338
+
339
+<template>
340
+  <ContentWrap>
341
+    <div style="margin-bottom: 10px">
342
+      <span style="color: #606266"> 资源分类:</span>
343
+      <el-input
344
+        v-model="text"
345
+        style="width: 200px; height: 43px; margin: 7px"
346
+        placeholder="请输入资源分类名称"
347
+      />
348
+      <ElButton type="primary" size="large" @click="handersearch" :icon="Search">搜索</ElButton>
349
+      <ElButton type="success" size="large" @click="tianjia" :icon="Edit">添加</ElButton>
350
+      <ElButton type="danger" size="large" @click="getSelections" :icon="Delete">删除</ElButton>
351
+    </div>
352
+
353
+    <Table
354
+      v-model:pageSize="pageSize"
355
+      v-model:currentPage="currentPage"
356
+      :columns="columns"
357
+      :image-preview="['icon']"
358
+      :data="dataList"
359
+      row-key="id"
360
+      headerAlign="center"
361
+      align="center"
362
+      :loading="loading"
363
+      sortable
364
+      :pagination="{
365
+        total: total
366
+      }"
367
+      @register="tableRegister"
368
+      @refresh="refresh"
369
+    />
370
+  </ContentWrap>
371
+
372
+  <Dialog v-model="dialogVisible" maxHeight="390px" width="35rem" :title="isedit">
373
+    <Form :schema="schema" @register="formRegister" />
374
+    <template #footer>
375
+      <div style="width: 100%; display: flex; justify-content: center">
376
+        <BaseButton
377
+          style="font-size: 1rem; height: 2.2rem; margin: auto"
378
+          type="primary"
379
+          class="w-[15%]"
380
+          @click="signIn"
381
+        >
382
+          确定
383
+        </BaseButton>
384
+      </div>
385
+    </template>
386
+  </Dialog>
387
+</template>
388
+
389
+<style>
390
+.el-image__preview {
391
+  width: 56px !important;
392
+  height: 56px !important;
393
+}
394
+</style>
395
+
396
+<style lang="less">
397
+.el-upload {
398
+  position: relative;
399
+  overflow: hidden;
400
+  cursor: pointer;
401
+  border: 1px dashed var(--el-border-color);
402
+  border-radius: 6px;
403
+  transition: var(--el-transition-duration-fast);
404
+}
405
+
406
+.el-upload:hover {
407
+  border-color: var(--el-color-primary);
408
+}
409
+.el-icon.avatar-uploader-icon {
410
+  width: 120px;
411
+  height: 120px;
412
+  font-size: 28px;
413
+  color: #8c939d;
414
+  text-align: center;
415
+}
416
+.avatar {
417
+  width: 120px;
418
+  height: 120px;
419
+}
420
+</style>