diff --git a/src/App.vue b/src/App.vue index 9280810..ff5e167 100644 --- a/src/App.vue +++ b/src/App.vue @@ -3,6 +3,7 @@
+ \ No newline at end of file diff --git a/src/router/index.ts b/src/router/index.ts index 25c5173..ec12b5f 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -23,17 +23,28 @@ const router = createRouter({ name: 'brand', component: () => import('../views/brand/index.vue') }, - { - path: '/digitalItem', - name: 'digitalItem', - component: () => import('../views/digitalItem/index.vue') - }, + { + path: '/digitalItem', + name: 'digitalItem', + component: () => import('../views/digitalItem/index.vue'), + meta: { cache: true } + }, + { + path: '/digitalItem/:id', + name: 'digitalItemDetail', + component: () => import('../views/digitalDetail/index.vue'), + }, { path: '/settings', name: 'settings', component: () => import('@/views/setting/index.vue'), meta: { cache: true } }, + { + path: '/shoppingCart',// 购物车 + name: 'shoppingCart', + component: () => import('@/views/shoppingCart/index.vue') + }, { path: '/notifications', name: 'notifications', diff --git a/src/utils/tools.ts b/src/utils/tools.ts index 69403ed..738e4b2 100644 --- a/src/utils/tools.ts +++ b/src/utils/tools.ts @@ -53,9 +53,9 @@ export function generateUUID(): string { if (typeof crypto !== 'undefined' && crypto.randomUUID) { return crypto.randomUUID() } - + // 备用方案:手动生成UUID v4 - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { const r = Math.random() * 16 | 0 const v = c === 'x' ? r : (r & 0x3 | 0x8) return v.toString(16) @@ -70,39 +70,37 @@ export { /** 时间格式化-自定义格式 * @param value 时间对象|时间戳|时间字符串 - * @param format 格式化字符串,默认值为 'yyyy-MM-dd HH:mm:ss' + * @param format 格式化字符串,默认值为 'YYYY-MM-DD HH:mm:ss' * @returns 格式化后的时间字符串 */ -export function FormatDate(value: Date | number | string, format: string = 'yyyy-MM-dd HH:mm:ss') { - const date = new Date(value); - const yyyy = String(date.getFullYear()); - const yy = String(date.getFullYear()).slice(-2); - const MM = String(date.getMonth() + 1).padStart(2, '0'); - const M = String(date.getMonth() + 1); - const dd = String(date.getDate()).padStart(2, '0'); - const d = String(date.getDate()); - const HH = String(date.getHours()).padStart(2, '0'); - const H = String(date.getHours()); - const mm = String(date.getMinutes()).padStart(2, '0'); - const m = String(date.getMinutes()); - const ss = String(date.getSeconds()).padStart(2, '0'); - const s = String(date.getSeconds()); - const str = format.replaceAll('yyyy', yyyy) - .replaceAll('yy', yy) - .replaceAll('MM', MM) - .replaceAll('M', M) - .replaceAll('dd', dd) - .replaceAll('d', d) - .replaceAll('HH', HH) - .replaceAll('H', H) - .replaceAll('mm', mm) - .replaceAll('m', m) - .replaceAll('ss', ss) - .replaceAll('s', s); - return str; +export function FormatDate(value: Date | number | string, format: string = 'YYYY-MM-DD HH:mm:ss') { + const d = new Date(value); + if (!d || isNaN(d.getTime())) return 'Invalid Date'; + const pad = (n) => String(n).padStart(2, '0'); + const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; + const tokens = { + YYYY: d.getFullYear(), + YY: String(d.getFullYear()).slice(-2), + MM: pad(d.getMonth() + 1), + M: d.getMonth() + 1, + SM: months[d.getMonth()], + DD: pad(d.getDate()), + D: d.getDate(), + HH: pad(d.getHours()), + H: d.getHours(), + hh: pad(d.getHours() % 12 || 12), + h: d.getHours() % 12 || 12, + mm: pad(d.getMinutes()), + m: d.getMinutes(), + ss: pad(d.getSeconds()), + s: d.getSeconds(), + A: d.getHours() < 12 ? 'AM' : 'PM', + a: d.getHours() < 12 ? 'am' : 'pm' + } + const reg = new RegExp(Object.keys(tokens).join('|'), 'g') + return format.replace(reg, match => tokens[match]); } - /** * 下载图片 * @param list 图片列表 @@ -163,7 +161,7 @@ export function encryptPassword(password: string): string { * @param url 图片URL * @returns 无 */ -export async function shareImageToWhatsapp (url: string){ +export async function shareImageToWhatsapp(url: string) { // 把图片 URL 转为 Blob const blob = await fetch(url).then((res) => res.blob()) @@ -195,3 +193,19 @@ export function CountDown(time: number) { const ss = String(time % 60).padStart(2, '0'); return `${mm}:${ss}`; } + +/** + * 字节转换为可读格式 + * @param {number} bytes - 字节数 + * @param {number} decimals - 保留小数位数,默认2位 + * @returns {string} 格式化后的字符串 + */ +export function FormatBytes(bytes, decimals = 2) { + if (bytes === 0) return '0 B'; + if (!bytes || isNaN(bytes)) return '0 B'; + const k = 1024; + const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + const i = Math.floor(Math.log(bytes) / Math.log(k)); + const value = bytes / Math.pow(k, i); + return `${Number(value.toFixed(decimals))} ${sizes[i]}`; +} diff --git a/src/views/brand/index.vue b/src/views/brand/index.vue index 9e2999d..e8350d5 100644 --- a/src/views/brand/index.vue +++ b/src/views/brand/index.vue @@ -2,13 +2,21 @@ import { ref, onMounted, onUnmounted, reactive, toRefs } from "vue"; import CommodityList from "./commodity-list.vue"; import MerchantInfo from "./merchant-info.vue"; +import { useRouter } from "vue-router"; +import myEvent from '@/utils/myEvent' //const props = defineProps({ //}) //const emit = defineEmits([ //]) +const router = useRouter() let data = reactive({ }) -const addShopping = (item) => {} +const addShopping = (item) => { + myEvent.emit('addShopping', item) +} +const openDetail = (item) => { + router.push({name: 'digitalDetail', params: {id: item.id}}) +} onMounted(()=>{ }) onUnmounted(()=>{ @@ -26,7 +34,7 @@ const {} = toRefs(data);
- +
diff --git a/src/views/collectionStory/detail/index.vue b/src/views/collectionStory/detail/index.vue index 9633a5f..2605e1c 100644 --- a/src/views/collectionStory/detail/index.vue +++ b/src/views/collectionStory/detail/index.vue @@ -7,8 +7,9 @@ import feelingWithAiDA from "./feelingWithAiDA.vue"; import CommodityItem from "@/components/CommodityItem.vue"; //const props = defineProps({ //}) -//const emit = defineEmits([ -//]) +const emit = defineEmits([ + 'addShopping' +]) let data = reactive({ }) const list = ref([ @@ -27,7 +28,7 @@ const list = ref([ }, ]) const addShopping = (item) => { - console.log(item); + emit('addShopping', item) } onMounted(()=>{ }) diff --git a/src/views/collectionStory/index.vue b/src/views/collectionStory/index.vue index 3fc0a59..701a696 100644 --- a/src/views/collectionStory/index.vue +++ b/src/views/collectionStory/index.vue @@ -1,13 +1,16 @@ + + \ No newline at end of file diff --git a/src/views/digitalItem/commodity-list.vue b/src/views/digitalItem/commodity-list.vue index 9c99b70..199ec6a 100644 --- a/src/views/digitalItem/commodity-list.vue +++ b/src/views/digitalItem/commodity-list.vue @@ -4,7 +4,8 @@ import img from "@/assets/images/collectionStory/Rectangle.png"; //const props = defineProps({ //}) const emit = defineEmits([ - 'addShopping' + 'addShopping', + 'openDetail' ]) let data = reactive({ }) @@ -47,6 +48,9 @@ const type = ref('All') const addShopping = (item) => { emit('addShopping', item) } +const openDetail = (item) => { + emit('openDetail', item) +} onMounted(()=>{ }) onUnmounted(()=>{ @@ -58,7 +62,7 @@ const {} = toRefs(data);
- +
diff --git a/src/views/digitalItem/index.vue b/src/views/digitalItem/index.vue index dcfb1cd..897cbc5 100644 --- a/src/views/digitalItem/index.vue +++ b/src/views/digitalItem/index.vue @@ -1,14 +1,31 @@