From ccd5595032a1083e891c9ca8dd5df9f2fc9ec802 Mon Sep 17 00:00:00 2001 From: "DESKTOP-VMMLSOQ\\wangzg" <1161909281@qq.com> Date: Wed, 26 Jun 2024 08:19:02 +0800 Subject: [PATCH] 1 --- components/smallCommon/Curd.vue | 127 +++++++++++++++++++++++++------- layouts/manager.vue | 11 ++- pages/manager/device.vue | 123 +++++++++++++++++++++++++++++++ pages/manager/login.vue | 94 +++++++++++++++++++++++ pages/manager/menu.vue | 100 +++++++++++++++++++++++++ pages/manager/role.vue | 86 +++++++++++++++------ pages/manager/user.vue | 61 ++++++++++++--- plugins/axios.js | 26 ++++++- 8 files changed, 564 insertions(+), 64 deletions(-) create mode 100644 pages/manager/device.vue create mode 100644 pages/manager/login.vue create mode 100644 pages/manager/menu.vue diff --git a/components/smallCommon/Curd.vue b/components/smallCommon/Curd.vue index 07c6e3f..4cdc972 100644 --- a/components/smallCommon/Curd.vue +++ b/components/smallCommon/Curd.vue @@ -32,7 +32,7 @@ 添加 - + 删除 @@ -47,21 +47,35 @@ @cancel="handleCancel" > - + - {{ cItem.label }} + {{ cItem.label }} - + + {{ cItem.label }} + + @@ -72,6 +86,7 @@ export default { name: "user", data () { return { + isValidate: false, tableDataSource: [], form: this.$form.createForm(this, { name: `form_${new Date().valueOf()}` }), editForm: this.$form.createForm(this, { name: `edit_form_${new Date().valueOf()}` }), @@ -108,9 +123,7 @@ export default { apiConf: { type: Object, default: () => ({}) - } - - + }, }, computed: { searchItems () { @@ -136,29 +149,60 @@ export default { this.handleSearch() }, methods: { + gtDecorator (menuItem) { + if (menuItem.rules) { + this.isValidate = true + return [ + menuItem.key, + { rules: menuItem.rules } + ] + } + return [ + menuItem.key + ] + }, handleSearchFormChange(changedFields) { this.searchFormModel = { ...this.searchFormModel, ...changedFields } }, addRow () { this.handleCancel() + this.$emit('edit', false) this.dialog.visible = true }, - editRow(row) { - this.selectRow = row - this.dialog.title = '添加' + async editRow(row) { + if (this.apiConf.detailApi) { + const {api, method, detailHandler} = this.apiConf.detailApi + const { data } = await this[`$${method}`](api, { [this.primaryKey]: row[this.primaryKey] }) + this.selectRow = detailHandler && detailHandler(data) || data + } else { + this.selectRow = row + } + this.dialog.title = '编辑' this.dialog.visible = true this.dialog.isEdit = true this.dialog.loading = false + this.$emit('edit', true) + setTimeout(() => { + this.editForm.setFieldsValue(this.selectRow) + }, 200) }, deleteRow(row) { + const self = this this.$confirm({ title: '确认要删除么?', okText: '确认', okType: 'danger', cancelText: '再想想', onOk() { - this.$post(this.apiConf.deleteApi, { - [this.primaryKey]: row[this.primaryKey], + const { api,deleteKey, paramsType, method } = self.apiConf.deleteApi + let params = {} + if (paramsType === 'Array') { + params = [row[self.primaryKey]] + } else { + params[deleteKey] = row[self.primaryKey] + } + self[`$${method}`](api, params, {params: params}).then(res => { + self.handleSearch() }) } }); @@ -177,33 +221,60 @@ export default { async handleSearch(e) { e && e.preventDefault(); const values = this.form.getFieldsValue() - const { data } = await this.$get(this.apiConf.listApi, { + const { api, noPage, method } = this.apiConf.listApi + const { data } = await this[`$${method}`](api, { ...values, pageSize: this.page.pageSize, current: this.page.pageNo, }) - this.tableDataSource = data.items + if (noPage) { + this.tableDataSource = data + } else { + this.tableDataSource = data.items + } }, async handleOk() { - const values = this.editForm.getFieldsValue() - if (this.dialog.isEdit) { - await this.$post(this.apiConf.editApi, { - [this.primaryKey]: this.selectRow[this.primaryKey], - ...values - }) + if (this.isValidate) { + this.editForm.validateFields(async (err, values) => { + if (!err) { + if (this.dialog.isEdit) { + const { api, method, updateKey } = this.apiConf.editApi + await this[`$${method}`](api, { + [updateKey || this.primaryKey]: this.selectRow[this.primaryKey], + ...values + }) + } else { + const { api, method } = this.apiConf.addApi + await this[`$${method}`](api, values) + } + this.handleCancel() + this.handleSearch() + } + }); } else { - debugger - await this.$post(this.apiConf.addApi, values) + const values = this.editForm.getFieldsValue() + if (this.dialog.isEdit) { + const { api, method, updateKey } = this.apiConf.editApi + await this[`$${method}`](api, { + [updateKey || this.primaryKey]: this.selectRow[this.primaryKey], + ...values + }) + } else { + const { api, method } = this.apiConf.addApi + await this[`$${method}`](api, values) + } + this.handleCancel() + this.handleSearch() } - this.handleCancel() - this.handleSearch() + }, handleCancel() { - this.editRow = null + this.selectRow = null this.dialog.title = '添加' this.dialog.visible = false this.dialog.isEdit = false this.dialog.loading = false + this.editForm.resetFields() }, } } diff --git a/layouts/manager.vue b/layouts/manager.vue index 68f5209..c4773a6 100644 --- a/layouts/manager.vue +++ b/layouts/manager.vue @@ -77,8 +77,14 @@ export default { { link: '/manager/role', title: '角色管理', - icon: 'user', + icon: 'branches', key: 'manager-role' + }, + { + link: '/manager/menu', + title: '菜单管理', + icon: 'link', + key: 'manager-menu' } ], selectedKeys: [] @@ -90,6 +96,9 @@ export default { handler (to) { this.selectedKeys = [to.name] } + }, + selectedKeys ([key]) { + this.$router.push({ name: key }) } }, computed: { diff --git a/pages/manager/device.vue b/pages/manager/device.vue new file mode 100644 index 0000000..dde9c6f --- /dev/null +++ b/pages/manager/device.vue @@ -0,0 +1,123 @@ + + + diff --git a/pages/manager/login.vue b/pages/manager/login.vue new file mode 100644 index 0000000..aa12265 --- /dev/null +++ b/pages/manager/login.vue @@ -0,0 +1,94 @@ + + + + + + diff --git a/pages/manager/menu.vue b/pages/manager/menu.vue new file mode 100644 index 0000000..98995c7 --- /dev/null +++ b/pages/manager/menu.vue @@ -0,0 +1,100 @@ + + + diff --git a/pages/manager/role.vue b/pages/manager/role.vue index 577e352..c38711d 100644 --- a/pages/manager/role.vue +++ b/pages/manager/role.vue @@ -1,59 +1,101 @@ - -