From 6688672ea05bb700bc4b2e40dd92bb1f359b51a0 Mon Sep 17 00:00:00 2001 From: JINGYJ <1458671527@qq.com> Date: Thu, 10 Aug 2023 17:05:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=94=A8=E6=88=B7=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=92=8C=E9=83=A8=E9=97=A8=E6=A8=A1=E5=9D=97=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E8=81=94=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 2 +- src/api/home.ts | 12 ++- src/api/system.ts | 42 ++++++---- src/api/user.ts | 4 +- src/views/system/dept/form.vue | 1 + src/views/system/dept/utils/hook.tsx | 4 + src/views/system/user/form.vue | 41 ++++++---- src/views/system/user/index.vue | 8 +- src/views/system/user/utils/hook.tsx | 57 +++++++++++-- src/views/system/user/utils/rule.ts | 26 +++++- src/views/system/user/utils/types.ts | 3 +- src/views/welcome/hook.tsx | 4 +- src/views/welcome/index.vue | 118 +++++++++++++++------------ vite.config.ts | 2 +- 14 files changed, 216 insertions(+), 108 deletions(-) diff --git a/.env.development b/.env.development index bfdecce..53437f7 100644 --- a/.env.development +++ b/.env.development @@ -8,4 +8,4 @@ VITE_PUBLIC_PATH = / VITE_ROUTER_HISTORY = "hash" # 开发环境后端地址 -VITE_APP_BASE_URL = 'http://192.168.10.13:8000' \ No newline at end of file +VITE_APP_BASE_URL = 'http://192.168.10.14:8008' \ No newline at end of file diff --git a/src/api/home.ts b/src/api/home.ts index eb4d3e7..6cf0506 100644 --- a/src/api/home.ts +++ b/src/api/home.ts @@ -8,14 +8,20 @@ type Result = { type Data = { success: boolean; msg: any; - results?: Array; + data?: Array; }; export const getHomeList = (params?: object) => { - return http.request("get", baseUrlApi("tps"), { params }); + return http.request("get", baseUrlApi(""), { params }); }; export const getEvents = (params?: object) => { - return http.request("get", baseUrlApi("tps/events"), { params }); + return http.request("get", baseUrlApi("events"), { params }); +}; +export const getScenes = (params?: object) => { + return http.request("get", baseUrlApi("scenes"), { params }); +}; +export const getReasons = (params?: object) => { + return http.request("get", baseUrlApi("violation_reasons"), { params }); }; export const updateHomeList = (params?: object) => { return http.request("put", baseUrlApi(""), { params }); diff --git a/src/api/system.ts b/src/api/system.ts index 78d6973..5983c1c 100644 --- a/src/api/system.ts +++ b/src/api/system.ts @@ -7,7 +7,7 @@ type deptResult = { /** 部门列表查询 */ export const getDeptList = (params?: object) => { - return http.request("get", baseUrlApi("departments/"), { + return http.request("get", baseUrlApi("organization/trees/"), { params }); }; @@ -19,16 +19,20 @@ type deptStatus = { /** 新增部门 */ export const addDept = (data?: object) => { - return http.request("post", baseUrlApi("departments/"), { - data - }); + return http.request( + "post", + baseUrlApi("organization/departments/"), + { + data + } + ); }; /** 更新部门 */ export const updateDept = (data?: object | any) => { return http.request( "put", - baseUrlApi(`departments/${data.id}/`), + baseUrlApi(`organization/departments/${data.id}/`), { data } @@ -39,7 +43,7 @@ export const updateDept = (data?: object | any) => { export const deleteDept = (data?: object | any) => { return http.request( "delete", - baseUrlApi(`departments/${data}/`), + baseUrlApi(`organization/departments/${data}/`), { data } @@ -55,7 +59,7 @@ type userList = { /** 用户列表查询 */ export const getUserList = (params?: object) => { - return http.request("get", baseUrlApi("user/"), { + return http.request("get", baseUrlApi("organization/users/"), { params }); }; @@ -66,19 +70,29 @@ type userStatus = { }; /** 新增用户 */ export const addUser = (data?: object) => { - return http.request("post", baseUrlApi("user/"), { data }); + return http.request("post", baseUrlApi("organization/users/"), { + data + }); }; /** 更新用户 */ export const updateUser = (data?: object | any) => { - return http.request("put", baseUrlApi(`user/${data.id}/`), { - data - }); + return http.request( + "put", + baseUrlApi(`organization/users/${data.id}/`), + { + data + } + ); }; /** 删除用户 */ export const deleteUser = (data?: object | any) => { - return http.request("delete", baseUrlApi(`user/${data}/`), { - data - }); + return http.request( + "delete", + baseUrlApi(`organization/users/${data}/`), + { + data + } + ); }; diff --git a/src/api/user.ts b/src/api/user.ts index 9d8f964..28b3f0c 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -37,7 +37,9 @@ export type RefreshTokenResult = { // return http.request("post", "/login", { data }); // }; export const getLogin = (data?: object) => { - return http.request("post", baseUrlApi("user/login/"), { data }); + return http.request("post", baseUrlApi("organization/login"), { + data + }); }; // export const getLogin = (data?: object) => { diff --git a/src/views/system/dept/form.vue b/src/views/system/dept/form.vue index bc9b6f6..f7f57c1 100644 --- a/src/views/system/dept/form.vue +++ b/src/views/system/dept/form.vue @@ -51,6 +51,7 @@ defineExpose({ getRef }); emitPath: false, checkStrictly: true }" + :disabled="newFormInline.id ? true : false" clearable filterable placeholder="请选择上级部门" diff --git a/src/views/system/dept/utils/hook.tsx b/src/views/system/dept/utils/hook.tsx index 4526fdf..c69730d 100644 --- a/src/views/system/dept/utils/hook.tsx +++ b/src/views/system/dept/utils/hook.tsx @@ -189,6 +189,10 @@ export function useDept() { addDept(params).then(res => { if (res.success) { chores(); + } else { + message(`${res.msg}`, { + type: "warning" + }); } }); } else { diff --git a/src/views/system/user/form.vue b/src/views/system/user/form.vue index fa2ffff..9dd5947 100644 --- a/src/views/system/user/form.vue +++ b/src/views/system/user/form.vue @@ -10,9 +10,10 @@ const props = withDefaults(defineProps(), { department_id: "", username: "", phone_number: "", - status: 1, + is_active: true, gender: null, id: "" + // password: "" }) }); @@ -46,7 +47,7 @@ defineExpose({ getRef }); emitPath: false, checkStrictly: true, disabled: function (data) { - if (data.children && data.children.length > 0) { + if (!data.parent_id) { return true; } else { return false; @@ -75,7 +76,16 @@ defineExpose({ getRef }); /> - + - - - - - + @@ -106,6 +105,18 @@ defineExpose({ getRef }); + + + + + diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index fc5b769..4a345ab 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -76,15 +76,15 @@ const { class="!w-[160px]" /> - + - - + + diff --git a/src/views/system/user/utils/hook.tsx b/src/views/system/user/utils/hook.tsx index f4931da..ea8b81b 100644 --- a/src/views/system/user/utils/hook.tsx +++ b/src/views/system/user/utils/hook.tsx @@ -35,7 +35,7 @@ export function useUser() { /** 手机号 */ phone_number: "", /** 状态 */ - status: "", + is_active: null, /** 部门 */ department_id: "" }); @@ -93,15 +93,15 @@ export function useUser() { }, { label: "状态", - prop: "status", + prop: "is_active", minWidth: 90, cellRenderer: scope => ( { + const params = { + ...curData, + password: "test1234" + }; + addUser(params).then(res => { console.log(res); if (res.success) { chores(); @@ -287,7 +291,7 @@ export function useUser() { department_id: curData.department_id, username: curData.username, phone_number: curData.phone_number, - status: curData.status, + is_active: curData.is_active, gender: curData.gender, id: curData.id }; @@ -376,13 +380,24 @@ export function useUser() { isIndeterminate.value = value.length !== allRole.value.length; } + /** 密码正则(密码格式应为8-18位数字、字母、符号的任意两种组合) */ + const REGEXP_PWD = + /^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)]|[()])+$)(?!^.*[\u4E00-\u9FA5].*$)([^(0-9a-zA-Z)]|[()]|[a-z]|[A-Z]|[0-9]){8,18}$/; + function resetPassword(row: { username: string; id: any }) { ElMessageBox.prompt( "请输入用户「" + row.username + "」的新密码", "重置密码", { confirmButtonText: "确定", - cancelButtonText: "取消" + cancelButtonText: "取消", + inputValidator: val => { + if (val === null) { + return true; //初始化的值为null,不做处理的话,刚打开MessageBox就会校验出错,影响用户体验 + } + return REGEXP_PWD.test(val); + }, + inputErrorMessage: "密码格式应为8-18位数字、字母、符号的任意两种组合" } ) .then(({ value }) => { @@ -391,6 +406,30 @@ export function useUser() { type: "warning" }); return false; + } else { + console.log(value); + const params = { + id: row.id, + password: value + }; + updateUser(params) + .then(res => { + console.log(res); + if (res.success) { + message(`${res.msg}`, { + type: "success" + }); + } else { + message(`${res.msg}`, { + type: "warning" + }); + } + }) + .catch(error => { + message(`${error}`, { + type: "warning" + }); + }); } }) .catch(() => {}); diff --git a/src/views/system/user/utils/rule.ts b/src/views/system/user/utils/rule.ts index e1eafe8..ed04b8a 100644 --- a/src/views/system/user/utils/rule.ts +++ b/src/views/system/user/utils/rule.ts @@ -2,6 +2,10 @@ import { reactive } from "vue"; import type { FormRules } from "element-plus"; import { isPhone } from "@pureadmin/utils"; +/** 密码正则(密码格式应为8-18位数字、字母、符号的任意两种组合) */ +export const REGEXP_PWD = + /^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)]|[()])+$)(?!^.*[\u4E00-\u9FA5].*$)([^(0-9a-zA-Z)]|[()]|[a-z]|[A-Z]|[0-9]){8,18}$/; + /** 自定义表单规则校验 */ export const formRules = reactive({ username: [{ required: true, message: "角色名称为必填项", trigger: "blur" }], @@ -9,9 +13,7 @@ export const formRules = reactive({ phone_number: [ { validator: (rule, value, callback) => { - if (value === "") { - callback(); - } else if (!isPhone(value)) { + if (!isPhone(value)) { callback(new Error("请输入正确的手机号码格式")); } else { callback(); @@ -21,5 +23,21 @@ export const formRules = reactive({ // trigger: "click" // 如果想在点击确定按钮时触发这个校验,trigger 设置成 click 即可 } ], - gender: [{ required: true, message: "性别为必填项", trigger: "blur" }] + gender: [{ required: true, message: "性别为必填项", trigger: "blur" }], + password: [ + { + validator: (rule, value, callback) => { + if (value === "") { + callback(new Error("请输入密码")); + } else if (!REGEXP_PWD.test(value)) { + callback( + new Error("密码格式应为8-18位数字、字母、符号的任意两种组合") + ); + } else { + callback(); + } + }, + trigger: "blur" + } + ] }); diff --git a/src/views/system/user/utils/types.ts b/src/views/system/user/utils/types.ts index d4fdc6d..9e79a7f 100644 --- a/src/views/system/user/utils/types.ts +++ b/src/views/system/user/utils/types.ts @@ -2,10 +2,11 @@ interface FormItemProps { higherDeptOptions: Record[]; username: string; phone_number: string | number; - status: number; + is_active: boolean; department_id: string | number; gender: string | number; id: string | number; + // password: string | number; } interface FormProps { formInline: FormItemProps; diff --git a/src/views/welcome/hook.tsx b/src/views/welcome/hook.tsx index df8554c..60d03e9 100644 --- a/src/views/welcome/hook.tsx +++ b/src/views/welcome/hook.tsx @@ -5,7 +5,7 @@ import { ref, h } from "vue"; export function welcomeUtil() { const currentPlayingIndex = ref(-1); function openDialog(title = "视频", row, index: number) { - console.log(row.video_dir, "row.video_dir"); + console.log(row.video_path, "row.video_path"); addDialog({ title: `${title}用户`, width: "40%", @@ -20,7 +20,7 @@ export function welcomeUtil() { id: "video-" + index, onPlay: () => playVideo(row, index) }, - [h("source", { src: row.video_dir, type: "video/mp4" })] + [h("source", { src: row.video_path, type: "video/mp4" })] ); } }); diff --git a/src/views/welcome/index.vue b/src/views/welcome/index.vue index 507bb54..281e260 100644 --- a/src/views/welcome/index.vue +++ b/src/views/welcome/index.vue @@ -9,7 +9,7 @@ import { type PaginationProps } from "@pureadmin/table"; import { ElMessageBox } from "element-plus"; // import { getConfig } from "@/config"; // import { getToken, formatToken } from "@/utils/auth"; -import { getHomeList, getEvents } from "@/api/home"; +import { getHomeList, getEvents, getScenes, getReasons } from "@/api/home"; import { welcomeUtil } from "./hook"; defineOptions({ @@ -20,10 +20,10 @@ defineOptions({ const { openDialog } = welcomeUtil(); const formInline = reactive({ date: "", - policeId: "", event: "", violation: "", - violationType: "" + violationReason: "", + scene: "" }); const currentPage = ref(1); @@ -37,6 +37,10 @@ const tableData = ref([]); const eventMap = ref({}); +const sceneMap = ref({}); + +const vioReasonMap = ref({}); + const violationMap = ref({ 是: "1", 否: "0", @@ -70,10 +74,10 @@ function onSearch() { const params = { start_time: formInline.date === null ? undefined : formInline.date[0], end_time: formInline.date === null ? undefined : formInline.date[1], - police_id: formInline.policeId || undefined, + scene: formInline.scene || undefined, event_type: formInline.event || undefined, violation: violationMap.value[formInline.violation] || undefined, - violation_type: formInline.violationType || undefined, + violation_type: formInline.violationReason || undefined, page: currentPage.value || undefined, page_size: pageSize.value || undefined }; @@ -165,25 +169,18 @@ const handleClose = (done: () => void) => { }; async function getEvent() { - // axios({ - // url: AdminHostUrl + "events", - // headers: { - // token: formatToken(getToken().accessToken) - // } - // }) - // .then(response => { - // eventMap.value = response.data.data; - // // console.log(eventMap.value); - // }) - // .catch(error => { - // ElMessage({ - // message: "网络暂不通畅", - // type: "warning" - // }); - // console.log(error); - // }); - const { results } = await getEvents(); - eventMap.value = results; + const { data } = await getEvents(); + eventMap.value = data; +} + +async function getScene() { + const { data } = await getScenes(); + sceneMap.value = data; +} + +async function getReason() { + const { data } = await getReasons(); + vioReasonMap.value = data; } function pickerOptions(time) { @@ -202,12 +199,12 @@ const columns: TableColumnList = [ sortable: true }, { - label: "警号", - prop: "police_id", + label: "场景", + prop: "scene", minWidth: 100 }, { - label: "违法行为", + label: "事件类型", prop: "event_type", minWidth: 100 }, @@ -218,24 +215,19 @@ const columns: TableColumnList = [ slot: "violation" }, { - label: "违规行为", - prop: "ai_analysis", - minWidth: 100 - }, - { - label: "时间点", - prop: "relative_time", + label: "违规原因", + prop: "violation_reason", minWidth: 100 }, { label: "缩率图", slot: "image" }, - { - label: "车牌号", - prop: "car_number", - minWidth: 100 - }, + // { + // label: "车牌号", + // prop: "car_number", + // minWidth: 100 + // }, // { // label: "视频", // slot: "video" @@ -294,7 +286,7 @@ onMounted(() => { :default-value="lastMonth" /> - + + + + + - - - + { - - + + @click="getReason()" + > + + @@ -380,8 +392,8 @@ onMounted(() => { { // 本地跨域代理 https://cn.vitejs.dev/config/server-options.html#server-proxy proxy: { "/api": { - target: "http://192.168.10.13:8000", + target: "http://192.168.10.14:8008", changeOrigin: true, rewrite: path => path.replace(/^\/api/, "") }