From 2293c7205bbd692ff085032d3cb841f541453ddc Mon Sep 17 00:00:00 2001
From: hx <190679152@qq.com>
Date: Tue, 17 Mar 2026 18:05:03 +0800
Subject: [PATCH] =?UTF-8?q?b=E7=AB=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/utils/request.js | 7 +++
src/utils/ruoyi.js | 97 +++++++++++++++++++++----------
src/views/device/device/index.vue | 38 +++++++++++-
src/views/system/user/index.vue | 32 ++++++----
4 files changed, 130 insertions(+), 44 deletions(-)
diff --git a/src/utils/request.js b/src/utils/request.js
index 81b91ca..7557743 100644
--- a/src/utils/request.js
+++ b/src/utils/request.js
@@ -51,6 +51,13 @@ service.interceptors.request.use(
if (getToken() && !isToken) {
config.headers["Authorization"] = "Bearer " + getToken(); // 让每个请求携带自定义token 请根据实际情况自行修改
}
+ const clientTimeZone =
+ (Intl.DateTimeFormat &&
+ Intl.DateTimeFormat().resolvedOptions &&
+ Intl.DateTimeFormat().resolvedOptions().timeZone) ||
+ "Asia/Shanghai";
+ console.log(`时区 :${clientTimeZone}`);
+ config.headers["X-Timezone"] = clientTimeZone;
// get请求映射params参数
if (config.method === "get" && config.params) {
let url = config.url + "?" + tansParams(config.params);
diff --git a/src/utils/ruoyi.js b/src/utils/ruoyi.js
index 2834e83..14b2d1b 100644
--- a/src/utils/ruoyi.js
+++ b/src/utils/ruoyi.js
@@ -6,49 +6,86 @@ import { Message } from "element-ui";
*/
const baseURL = process.env.VUE_APP_BASE_API;
// 日期格式化
+// export function parseTime(time, pattern) {
+// if (arguments.length === 0 || !time) {
+// return null;
+// }
+// const format = pattern || "{y}-{m}-{d} {h}:{i}:{s}";
+// let date;
+// if (typeof time === "object") {
+// date = time;
+// } else {
+// if (typeof time === "string" && /^[0-9]+$/.test(time)) {
+// time = parseInt(time);
+// } else if (typeof time === "string") {
+// time = time
+// .replace(new RegExp(/-/gm), "/")
+// .replace("T", " ")
+// .replace(new RegExp(/\.[\d]{3}/gm), "");
+// }
+// if (typeof time === "number" && time.toString().length === 10) {
+// time = time * 1000;
+// }
+// date = new Date(time);
+// }
+// const formatObj = {
+// y: date.getFullYear(),
+// m: date.getMonth() + 1,
+// d: date.getDate(),
+// h: date.getHours(),
+// i: date.getMinutes(),
+// s: date.getSeconds(),
+// a: date.getDay(),
+// };
+// const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
+// let value = formatObj[key];
+// // Note: getDay() returns 0 on Sunday
+// if (key === "a") {
+// return ["日", "一", "二", "三", "四", "五", "六"][value];
+// }
+// if (result.length > 0 && value < 10) {
+// value = "0" + value;
+// }
+// return value || 0;
+// });
+// return time_str;
+// }
export function parseTime(time, pattern) {
- if (arguments.length === 0 || !time) {
- return null;
- }
+ if (!time) return null;
+
const format = pattern || "{y}-{m}-{d} {h}:{i}:{s}";
- let date;
- if (typeof time === "object") {
- date = time;
+
+ // 把字符串当作 +8 时区
+ if (typeof time === "string") {
+ time = time.replace(/-/g, "/");
+ time = new Date(time + " GMT+0800");
} else {
- if (typeof time === "string" && /^[0-9]+$/.test(time)) {
- time = parseInt(time);
- } else if (typeof time === "string") {
- time = time
- .replace(new RegExp(/-/gm), "/")
- .replace("T", " ")
- .replace(new RegExp(/\.[\d]{3}/gm), "");
- }
- if (typeof time === "number" && time.toString().length === 10) {
- time = time * 1000;
- }
- date = new Date(time);
+ time = new Date(time);
}
+
const formatObj = {
- y: date.getFullYear(),
- m: date.getMonth() + 1,
- d: date.getDate(),
- h: date.getHours(),
- i: date.getMinutes(),
- s: date.getSeconds(),
- a: date.getDay(),
+ y: time.getFullYear(),
+ m: time.getMonth() + 1,
+ d: time.getDate(),
+ h: time.getHours(),
+ i: time.getMinutes(),
+ s: time.getSeconds(),
+ a: time.getDay(),
};
- const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
+
+ return format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
let value = formatObj[key];
- // Note: getDay() returns 0 on Sunday
+
if (key === "a") {
- return ["日", "一", "二", "三", "四", "五", "六"][value];
+ return ["日","一","二","三","四","五","六"][value];
}
+
if (result.length > 0 && value < 10) {
value = "0" + value;
}
- return value || 0;
+
+ return value;
});
- return time_str;
}
export async function handleCopy(copyText) {
diff --git a/src/views/device/device/index.vue b/src/views/device/device/index.vue
index d6060eb..1de4cd5 100644
--- a/src/views/device/device/index.vue
+++ b/src/views/device/device/index.vue
@@ -17,6 +17,10 @@
+
+
+
+
@@ -62,6 +66,8 @@
分配设备
+
+
@@ -417,6 +436,8 @@ function getDefaultQueryParams() {
battery: null,
lastReportedTime: null,
lastLocationTime: null,
+ lastAddress: null,
+ lastLocationSort: undefined,
orderCode: null,
};
}
@@ -650,10 +671,21 @@ export default {
this.resetForm("queryForm");
}
this.queryParams = getDefaultQueryParams();
+ if (this.$refs.deviceTable) {
+ this.$refs.deviceTable.clearSort();
+ }
this.searchBusinessName = "";
this.searchBusinessSelectVisible = false;
this.handleQuery();
},
+ handleTableSortChange({ prop, order }) {
+ if (prop !== "lastLocationTime") {
+ return;
+ }
+ this.queryParams.lastLocationSort =
+ order === "ascending" ? "asc" : order === "descending" ? "desc" : undefined;
+ this.handleQuery();
+ },
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map((item) => item.id);
diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue
index ccfb164..16cad1a 100644
--- a/src/views/system/user/index.vue
+++ b/src/views/system/user/index.vue
@@ -32,8 +32,8 @@
size="small"
style="width: 240px"
>
-
-
+
+
@@ -101,8 +101,8 @@
@@ -209,8 +209,8 @@
- 启用
- 禁用
+ 启用
+ 禁用
@@ -466,6 +466,15 @@ export default {
// });
},
methods: {
+ normalizeBooleanStatus(value) {
+ if (value === true || value === "true" || value === 1 || value === "1") {
+ return true;
+ }
+ if (value === false || value === "false" || value === 0 || value === "0") {
+ return false;
+ }
+ return false;
+ },
normalizeRoleOptions(list = []) {
return (Array.isArray(list) ? list : []).map(item => ({
roleId: item.roleId != null ? item.roleId : item.id,
@@ -485,7 +494,7 @@ export default {
listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
this.userList = response.data.list.map(user => ({
...user,
- status: String(user.status) // 确保状态是字符串类型
+ status: this.normalizeBooleanStatus(user.status)
}));
// console.log(this.userList[0].googleAuthSecret)
this.total = Number(response.data.total);
@@ -511,7 +520,7 @@ export default {
},
// 用户状态修改
handleStatusChange(row) {
- let text = row.status === "0" ? "启用" : "停用";
+ let text = row.status ? "禁用" : "启用";
this.$confirm('确认要"' + text + '""' + row.account + '"用户吗?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
@@ -521,7 +530,7 @@ export default {
}).then(() => {
this.msgSuccess(text + "成功");
}).catch(function() {
- row.status = row.status === "0" ? "1" : "0";
+ row.status = !row.status;
});
},
// 取消按钮
@@ -544,7 +553,7 @@ export default {
phonenumber: undefined,
email: undefined,
sex: undefined,
- status: 0,
+ status: false,
remark: undefined,
postIds: [],
roleIds: []
@@ -608,6 +617,7 @@ export default {
this.form = Object.assign({}, data, {
postIds: userRes.postIds || [],
roleIds: roleIds,
+ status: this.normalizeBooleanStatus(data.status),
passwordHash: undefined
});
this.$set(this.form, "roleIds", roleIds);
@@ -674,7 +684,7 @@ export default {
nickName: this.employeeForm.nickName,
account: this.employeeForm.account,
passwordHash: this.employeeForm.passwordHash,
- status: 0,
+ status: false,
roleIds: (this.employeeForm.roleIds || []).map(id => Number(id))
};
addEmployeeUser(submitData).then(() => {