From b0268b83c34bbfc5e2dca74bdf4374241b3e2b55 Mon Sep 17 00:00:00 2001 From: fuxiaochun Date: Tue, 15 Aug 2023 02:04:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=AD=E5=BF=83=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E8=81=94=E8=B0=83=E5=AE=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/auth/Login.vue | 2 +- src/layouts/Header.vue | 2 +- src/router/index.js | 11 +- src/utils/format.js | 58 +++++ .../ucenter/components/updateContactModal.vue | 212 ++++++++++++++++++ src/views/ucenter/order.vue | 145 ++++++++++++ src/views/ucenter/userInfo.vue | 120 +++++----- vite.config.js | 4 +- 8 files changed, 482 insertions(+), 72 deletions(-) create mode 100644 src/utils/format.js create mode 100644 src/views/ucenter/components/updateContactModal.vue create mode 100644 src/views/ucenter/order.vue diff --git a/src/components/auth/Login.vue b/src/components/auth/Login.vue index c4f7c0b..826a5ff 100644 --- a/src/components/auth/Login.vue +++ b/src/components/auth/Login.vue @@ -218,7 +218,7 @@ const getUserInfo = () => { http('/api/user/profile', {}, 'get').then(res => { localCache.set('userInfo', res.data); userInfo.updateUserInfo(res.data); - // window.location.reload(); + window.location.reload(); }).catch(err => { showToast(err.message); }) diff --git a/src/layouts/Header.vue b/src/layouts/Header.vue index 567d49e..fc8ac56 100644 --- a/src/layouts/Header.vue +++ b/src/layouts/Header.vue @@ -94,7 +94,7 @@ const onLogout = ()=>{ http('/api/auth/logout').then(res => { localCache.remove('userInfo'); localCache.remove('auth'); - userInfo.updateUserInfo(); + userInfo.updateUserInfo({}); showToast('已退出登录!'); // window.location.replace('/'); }).catch(err => { diff --git a/src/router/index.js b/src/router/index.js index 7c716d3..9f13d0a 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -35,7 +35,16 @@ const router = createRouter({ group: 'ucenter' }, component: () => import("@/views/ucenter/userInfo.vue"), - } + }, + { + path: 'order', + name: 'order', + meta: { + title: '我的订单', + group: 'ucenter' + }, + component: () => import("@/views/ucenter/order.vue"), + }, ] }, ] diff --git a/src/utils/format.js b/src/utils/format.js new file mode 100644 index 0000000..a570de0 --- /dev/null +++ b/src/utils/format.js @@ -0,0 +1,58 @@ +export function DateFormat(date, format) { + var o = { + 'M+': date.getMonth() + 1, + 'd+': date.getDate(), + 'h+': date.getHours(), + 'm+': date.getMinutes(), + 's+': date.getSeconds(), + 'q+': Math.floor((date.getMonth() + 3) / 3), + 'S': date.getMilliseconds() //毫秒 + }; + if (/(y+)/.test(format)) + format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)); + for (let k in o) + if (new RegExp('(' + k + ')').test(format)) + format = format.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length))); + return format; +} + + + +export function formatDate(dateTime = null, formatStr = 'yyyy-MM-dd HH:mm:ss') { + + if (!dateTime) return '' + let date + // 若传入时间为假值,则取当前时间 + if (!dateTime) { + date = new Date() + } else if (/^\d{10}$/.test(dateTime.toString().trim())) { + date = new Date(dateTime * 1000) + } else if (typeof dateTime === 'string' && /^\d+$/.test(dateTime.trim())) { + date = new Date(Number(dateTime)) + } else { + date = new Date( + typeof dateTime === 'string' ? + dateTime.replace(/-/g, '/') : + dateTime + ) + } + + const timeSource = { + 'y': date.getFullYear().toString(), // 年 + 'M': (date.getMonth() + 1).toString().padStart(2, '0'), // 月 + 'd': date.getDate().toString().padStart(2, '0'), // 日 + 'H': date.getHours().toString().padStart(2, '0'), // 时 + 'm': date.getMinutes().toString().padStart(2, '0'), // 分 + 's': date.getSeconds().toString().padStart(2, '0') // 秒 + + } + + for (const key in timeSource) { + const [ret] = new RegExp(`${key}+`).exec(formatStr) || [] + if (ret) { + const beginIndex = key === 'y' && ret.length === 2 ? 2 : 0 + formatStr = formatStr.replace(ret, timeSource[key].slice(beginIndex)) + } + } + return formatStr + } \ No newline at end of file diff --git a/src/views/ucenter/components/updateContactModal.vue b/src/views/ucenter/components/updateContactModal.vue new file mode 100644 index 0000000..47e7902 --- /dev/null +++ b/src/views/ucenter/components/updateContactModal.vue @@ -0,0 +1,212 @@ + + + + + \ No newline at end of file diff --git a/src/views/ucenter/order.vue b/src/views/ucenter/order.vue new file mode 100644 index 0000000..6bfaa6e --- /dev/null +++ b/src/views/ucenter/order.vue @@ -0,0 +1,145 @@ + + + + + \ No newline at end of file diff --git a/src/views/ucenter/userInfo.vue b/src/views/ucenter/userInfo.vue index 7870995..503c80e 100644 --- a/src/views/ucenter/userInfo.vue +++ b/src/views/ucenter/userInfo.vue @@ -13,7 +13,7 @@
*地区
-
@@ -75,9 +64,6 @@
-
- 保存 -
会员信息
@@ -101,8 +87,12 @@
- +
+ 保存 +
+ + @@ -112,7 +102,7 @@ import http from '@/io/http'; import { localCache } from '@/io/cache'; import { showToast } from 'vant'; import { useUserInfo } from '@/stores/userInfo'; -// import UpdateContactModal from './components/updateContactModal.vue'; +import UpdateContactModal from './components/updateContactModal.vue'; import { useRouter, useRoute } from 'vue-router'; const router = useRouter(); @@ -124,40 +114,37 @@ const updateType = ref(''); const name = ref(); const industry = ref(); // 行业 const job = ref(); // 职业 -const provinces = ref([]); -const cities = ref([]); -const areas = ref([]); +const areaValue = ref(); const province = ref(); const city = ref(); const area = ref(); const showAreaPopup = ref(false); - +const cascaderValue = ref(); const options = ref([]); -const fieldValue = ref([]); -const cascaderValue = ref([]); -const onFinish = (v)=>{ - console.log(v); +const onFinish = (data)=>{ + showAreaPopup.value = false; + let selectedOptions = data.selectedOptions || []; + let _areaValue = []; + selectedOptions.forEach((v,i)=>{ + _areaValue.push(v.name); + i == 0 && (province.value = v.id); + i == 1 && (city.value = v.id); + i == 2 && (area.value = v.id); + }); + areaValue.value = _areaValue.join('/'); } -onBeforeMount(() => { - getAreas(); -}); onMounted(() => { - initData(); - if (province.value) { - getAreaByPid(province.value, res => { - cities.value = res.data; - }); - } - if (city.value) { - getAreaByPid(city.value, res => { - areas.value = res.data; - }); + let userData = localCache.get('userInfo') || {}; + if(userData.id){ + initData(); + getAreas(); } + }); const initData = () => { @@ -168,41 +155,26 @@ const initData = () => { province.value = data.province_id; city.value = data.city_id; area.value = data.district_id; + cascaderValue.value = data.district_id; }; - +const initAreaData = (data = [])=>{ + let _province = data.filter(v=>v.id == province.value)[0]; + let _city = _province.children.filter(v=>v.id == city.value)[0]; + let _area = _city.children.filter(v=>v.id == area.value)[0]; + areaValue.value = [_province, _city, _area].map(v=>v.name).join('/'); +}; const getAreas = () => { http('/api/region/tree', {}, 'get').then(res => { options.value = res.data; + initAreaData(res.data); }).catch(err => { showToast(err.message); }); } -const getAreaByPid = (parent_key, cb) => { - http('/api/region', { parent_key }, 'get').then(res => { - cb(res); - }).catch(err => { - showToast(err.message); - }); -} - -const provinceChoosed = (pid) => { - city.value = null; - area.value = null; - getAreaByPid(pid, res => { - cities.value = res.data; - }); -}; -const cityChoosed = (pid) => { - area.value = null; - getAreaByPid(pid, res => { - areas.value = res.data; - }); -}; - const onUpdateContactOk = (newVal) => { let temp = { ...userInfo.userData }; if (updateType.value == 'tel') { @@ -254,7 +226,7 @@ const onSave = () => { }; http('/api/user/profile', formData).then(res => { - message.success('保存成功!'); + showToast('保存成功!'); let temp = { ...userInfo.userData }; temp.name = name.value; temp.province_id = province.value; @@ -277,7 +249,10 @@ const jump = (path) => {