瀏覽代碼

转化日期格式

吴sir 3 月之前
父節點
當前提交
b7880cbeb9
共有 6 個文件被更改,包括 71 次插入12 次删除
  1. 20 0
      package-lock.json
  2. 1 0
      package.json
  3. 12 2
      src/App.vue
  4. 4 0
      src/store/modules/systemStore.js
  5. 32 10
      src/utils/axios.js
  6. 2 0
      src/views/tariffManagement/index.vue

+ 20 - 0
package-lock.json

@@ -17,6 +17,7 @@
         "less": "^4.2.0",
         "less-loader": "^12.2.0",
         "lodash": "^4.17.21",
+        "moment-timezone": "^0.5.46",
         "monaco-editor": "^0.52.0",
         "pinia": "^2.1.7",
         "qrcode.vue": "^3.6.0",
@@ -3169,6 +3170,25 @@
         "node": ">=0.10.0"
       }
     },
+    "node_modules/moment": {
+      "version": "2.30.1",
+      "resolved": "https://registry.npmmirror.com/moment/-/moment-2.30.1.tgz",
+      "integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==",
+      "engines": {
+        "node": "*"
+      }
+    },
+    "node_modules/moment-timezone": {
+      "version": "0.5.46",
+      "resolved": "https://registry.npmmirror.com/moment-timezone/-/moment-timezone-0.5.46.tgz",
+      "integrity": "sha512-ZXm9b36esbe7OmdABqIWJuBBiLLwAjrN7CE+7sYdCCx82Nabt1wHDj8TVseS59QIlfFPbOoiBPm6ca9BioG4hw==",
+      "dependencies": {
+        "moment": "^2.29.4"
+      },
+      "engines": {
+        "node": "*"
+      }
+    },
     "node_modules/monaco-editor": {
       "version": "0.52.0",
       "resolved": "https://registry.npmmirror.com/monaco-editor/-/monaco-editor-0.52.0.tgz",

+ 1 - 0
package.json

@@ -18,6 +18,7 @@
     "less": "^4.2.0",
     "less-loader": "^12.2.0",
     "lodash": "^4.17.21",
+    "moment-timezone": "^0.5.46",
     "monaco-editor": "^0.52.0",
     "pinia": "^2.1.7",
     "qrcode.vue": "^3.6.0",

+ 12 - 2
src/App.vue

@@ -13,8 +13,7 @@
 import { ref, onMounted, nextTick, provide } from "vue"
 import { useDarkThemeHook, useLang } from '@/hooks'
 import { useSystemStore } from '@/store/modules/systemStore'
-
-
+import axios from "axios";
 const isRouterActive = ref(true)
 // 全局语言
 const { locale } = useLang()
@@ -30,6 +29,16 @@ provide('reloadRoutePage', () => {
   })
 })
 
+// 获取当前用户ip
+async function getIpClient() {
+  try {
+    const response = await axios.get('https://ipinfo.io/json');
+    systemStore.USER_IP =  response.data
+  } catch (error) {
+    console.error(error);
+  }
+}
+
 
 onMounted(async () => {
   const getLoadingNode = document.getElementById('Loading')
@@ -37,6 +46,7 @@ onMounted(async () => {
   if (getLoadingNode) {
     body.removeChild(getLoadingNode)
   }
+  getIpClient()
 })
 </script>
 

+ 4 - 0
src/store/modules/systemStore.js

@@ -11,6 +11,7 @@ const INITIALIZE = {
   menuSecondLongShow: false,
   user_login_information: "",
   stsClientInfo: {},
+  USER_IP: {}, // 当前用户ip地址
 };
 try {
   const SYSTEM_STORE = getLocalStorage("SYSTEM_STORE")
@@ -28,6 +29,9 @@ export const useSystemStore = defineStore({
     ...INITIALIZE,
   }),
   getters: {
+    getUserIp(){
+      return this.USER_IP
+    },
     getLocalLoading() {
       return this.local_loading
     },

+ 32 - 10
src/utils/axios.js

@@ -2,11 +2,11 @@ import axios from "axios";
 import Router from "@/router";
 import { Message, Notification } from "@arco-design/web-vue";
 import { useSystemStore } from "@/store/modules/systemStore";
-
+import moment from 'moment-timezone';
 import { fn_logout } from "@/utils";
 
 const axiosInstance = axios.create({
-  // baseURL: `${import.meta.env.PROD ? import.meta.env.VITE_PRO_PATH : ''}/api`,
+  // baseURL: `${import.meta.env.PROD? import.meta.env.VITE_PRO_PATH : ''}/api`,
   baseURL: import.meta.env.BASE_URL + "api",
   timeout: 300000,
 });
@@ -18,7 +18,7 @@ const requestState = {
   beOverdue: [886],
   // 没有访问权限
   NotAccessRight: [500],
-  // 异常code
+  // 异常 code
   exception: [400],
 };
 
@@ -49,10 +49,15 @@ axiosInstance.interceptors.response.use(
   (res) => {
     const systemStore = useSystemStore();
     systemStore.localLoading();
-    const { code, data, message:msg } = res.data;
+    const { code, data, message: msg } = res.data;
     // 成功
     if (code === 200) {
-      return Promise.resolve(res.data);
+      const dataList = {
+        code: code,
+        message: res.data.msg,
+        data: data && data.records ?  {records:data.records.map(item => ({ ...item, createdAt: timeLoadTemeYear(item.createdAt || false), updatedAt: timeLoadTemeYear(item.updatedAt || false) }))} : data.map(item => ({ ...item, createdAt: timeLoadTemeYear(item.createdAt || false), updatedAt: timeLoadTemeYear(item.updatedAt || false) }))
+      }
+      return Promise.resolve(dataList);
     }
 
     // 服务端错误信息
@@ -64,7 +69,7 @@ axiosInstance.interceptors.response.use(
       return Promise.reject(msg);
     }
 
-    // 异常code
+    // 异常 code
     if (requestState.exception.includes(code)) {
       Notification.warning({
         title: "系统提示",
@@ -72,7 +77,7 @@ axiosInstance.interceptors.response.use(
       });
       return Promise.reject(msg);
     }
-    
+
     return Promise.resolve(data);
   },
   (err) => {
@@ -83,12 +88,12 @@ axiosInstance.interceptors.response.use(
       console.log("请求中断");
       return;
     }
-    const msg = err.response.data ? err.response.data.message : ""
+    const msg = err.response.data ? err.response.data.message : "";
     Notification.warning({
       title: "系统信息",
       content: msg
     });
-    //token失效
+    // token 失效
     if (requestState.beOverdue.includes(err.status)) {
       fn_logout(Router);
       // 直接终止请求
@@ -98,4 +103,21 @@ axiosInstance.interceptors.response.use(
   }
 );
 
-export default axiosInstance;
+
+function timeLoadTemeYear(value) {
+  if (!value) return;
+  const systemStore = useSystemStore();
+  const date = moment(value, moment.ISO_8601);
+  if (!date.isValid()) return null
+  // 使用用户所在时区转换时间
+  if (systemStore.getUserIp && systemStore.getUserIp.timezone) {
+    const localDate = date.tz(systemStore.getUserIp.timezone);
+    const time = localDate.format('YYYY-MM-DD HH:mm:ss');
+    console.log(time);
+    return time;
+  } else {
+    return null;
+  }
+}
+
+export default axiosInstance;

+ 2 - 0
src/views/tariffManagement/index.vue

@@ -140,6 +140,8 @@ const intData = async (item) => {
     ...searchForm.value,
   }
   const { data } = await tariffList(param)
+  
+  console.log(data);
   dataSource.value = (data.records || []).map((item, index) => {
     const sourceName = sourceList.value.find(val => val.value == item.source)?.label
     const billingCycleName = cycleist.value.find(val => val.value == item.billingCycle)?.label