Browse Source

bug: 修改用户日期详情页格式化不生效bug

zhouyuhao 9 tháng trước cách đây
mục cha
commit
8f4b178773

+ 2 - 1
src/stores/modules/user.ts

@@ -71,8 +71,9 @@ export const useUserStore = defineStore('user', {
   },
   actions: {
     setUserInfo(userInfo: any, isFirstLogin?: boolean) {
-      localStorage.setItem('userInfo', JSON.stringify(userInfo))
       this.userInfo = userInfo
+      localStorage.setItem('userInfo', JSON.stringify(userInfo))
+
       if (isFirstLogin !== undefined) {
         localStorage.setItem('isFirstLogin', JSON.stringify(isFirstLogin))
         this.isFirstLogin = isFirstLogin

+ 6 - 4
src/utils/tools.ts

@@ -2,13 +2,15 @@ import moment from 'moment-timezone'
 import { useUserStore } from '@/stores/modules/user'
 
 const userStore = useUserStore()
-const formatString = userStore.dateFormat || 'MM/DD/YYYY'
+const formatString = computed(() => {
+  return userStore.dateFormat || 'MM/DD/YYYY'
+})
 
 export const formatTimezone = (time: string, timezone?: string) => {
   if (!time) return '--'
   let formattedTime = ''
   if (time.length > 12) {
-    formattedTime = moment(time).format(`${formatString} hh:mm A`)
+    formattedTime = moment(time).format(`${formatString.value} hh:mm A`)
     if (!timezone) {
       return formattedTime
     }
@@ -18,7 +20,7 @@ export const formatTimezone = (time: string, timezone?: string) => {
     utcOffset = `(UTC${timeZoneOffset.slice(0, 3)})`
     return `${formattedTime} ${utcOffset}`
   } else {
-    formattedTime = moment(time).format(formatString)
+    formattedTime = moment(time).format(formatString.value)
     return formattedTime
   }
 }
@@ -37,7 +39,7 @@ export const getTimezone = (timezone: string): string => {
 export const formatTimezoneByUTCorGMT = (time: string, timezone: string) => {
   if (!time) return '--'
   let formattedTime = ''
-  formattedTime = moment(time).format(`${formatString} hh:mm A`)
+  formattedTime = moment(time).format(`${formatString.value} hh:mm A`)
   let gmtOffset = ''
   if (timezone != null) {
     const timeZoneOffset = moment().tz(timezone).format('Z')

+ 0 - 1
src/views/Dashboard/src/components/PieChart.vue

@@ -116,7 +116,6 @@ const initOption: any = reactive({
       show: true,
       // formatter: '{d}%({c})',
       formatter: (params) => {
-        console.log(params, 'params')
         return `{name|${params.percent}%}\n {time|(${formatNumber(params.value)})}`
       },
       alignTo: 'labelLine',

+ 28 - 21
src/views/SystemSettings/src/components/PersonalProfile.vue

@@ -77,7 +77,9 @@ const initNumbersFormat = () => {
 }
 const numbersFormat = ref(initNumbersFormat())
 
+const loading = ref(false)
 const saveConfig = (model: string) => {
+  loading.value = true
   let params = {}
   if (model === 'profile') {
     params = {
@@ -92,32 +94,37 @@ const saveConfig = (model: string) => {
       numbers_format: numbersFormat.value
     }
   }
-  $api.saveUserInfo(params).then((res: any) => {
-    if (res.code === 200) {
-      const updatedInfo =
-        model === 'profile'
-          ? {
-              ...userStore.userInfo,
-              first_name: form.firstName,
-              last_name: form.lastName
-            }
-          : {
-              ...userStore.userInfo,
-              date_format: monthFormat.value,
-              numbers_format: numbersFormat.value
-            }
+  $api
+    .saveUserInfo(params)
+    .then((res: any) => {
+      if (res.code === 200) {
+        const updatedInfo =
+          model === 'profile'
+            ? {
+                ...userStore.userInfo,
+                first_name: form.firstName,
+                last_name: form.lastName
+              }
+            : {
+                ...userStore.userInfo,
+                date_format: monthFormat.value,
+                numbers_format: numbersFormat.value
+              }
 
-      userStore.setUserInfo(updatedInfo)
-      ElMessage.success('Save successfully')
-    } else {
-      ElMessage.error('Save failed')
-    }
-  })
+        userStore.setUserInfo(updatedInfo)
+        ElMessage.success('Save successfully')
+      } else {
+        ElMessage.error('Save failed')
+      }
+    })
+    .finally(() => {
+      loading.value = false
+    })
 }
 </script>
 
 <template>
-  <div class="personal-profile">
+  <div class="personal-profile" v-vloading="loading">
     <div class="basic-information">
       <div class="title">Basic Information</div>
       <div class="content">