@@ -328,25 +333,24 @@ const formatDate = (dateStr) => {
// 获取用户类型名称(根据行数据)
const getUserTypeNameByRow = (row) => {
- // userId 不为 0 说明是用户
- if (row.userId && row.userId !== 0) {
+
+//通过看是否有user对象参数判断是否为用户还是用户组类型
+ if(row.user){
return '用户'
- }
- // userGroupId 不为 0 说明是用户组
- if (row.userGroupId && row.userGroupId !== 0) {
+ }else{
return '用户组'
}
+
return '-'
}
// 获取用户类型标签(根据行数据)
const getUserTypeTagByRow = (row) => {
- // 用户用蓝色
- if (row.userId && row.userId !== 0) {
+
+
+ if(row.user){
return 'primary'
- }
- // 用户组用橙色
- if (row.userGroupId && row.userGroupId !== 0) {
+ }else{
return 'warning'
}
return 'info'
diff --git a/src/views/product/ProductList.vue b/src/views/product/ProductList.vue
index b79f443..d7ff893 100644
--- a/src/views/product/ProductList.vue
+++ b/src/views/product/ProductList.vue
@@ -82,8 +82,8 @@
-
- {{ row.inventory_control ? '已启用' : '未启用' }}
+
+ {{ row.inventoryControl ? '已启用' : '未启用' }}
@@ -125,6 +125,7 @@
v-model="dialogVisible"
:title="dialogType === 'add' ? '新增商品' : '编辑商品'"
width="700px"
+ style="margin-top: 300px;"
>
-
-
+
+
@@ -498,6 +499,7 @@ const handleAdd = () => {
// 编辑商品
const handleEdit = (row) => {
+ console.log("更新:",row)
dialogType.value = 'edit'
dialogVisible.value = true
Object.assign(productForm, {
@@ -507,7 +509,7 @@ const handleEdit = (row) => {
content: row.content,
cover_id: row.coverId,
good_group_id: row.goodGroupId,
- inventory_control: row.inventory_control,
+ inventory_control: row.inventoryControl,
inventory: row.inventory,
price: row.price,
pay_num: row.payNum,
@@ -603,10 +605,12 @@ const submitForm = () => {
good_group_id: Number(productForm.good_group_id), // 确保是数字类型
cover_id: productForm.cover_id || 0,
inventory: productForm.inventory || 0,
- price: productForm.price || 0,
+ price: productForm.price/100 || 0,
pay_num: productForm.pay_num || 1,
expire_time: productForm.expire_time || 0,
- recommend_rebate: productForm.recommend_rebate || 0
+ recommend_rebate: productForm.recommend_rebate || 0,
+ inventory_control:productForm.inventoryControl
+
}
console.log('提交的数据:', submitData) // 调试日志
diff --git a/src/views/ticket/TicketChat.vue b/src/views/ticket/TicketChat.vue
index 5ef147e..0de9642 100644
--- a/src/views/ticket/TicketChat.vue
+++ b/src/views/ticket/TicketChat.vue
@@ -545,7 +545,7 @@ const fetchTicketMessages = async (workId) => {
id: msg.id,
content: msg.content !== 'empty' ? msg.content : null,
images: images,
- time: new Date().toLocaleString(), // API 没有返回时间,使用当前时间
+ time: msg.created_at || msg.updated_at || new Date().toLocaleString(),
isAdmin: isAdminMsg,
isSystem: false,
userId: msg.user?.userId,
@@ -730,42 +730,149 @@ const updateTicketStats = () => {
// 格式化消息时间
const formatMessageTime = (timeStr) => {
- const date = new Date(timeStr)
- return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
+ if (!timeStr) return ''
+
+ try {
+ const date = new Date(timeStr)
+ if (isNaN(date.getTime())) return ''
+
+ // 格式化为 HH:MM
+ const hours = String(date.getHours()).padStart(2, '0')
+ const minutes = String(date.getMinutes()).padStart(2, '0')
+ return `${hours}:${minutes}`
+ } catch (e) {
+ console.error('时间格式化失败:', e)
+ return ''
+ }
}
// 格式化列表项时间
const formatTime = (timeStr) => {
- const date = new Date(timeStr)
- const now = new Date()
- const diff = now - date
-
- // 今天内的消息只显示时间
- if (diff < 24 * 60 * 60 * 1000 && date.getDate() === now.getDate()) {
- return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
+ if (!timeStr) return ''; // 空值兜底
+
+ // 步骤1:解析中文时间字符串(核心适配点)
+ let date;
+ try {
+ // 先尝试原生解析(兼容ISO格式)
+ date = new Date(timeStr);
+ // 若原生解析失败(返回Invalid Date),解析中文格式
+ if (isNaN(date.getTime())) {
+ // 正则提取中文时间的年、月、日、时、分、秒
+ const cnTimeMatch = timeStr.match(
+ /(\d{4})年(\d{1,2})月(\d{1,2})日\s*(上午|下午)\s*(\d{1,2}):(\d{1,2}):(\d{1,2})/
+ );
+ if (cnTimeMatch) {
+ const [, year, month, day, period, hour, minute, second] = cnTimeMatch;
+ // 处理下午/上午的小时转换(12小时制转24小时制)
+ let hour24 = parseInt(hour, 10);
+ if (period === '下午' && hour24 !== 12) {
+ hour24 += 12;
+ }
+ if (period === '上午' && hour24 === 12) {
+ hour24 = 0; // 上午12点转为0点
+ }
+ // 构造日期(月份从0开始,需-1)
+ date = new Date(
+ parseInt(year, 10),
+ parseInt(month, 10) - 1,
+ parseInt(day, 10),
+ hour24,
+ parseInt(minute, 10),
+ parseInt(second, 10)
+ );
+ } else {
+ return '无效时间'; // 既不是ISO也不是中文格式
+ }
+ }
+ } catch (e) {
+ console.error('时间解析失败:', e);
+ return '无效时间';
}
+
+ const now = new Date();
+ const dateTime = date.getTime();
+ const nowTime = now.getTime();
+ const diff = nowTime - dateTime;
+
+ // 步骤2:判断“今天”(年/月/日完全一致)
+ const isToday = date.getFullYear() === now.getFullYear() &&
+ date.getMonth() === now.getMonth() &&
+ date.getDate() === now.getDate();
- // 一周内的显示星期几
- if (diff < 7 * 24 * 60 * 60 * 1000) {
- const weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
- return weekdays[date.getDay()]
+ if (isToday) {
+ // 格式化今天的时间(24小时制,补零)
+ const hour = String(date.getHours()).padStart(2, '0');
+ const minute = String(date.getMinutes()).padStart(2, '0');
+ return `${hour}:${minute}`;
}
-
- // 其他显示日期
- return date.toLocaleDateString()
-}
+
+ // 步骤3:判断“一周内”
+ const oneWeek = 7 * 24 * 60 * 60 * 1000;
+ if (diff < oneWeek) {
+ const weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
+ return weekdays[date.getDay()];
+ }
+
+ // 步骤4:格式化其他日期(补零,统一格式:YYYY/MM/DD)
+ const year = date.getFullYear();
+ const month = String(date.getMonth() + 1).padStart(2, '0');
+ const day = String(date.getDate()).padStart(2, '0');
+ return `${year}/${month}/${day}`;
+};
// 格式化日期显示
const formatDate = (timeStr) => {
- const date = new Date(timeStr)
- const now = new Date()
-
- if (date.toDateString() === now.toDateString()) {
- return '今天'
+ console.log("原始时间字符串:", timeStr);
+ if (!timeStr) return ''; // 空值兜底
+
+ let date;
+ // 1. 先尝试原生解析(兼容ISO等标准格式)
+ date = new Date(timeStr);
+
+ // 2. 若原生解析失败,专门解析中文时间格式
+ if (isNaN(date.getTime())) {
+ // 正则匹配:xxxx年xx月xx日 上午/下午 xx:xx:xx
+ const cnTimeReg = /(\d{4})年(\d{1,2})月(\d{1,2})日\s*(上午|下午)\s*(\d{1,2}):(\d{1,2}):(\d{1,2})/;
+ const match = timeStr.match(cnTimeReg);
+
+ if (match) {
+ const [, year, month, day, period, hour, minute, second] = match;
+ // 处理12小时制转24小时制(关键适配)
+ let hour24 = parseInt(hour, 10);
+ if (period === '下午') {
+ hour24 = hour24 === 12 ? 12 : hour24 + 12; // 下午12点=12点,下午1-11点+12
+ } else { // 上午
+ hour24 = hour24 === 12 ? 0 : hour24; // 上午12点=0点,上午1-11点不变
+ }
+ // 手动构造合法的Date对象(月份从0开始,需-1)
+ date = new Date(
+ parseInt(year, 10),
+ parseInt(month, 10) - 1,
+ parseInt(day, 10),
+ hour24,
+ parseInt(minute, 10),
+ parseInt(second, 10)
+ );
+ } else {
+ return '无效时间'; // 非目标格式,返回兜底
+ }
}
-
- return date.toLocaleDateString()
-}
+
+ const now = new Date();
+ // 3. 对比“今天”(按日期维度,忽略时分秒)
+ const isToday = date.getFullYear() === now.getFullYear() &&
+ date.getMonth() === now.getMonth() &&
+ date.getDate() === now.getDate();
+
+ if (isToday) {
+ return '今天';
+ }
+
+ // 4. 格式化非今天的日期(统一格式,避免环境差异)
+ const formattedDate = `${date.getFullYear()}/${String(date.getMonth() + 1).padStart(2, '0')}/${String(date.getDate()).padStart(2, '0')}`;
+
+ return formattedDate;
+};
// 监听显示工单变化,更新消息和滚动
watch(currentTicket, (newVal) => {
@@ -937,7 +1044,7 @@ const refreshTicketMessages = async (workId) => {
id: msg.id,
content: msg.content !== 'empty' ? msg.content : null,
images: images,
- time: new Date().toLocaleString(), // API 没有返回时间,使用当前时间
+ time: msg.created_at || msg.updated_at || new Date().toLocaleString(),
isAdmin: isAdminMsg,
isSystem: false,
userId: msg.user?.userId,