diff --git a/App.vue b/App.vue index 0c1c10b..189a16c 100644 --- a/App.vue +++ b/App.vue @@ -3,62 +3,57 @@ App.vue本身不是页面,这里不能编写视图元素,也就是没有 diff --git a/pageMarket/limitDiscount/index.vue b/pageMarket/limitDiscount/index.vue index bb680ba..80a18c6 100644 --- a/pageMarket/limitDiscount/index.vue +++ b/pageMarket/limitDiscount/index.vue @@ -11,26 +11,29 @@ - + 活动时间: - {{ item.updateTime }} + {{ item.validStartTime }}至{{ item.validEndTime }} {{ item.useDays }} + + {{ convertTimeFormat(item.useStartTime) }} - {{ convertTimeFormat(item.useEndTime) }} + 折扣:{{ item.discountRate }}% - 删除 + 删除 - 编辑 + 编辑 @@ -45,6 +48,7 @@ import { reactive, ref } from 'vue'; import { onLoad, onShow, onReachBottom } from '@dcloudio/uni-app'; import { limitTimeDiscountPage, limitTimeDiscountDel } from '@/http/api/market/index.js'; import go from '@/commons/utils/go.js'; +import { convertTimeFormat } from '@/utils/index.js'; // 去编辑 function editorHandle(item) { @@ -118,15 +122,21 @@ const tableData = reactive({ // 滚动到底部 onReachBottom(() => { - tableData.page++; - limitTimeDiscountPageAjax(); + if (tableData.status != 'nomore') { + tableData.page++; + limitTimeDiscountPageAjax(); + } }); // 获取限时折扣分页 async function limitTimeDiscountPageAjax() { try { + uni.showLoading({ + title: '加载中...', + mask: true + }); const res = await limitTimeDiscountPage({ - page: 1, + page: tableData.page, size: 10, startTime: '', endTime: '' @@ -142,6 +152,9 @@ async function limitTimeDiscountPageAjax() { } catch (error) { console.log(error); } + setTimeout(() => { + uni.hideLoading(); + }, 500); } onShow(() => { @@ -159,7 +172,7 @@ page { diff --git a/utils/index.js b/utils/index.js index ce2d838..8216033 100644 --- a/utils/index.js +++ b/utils/index.js @@ -1,3 +1,7 @@ +import dayjs from 'dayjs'; +import customParseFormat from 'dayjs/plugin/customParseFormat'; +dayjs.extend(customParseFormat); // 注册插件 + /** * 过滤输入,只允许数字和最多两位小数 * @param {string} value - 输入框当前值 @@ -41,4 +45,30 @@ export function filterNumberInput(value, isIntegerOnly = false) { } return filtered; -} \ No newline at end of file +} + +/** + * 时间格式互转:HH:mm → HH:mm:ss;HH:mm:ss → HH:mm + * @param {string} timeStr - 输入的时间字符串 + * @returns {string} 转换后的时间字符串 + */ +export const convertTimeFormat = (timeStr) => { + if (!timeStr) return '00:00'; + + // 正则判断格式 + const isHms = /^\d{1,2}:\d{2}:\d{2}$/.test(timeStr); // HH:mm:ss + const isHm = /^\d{1,2}:\d{2}$/.test(timeStr); // HH:mm + + if (isHm) { + // HH:mm → 解析后格式化为 HH:mm:ss + return dayjs(timeStr, 'HH:mm').format('HH:mm:ss'); + } + + if (isHms) { + // HH:mm:ss → 解析后格式化为 HH:mm + return dayjs(timeStr, 'HH:mm:ss').format('HH:mm'); + } + + // 非法格式兜底 + return '00:00'; +}; \ No newline at end of file