From 3fe0b0d6b0648e255bbed7831740e6f56ce685b9 Mon Sep 17 00:00:00 2001 From: lzq <2495532633@qq.com> Date: Thu, 11 Dec 2025 18:01:28 +0800 Subject: [PATCH] 1 --- src/common/utils/client-util.ts | 38 ++++++++++++++++++++++++++++++++ src/pages/login/Login.vue | 2 +- src/pages/sys/menus/MenuForm.vue | 9 ++++++++ src/pages/sys/menus/menu.d.ts | 2 ++ src/pages/sys/user/User.vue | 8 +++---- src/pages/sys/user/user-api.ts | 6 ++--- 6 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 src/common/utils/client-util.ts diff --git a/src/common/utils/client-util.ts b/src/common/utils/client-util.ts new file mode 100644 index 0000000..ccfc5b8 --- /dev/null +++ b/src/common/utils/client-util.ts @@ -0,0 +1,38 @@ +import Colls from '@/common/utils/colls.ts' + +const clientList = [ + { + txt: '电脑端', + val: 1, + }, + { + txt: '微信小程序', + val: 2, + }, +] + +function hasClient(client: number, clientCode: number) { + const find = clientList.find(it => it.val === client) + if (find == null) return false + return (client & clientCode) !== 0 +} + +function getClientCode(clients: number[]) { + if (Colls.isEmpty(clients)) return 0 + let clientCode = 0 + for (let client of clients) { + clientCode |= client + } + return clientCode +} + +function getClients(clientCode: number) { + return clientList.filter(it => hasClient(it.val, clientCode)) +} + +export default { + clients: clientList, + hasClient, + getClientCode, + getClients, +} diff --git a/src/pages/login/Login.vue b/src/pages/login/Login.vue index aff9bad..29d21f8 100644 --- a/src/pages/login/Login.vue +++ b/src/pages/login/Login.vue @@ -17,7 +17,7 @@ const loginFormIns = useTemplateRef('loginFormRef') const loginForm = reactive({ account: '', secret: '', - clientCode: 0, + clientCode: 1, }) const rules = reactive>({ account: [ diff --git a/src/pages/sys/menus/MenuForm.vue b/src/pages/sys/menus/MenuForm.vue index 0833c55..ba5db9e 100644 --- a/src/pages/sys/menus/MenuForm.vue +++ b/src/pages/sys/menus/MenuForm.vue @@ -6,6 +6,11 @@ + + + + + @@ -77,6 +82,7 @@ import { icons, } from '@/components/a-icon/iconfont.ts' import AIcon from '@/components/a-icon/AIcon.tsx' +import ClientUtil from '@/common/utils/client-util.ts' const emits = defineEmits([ 'editSucc' ]) @@ -136,9 +142,12 @@ const menuCategoryData = computed(() => { const menuTreeDataSource = ref() + function submitHandler() { if (status.value === 'view') return submiting.value = true + + menuForm.value.clientCode = ClientUtil.getClientCode(menuForm.value.clients!) if (menuForm.value.id != null) { MenuApi.modify(menuForm.value) .then(() => { diff --git a/src/pages/sys/menus/menu.d.ts b/src/pages/sys/menus/menu.d.ts index b47e25e..3874573 100644 --- a/src/pages/sys/menus/menu.d.ts +++ b/src/pages/sys/menus/menu.d.ts @@ -50,6 +50,8 @@ declare global { iconName?: string // 排序 sort?: number + clients?: number[] + clientCode?: number // 路由名称 routeName?: string routePath?: string diff --git a/src/pages/sys/user/User.vue b/src/pages/sys/user/User.vue index d970bb5..4124d9f 100644 --- a/src/pages/sys/user/User.vue +++ b/src/pages/sys/user/User.vue @@ -52,11 +52,10 @@ - + @@ -93,6 +92,7 @@ import { } from 'element-plus' import AppApi from '@/common/app/app-api.ts' import BindRole from '@/pages/sys/user/BindRole.vue' +import ClientUtil from '@/common/utils/client-util.ts' const tableData = ref([]) const searchForm = reactive({ @@ -189,7 +189,7 @@ function paging() { .then(res => { tableData.value = res.data?.records ?? [] tableData.value.map(it => { - it.account.clients = UserApi.clients(it.account.clientCode!).map(it => it.val) + it.account.clients = ClientUtil.getClients(it.account.clientCode!).map(it => it.val) return it }) }) diff --git a/src/pages/sys/user/user-api.ts b/src/pages/sys/user/user-api.ts index 98ec06e..980ca99 100644 --- a/src/pages/sys/user/user-api.ts +++ b/src/pages/sys/user/user-api.ts @@ -2,6 +2,7 @@ import { get, post, } from '@/common/utils/http-util.ts' +import ClientUtil from '@/common/utils/client-util.ts' const Clients = [ { txt: '电脑端', @@ -48,10 +49,7 @@ export default { }) }, bindClient(id: string, clients: number[]) { - let clientCode = (1 << Clients.length) - 1 - for (let client of clients) { - clientCode = (1 << client) ^ clientCode - } + let clientCode = ClientUtil.getClientCode(clients) return get('/user/bind_client', {id, clientCode}) }, }