From d810b6abceb3678ed2f15a857adabb8ee0cecd29 Mon Sep 17 00:00:00 2001 From: JINGYJ <1458671527@qq.com> Date: Thu, 27 Jul 2023 16:58:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BB=A3=E7=A0=81=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 3 + src/api/home.ts | 11 + src/api/user.ts | 10 +- src/api/utils.ts | 2 + src/assets/login/logo.svg | 81 +++++++ src/router/modules/system.ts | 11 +- src/store/modules/user.ts | 6 +- src/utils/http/index.ts | 3 + src/views/login/index.vue | 9 +- src/views/login/utils/static.ts | 3 +- src/views/system/dept/form.vue | 138 +++++++++++ src/views/system/dept/index.vue | 151 ++++++++++++ src/views/system/dept/utils/hook.tsx | 335 ++++++++++++++++++++++++++ src/views/system/dept/utils/rule.ts | 37 +++ src/views/system/dept/utils/types.ts | 16 ++ src/views/system/roles/index.vue | 29 +++ src/views/system/roles/utils/hook.tsx | 142 ++++++++++- src/views/system/roles/utils/types.ts | 18 +- src/views/system/user/index.vue | 52 ++++ src/views/system/user/utils/hook.tsx | 69 ++++++ src/views/welcome/index.vue | 117 +++++---- 21 files changed, 1183 insertions(+), 60 deletions(-) create mode 100644 src/api/home.ts create mode 100644 src/api/utils.ts create mode 100644 src/assets/login/logo.svg create mode 100644 src/views/system/dept/form.vue create mode 100644 src/views/system/dept/index.vue create mode 100644 src/views/system/dept/utils/hook.tsx create mode 100644 src/views/system/dept/utils/rule.ts create mode 100644 src/views/system/dept/utils/types.ts diff --git a/.env.development b/.env.development index 90d1146..bfdecce 100644 --- a/.env.development +++ b/.env.development @@ -6,3 +6,6 @@ VITE_PUBLIC_PATH = / # 开发环境路由历史模式(Hash模式传"hash"、HTML5模式传"h5"、Hash模式带base参数传"hash,base参数"、HTML5模式带base参数传"h5,base参数") VITE_ROUTER_HISTORY = "hash" + +# 开发环境后端地址 +VITE_APP_BASE_URL = 'http://192.168.10.13:8000' \ No newline at end of file diff --git a/src/api/home.ts b/src/api/home.ts new file mode 100644 index 0000000..bd13a98 --- /dev/null +++ b/src/api/home.ts @@ -0,0 +1,11 @@ +import { http } from "@/utils/http"; +import { baseUrlApi } from "./utils"; + +type Result = { + count: number; + results?: Array; +}; + +export const getHomeList = (params?: object) => { + return http.request("get", baseUrlApi(""), { params }); +}; diff --git a/src/api/user.ts b/src/api/user.ts index af7cfff..6aac1cc 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -1,4 +1,5 @@ import { http } from "@/utils/http"; +import { baseUrlApi } from "./utils"; // import { getConfig } from "@/config"; export type UserResult = { @@ -32,8 +33,11 @@ export type RefreshTokenResult = { }; /** 登录 */ +// export const getLogin = (data?: object) => { +// return http.request("post", "/login", { data }); +// }; export const getLogin = (data?: object) => { - return http.request("post", "/login", { data }); + return http.request("post", baseUrlApi("login"), { data }); }; // export const getLogin = (data?: object) => { @@ -44,5 +48,7 @@ export const getLogin = (data?: object) => { /** 刷新token */ export const refreshTokenApi = (data?: object) => { - return http.request("post", "/refreshToken", { data }); + return http.request("post", baseUrlApi("/refreshToken"), { + data + }); }; diff --git a/src/api/utils.ts b/src/api/utils.ts new file mode 100644 index 0000000..2f0d1a1 --- /dev/null +++ b/src/api/utils.ts @@ -0,0 +1,2 @@ +const { VITE_APP_BASE_URL } = import.meta.env; +export const baseUrlApi = (url: string) => `${VITE_APP_BASE_URL}/api/${url}`; diff --git a/src/assets/login/logo.svg b/src/assets/login/logo.svg new file mode 100644 index 0000000..f483034 --- /dev/null +++ b/src/assets/login/logo.svg @@ -0,0 +1,81 @@ + + + + diff --git a/src/router/modules/system.ts b/src/router/modules/system.ts index ec52c67..53265e8 100644 --- a/src/router/modules/system.ts +++ b/src/router/modules/system.ts @@ -4,7 +4,8 @@ export default { icon: "informationLine", title: "系统管理", // showLink: false, - rank: 3 + rank: 3, + roles: ["admin"] }, children: [ { @@ -25,11 +26,11 @@ export default { } }, { - path: "/system/organization", - name: "organization", - component: () => import("@/views/common/common.vue"), + path: "/system/dept/index", + name: "dept", + component: () => import("@/views/system/dept/index.vue"), meta: { - title: "组织" + title: "部门" } } ] diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 849a240..54ddb3b 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -8,7 +8,7 @@ import { getLogin, refreshTokenApi } from "@/api/user"; import { UserResult, RefreshTokenResult } from "@/api/user"; import { useMultiTagsStoreHook } from "@/store/modules/multiTags"; import { type DataInfo, setToken, removeToken, sessionKey } from "@/utils/auth"; -import {ElMessage} from "element-plus"; +import { ElMessage } from "element-plus"; export const useUserStore = defineStore({ id: "pure-user", @@ -37,8 +37,8 @@ export const useUserStore = defineStore({ setToken(data.data); resolve(data); } else { - ElMessage.error(data.msg) - resolve(data) + ElMessage.error(data.msg); + resolve(data); } }) .catch(error => { diff --git a/src/utils/http/index.ts b/src/utils/http/index.ts index 3a39993..67044e6 100644 --- a/src/utils/http/index.ts +++ b/src/utils/http/index.ts @@ -52,6 +52,7 @@ class PureHttp { return new Promise(resolve => { PureHttp.requests.push((token: string) => { config.headers["Authorization"] = formatToken(token); + config.headers["token"] = formatToken(token); resolve(config); }); }); @@ -90,6 +91,7 @@ class PureHttp { .then(res => { const token = res.data.accessToken; config.headers["Authorization"] = formatToken(token); + config.headers["token"] = formatToken(token); PureHttp.requests.forEach(cb => cb(token)); PureHttp.requests = []; }) @@ -102,6 +104,7 @@ class PureHttp { config.headers["Authorization"] = formatToken( data.accessToken ); + config.headers["token"] = formatToken(data.accessToken); resolve(config); } } else { diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 449069c..bf3cd5b 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -8,7 +8,7 @@ import type { FormInstance } from "element-plus"; import { useLayout } from "@/layout/hooks/useLayout"; import { useUserStoreHook } from "@/store/modules/user"; import { initRouter, getTopMenu } from "@/router/utils"; -import { avatar } from "./utils/static"; +import { logo } from "./utils/static"; import { useRenderIcon } from "@/components/ReIcon/src/hooks"; import { ref, reactive, onMounted, onBeforeUnmount } from "vue"; import { useDataThemeChange } from "@/layout/hooks/useDataThemeChange"; @@ -75,6 +75,7 @@ function onkeypress({ code }: KeyboardEvent) { onMounted(() => { window.document.addEventListener("keypress", onkeypress); + console.log(logo); }); onBeforeUnmount(() => { @@ -101,7 +102,7 @@ onBeforeUnmount(() => { --> diff --git a/src/views/system/user/utils/hook.tsx b/src/views/system/user/utils/hook.tsx index 0baff91..11a0bd8 100644 --- a/src/views/system/user/utils/hook.tsx +++ b/src/views/system/user/utils/hook.tsx @@ -9,6 +9,7 @@ import { type PaginationProps } from "@pureadmin/table"; import { reactive, ref, computed, h, onMounted } from "vue"; // import { http } from "@/utils/http"; import { number } from "echarts"; +import { string } from "vue-types"; export function useUser() { const form = reactive({ @@ -334,7 +335,67 @@ export function useUser() { } }); } + const formData = reactive({ + username: string + }); + const drawerShow = ref(null); + const checkAll = ref(false); + const allRole = ref([]); + const userRole = ref([]); + function setRole(row) { + Object.assign(formData, row); + Object.assign(allRole.value, [ + { + createTime: "2021-05-31 18:09:18", + id: 1, + remark: null, + roleName: "超级管理员", + updateTime: "2023-04-28 11:03:38" + }, + { + createTime: "2021-05-31 18:09:18", + id: 1, + remark: null, + roleName: "普通角色", + updateTime: "2023-04-28 11:03:38" + } + ]); + Object.assign(userRole.value, [ + { + createTime: "2021-05-31 18:09:18", + id: 1, + remark: null, + roleName: "超级管理员", + updateTime: "2023-04-28 11:03:38" + } + ]); + console.log(allRole); + drawerShow.value = true; + } + function confirmClick() { + drawerShow.value = false; + } + //控制顶部全选复选框不确定的样式 + const isIndeterminate = ref(true); + //顶部的全部复选框的change事件 + function handleCheckAllChange(val: boolean) { + console.log(val); + console.log(allRole.value); + //val:true(全选)|false(没有全选) + userRole.value = val ? allRole.value : []; + //不确定的样式(确定样式) + isIndeterminate.value = false; + } + //顶部全部的复选框的change事件 + function handleCheckedCitiesChange(value: string[]) { + console.log(value); + //顶部复选框的勾选数据 + //代表:勾选上的项目个数与全部的职位个数相等,顶部的复选框勾选上 + checkAll.value = value.length === allRole.value.length; + //不确定的样式 + isIndeterminate.value = value.length !== allRole.value.length; + } onMounted(() => { onSearch(); }); @@ -346,6 +407,14 @@ export function useUser() { dataList, pagination, buttonClass, + drawerShow, + formData, + allRole, + userRole, + setRole, + confirmClick, + handleCheckAllChange, + handleCheckedCitiesChange, onSearch, openDialog, resetForm, diff --git a/src/views/welcome/index.vue b/src/views/welcome/index.vue index a3df214..84ecc75 100644 --- a/src/views/welcome/index.vue +++ b/src/views/welcome/index.vue @@ -9,6 +9,7 @@ import { type PaginationProps } from "@pureadmin/table"; import { ElMessageBox, ElMessage } from "element-plus"; import { getConfig } from "@/config"; import { getToken, formatToken } from "@/utils/auth"; +import { getHomeList } from "@/api/home"; defineOptions({ name: "Welcome" @@ -63,47 +64,73 @@ function onSearch() { start_time = formInline.value.date[0]; end_time = formInline.value.date[1]; } - - axios({ - url: AdminHostUrl, - params: { - start_time: start_time || undefined, - end_time: end_time || undefined, - police_id: formInline.value.policeId || undefined, - event_type: formInline.value.event || undefined, - violation: violationMap.value[formInline.value.violation] || undefined, - violation_type: formInline.value.violationType || undefined, - page: currentPage.value || undefined, - page_size: pageSize.value || undefined - }, - headers: { - token: formatToken(getToken().accessToken) - } - }) - .then(response => { - // console.log(response.data); - totalNumber.value = response.data.count; - if (!isDisplay) { - tableData.value = response.data.results.filter(data => { - return data.is_display === true; - }); - } else { - tableData.value = response.data.results; - } - setTimeout(() => { - loading.value = false; - }, 500); - }) - .catch(error => { - ElMessage({ - message: "网络暂不通畅", - type: "warning" + const params = { + start_time: start_time || undefined, + end_time: end_time || undefined, + police_id: formInline.value.policeId || undefined, + event_type: formInline.value.event || undefined, + violation: violationMap.value[formInline.value.violation] || undefined, + violation_type: formInline.value.violationType || undefined, + page: currentPage.value || undefined, + page_size: pageSize.value || undefined + }; + getHomeList(params).then(response => { + const dataList = response; + totalNumber.value = dataList.count; + pagination.total = dataList.count; + console.log(totalNumber.value, "totalNumber"); + if (!isDisplay) { + tableData.value = dataList.results.filter(data => { + return data.is_display === true; }); - setTimeout(() => { - loading.value = false; - }, 500); - console.log(error); - }); + } else { + tableData.value = dataList.results; + } + console.log(pagination, "pagination"); + setTimeout(() => { + loading.value = false; + }, 500); + }); + // axios({ + // url: AdminHostUrl, + // params: { + // start_time: start_time || undefined, + // end_time: end_time || undefined, + // police_id: formInline.value.policeId || undefined, + // event_type: formInline.value.event || undefined, + // violation: violationMap.value[formInline.value.violation] || undefined, + // violation_type: formInline.value.violationType || undefined, + // page: currentPage.value || undefined, + // page_size: pageSize.value || undefined + // }, + // headers: { + // token: formatToken(getToken().accessToken) + // } + // }) + // .then(response => { + // // console.log(response.data); + // totalNumber.value = response.data.count; + // if (!isDisplay) { + // tableData.value = response.data.results.filter(data => { + // return data.is_display === true; + // }); + // } else { + // tableData.value = response.data.results; + // } + // setTimeout(() => { + // loading.value = false; + // }, 500); + // }) + // .catch(error => { + // ElMessage({ + // message: "网络暂不通畅", + // type: "warning" + // }); + // setTimeout(() => { + // loading.value = false; + // }, 500); + // console.log(error); + // }); } function handleSearch() { @@ -217,6 +244,8 @@ const pagination = reactive({ currentPage: currentPage.value, background: true }); +console.log(totalNumber.value, "totalNumber"); +console.log(pagination, "pagination111111"); onMounted(() => { onSearch(); @@ -231,7 +260,7 @@ onMounted(() => { :before-close="handleClose" destroy-on-close > - + { > {