From 3eb092eb1badc2272d35f275c8068dbd6ded5ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=96=87=E5=8F=AF?= <1041367524@qq.com> Date: Thu, 9 Jun 2022 11:06:19 +0800 Subject: [PATCH 1/3] =?UTF-8?q?perf:=20UC=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/permission/feature.js | 13 ++ src/store/modules/permission/menu/feature.js | 17 +++ src/store/modules/permission/menu/menu.js | 3 + src/views/permission/menu/index.vue | 130 +++++++++++++++---- 4 files changed, 141 insertions(+), 22 deletions(-) diff --git a/src/api/permission/feature.js b/src/api/permission/feature.js index 1da6d93..21bca43 100644 --- a/src/api/permission/feature.js +++ b/src/api/permission/feature.js @@ -6,6 +6,19 @@ export const search = (params) => { params, }); }; +export const searchFree = () => { + return request({ + url: '/uc/permission/NotDistribution', + method: 'get', + }); +}; +export const assign = (params) => { + return request({ + url: '/uc/permission/menu', + method: 'put', + params, + }); +}; export const create = (data) => { return request({ url: '/uc/permission', diff --git a/src/store/modules/permission/menu/feature.js b/src/store/modules/permission/menu/feature.js index 35829c8..8f7f286 100644 --- a/src/store/modules/permission/menu/feature.js +++ b/src/store/modules/permission/menu/feature.js @@ -7,6 +7,16 @@ const state = () => ({ total: 0, opts: { init: false, + type: [ + { + label: '需要分配', + value: 1, + }, + { + label: '登录即有', + value: 2, + }, + ], }, }); const getters = {}; @@ -38,6 +48,13 @@ const actions = { } return res; }, + assign: async (context, data) => { + let res = await api.assign(data); + if (!res) { + ElMessage.error('分配失败'); + } + return res; + }, save: async ({ dispatch }, data) => { if (!data.parentId) { data.parentId = 0; diff --git a/src/store/modules/permission/menu/menu.js b/src/store/modules/permission/menu/menu.js index fb9aa22..50d68e5 100644 --- a/src/store/modules/permission/menu/menu.js +++ b/src/store/modules/permission/menu/menu.js @@ -1,3 +1,4 @@ +import * as featureAPI from '@/api/permission/feature.js'; import * as api from '@/api/permission/menu.js'; import * as systemAPI from '@/api/permission/system.js'; import { ElMessage, ElMessageBox } from '@/plugins/element-plus'; @@ -9,6 +10,7 @@ const state = () => ({ opts: { init: false, system: [], + free: [], type: [ { label: '目录', @@ -64,6 +66,7 @@ const actions = { ...state.opts, init: true, system: await systemAPI.search(), + free: await featureAPI.searchFree(), }); }, detail: async (context, id) => { diff --git a/src/views/permission/menu/index.vue b/src/views/permission/menu/index.vue index d85365f..627051b 100644 --- a/src/views/permission/menu/index.vue +++ b/src/views/permission/menu/index.vue @@ -35,7 +35,7 @@ value: 'id', children: 'menuChild', }" - @current-change="(data) => (state.condition2.menuId = data.id)" + @node-click="(data) => handleCreateMenu(data)" > @@ -227,6 +251,7 @@ const store = useStore(); const { proxy } = getCurrentInstance(); const opts = computed(() => store.state.menu.opts); + const opts2 = computed(() => store.state.feature.opts); if (!unref(opts).init) { store.dispatch('menu/load'); } @@ -243,6 +268,15 @@ await store.dispatch('menu/search'); loading.value = false; }; + watch( + () => unref(opts).system, + (value) => { + state.condition.systemId = value?.[0]?.id; + }, + { + deep: true, + } + ); watch( () => state.condition, (value) => { @@ -297,7 +331,11 @@ }, }); const handleCreateMenu = (row, parent) => { + if (row) { + state.condition2.menuId = row.id; + } menuState.formVisible = true; + featureState.formVisible = false; Object.assign( menuState.form, row || { @@ -341,6 +379,7 @@ /* 功能表单 */ const refsFeatureForm = ref(null); + const refsPickForm = ref(null); const featureState = reactive({ formVisible: false, submitting: false, @@ -349,21 +388,66 @@ systemId: null, menuId: null, name: null, + service: null, method: 'GET', uri: null, + type: 1, isEnable: true, }, rules: { systemId: [{ required: true, message: '所属系统不能为空' }], menuId: [{ required: true, message: '所属菜单不能为空' }], name: [{ required: true, message: '功能名称不能为空' }], + service: [{ required: true, message: '服务名称不能为空' }], method: [{ required: true, message: '请求方式不能为空' }], uri: [{ required: true, message: '接口路径不能为空' }], + type: [{ required: true, message: '权限类型不能为空' }], isEnable: [{ required: true, message: '是否启用不能为空' }], }, + pickVisible: false, + pick: { + permissionId: null, + menuId: null, + }, + pickRules: { + permissionId: [{ required: true, message: '功能权限不能为空' }], + }, }); - const handleCreateFeature = (row) => { + const handleCancelPick = () => { + featureState.pickVisible = false; + featureState.pick = { + permissionId: null, + menuId: null, + }; + }; + const handleSavePick = async () => { + featureState.submitting = true; + try { + await proxy.$validate(refsPickForm); + let res = await store.dispatch('feature/assign', featureState.pick); + if (res) { + handleSearchFeature(); + handleCancelPick(); + store.dispatch('menu/load'); + } + } catch (e) { + console.info('取消保存', e); + } + featureState.submitting = false; + }; + const handlePickFeature = async () => { + try { + await proxy.$confirm('是否选择尚未分配菜单的功能权限?'); + featureState.formVisible = false; + featureState.pickVisible = true; + featureState.pick.menuId = state.condition2.menuId; + } catch (e) { + handleCreateFeature(); + } + }; + const handleCreateFeature = async (row) => { featureState.formVisible = true; + menuState.formVisible = false; Object.assign( featureState.form, row || { @@ -371,8 +455,10 @@ systemId: state.condition.systemId, menuId: state.condition2.menuId, name: null, + service: null, method: 'GET', uri: null, + type: 1, isEnable: true, } ); @@ -391,12 +477,12 @@ } featureState.submitting = false; }; - const handleDeleteFeature = (data) => { - store.dispatch( - 'feature/remove', - data.map((item) => item.id) - ); - }; + // const handleDeleteFeature = (data) => { + // store.dispatch( + // 'feature/remove', + // data.map((item) => item.id) + // ); + // }; + From 462f25020bac556a95ca71c2fee8ffed9f667e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=96=87=E5=8F=AF?= <1041367524@qq.com> Date: Mon, 13 Jun 2022 16:00:44 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E7=94=A8=E6=88=B7=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/sales/order/index.vue | 54 ++++++++++++++--------------- src/views/system/customer/index.vue | 27 +++++++++------ 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/src/views/sales/order/index.vue b/src/views/sales/order/index.vue index b41a8f8..f4f25da 100644 --- a/src/views/sales/order/index.vue +++ b/src/views/sales/order/index.vue @@ -90,33 +90,6 @@ endTime: null, }, }); - watch( - () => route.query.id, - (value) => { - state.condition.userId = value; - }, - { immediate: true, deep: true } - ); - watch( - () => state.condition, - (value) => { - store.commit('order/setCondition', _.cloneDeep(value)); - }, - { immediate: true, deep: true } - ); - watch( - () => state.condition.orderStatus, - () => { - handleSearch(); - }, - { deep: true } - ); - watch( - () => state.condition.userId, - () => { - handleSearch(); - } - ); const handleReset = () => { state.condition = { userId: null, @@ -154,6 +127,33 @@ await store.dispatch('order/search'); loading.value = false; }; + watch( + () => route.query.id, + (value) => { + state.condition.userId = value; + }, + { immediate: true, deep: true } + ); + watch( + () => state.condition, + (value) => { + store.commit('order/setCondition', _.cloneDeep(value)); + }, + { immediate: true, deep: true } + ); + watch( + () => state.condition.orderStatus, + () => { + handleSearch(); + }, + { deep: true } + ); + watch( + () => state.condition.userId, + () => { + handleSearch(); + } + ); onActivated(() => { if (route.query.status) { state.condition.orderStatus = route.query.status.split(',').map((item) => +item); diff --git a/src/views/system/customer/index.vue b/src/views/system/customer/index.vue index e59e3d1..29f3e5e 100644 --- a/src/views/system/customer/index.vue +++ b/src/views/system/customer/index.vue @@ -52,13 +52,6 @@ dateRange: [], }, }); - watch( - () => state.condition, - (value) => { - store.commit('customer/setCondition', _.cloneDeep(value)); - }, - { immediate: true, deep: true } - ); const handleReset = () => { state.condition = { phone: null, @@ -67,14 +60,26 @@ }; }; const handleSearch = async () => { - if (route.query.phone && !state.condition.phone) { - state.condition.phone = route.query.phone; - store.commit('customer/setCondition', _.cloneDeep(state.condition)); - } loading.value = true; await store.dispatch('customer/search'); loading.value = false; }; + watch( + () => route.query.phone, + (value) => { + state.condition.phone = value; + store.commit('customer/setCondition', _.cloneDeep(state.condition)); + handleSearch(); + }, + { immediate: true } + ); + watch( + () => state.condition, + (value) => { + store.commit('customer/setCondition', _.cloneDeep(value)); + }, + { immediate: true, deep: true } + ); onActivated(handleSearch); const handleEnable = async (row) => { loading.value = true;