ZaiZai 2 жил өмнө
parent
commit
f13f351933
3 өөрчлөгдсөн 59 нэмэгдсэн , 22 устгасан
  1. 4 4
      manifest.json
  2. 0 5
      pages/login/login.vue
  3. 55 13
      store/user.js

+ 4 - 4
manifest.json

@@ -1,9 +1,9 @@
 {
-    "name" : "泓创数字工程",
+    "name" : "工程云家",
     "appid" : "__UNI__A0B807E",
-    "description" : "",
-    "versionName" : "2.0.4",
-    "versionCode" : 204,
+    "description" : "智慧数字工程",
+    "versionName" : "2.0.5",
+    "versionCode" : 205,
     "transformPx" : false,
     "networkTimeout" : {
         "request" : 300000,

+ 0 - 5
pages/login/login.vue

@@ -143,11 +143,6 @@ const submitClick = () => {
                     url: '/pages/index/index'
                 })
             }, 2000);
-        }).catch(({msg}) => {
-            uni.showToast({
-                title: msg,
-                icon: 'none'
-            });
         })
     }
 }

+ 55 - 13
store/user.js

@@ -4,7 +4,7 @@ import {setStorage} from "@/utils/storage";
 import userApi from '~api/user/index';
 import projectApi from "~api/user/project";
 import {setToken, setRefreshToken} from '@/httpApi/util/auth';
-import {getObjValue} from "js-fast-way";
+import {getArrValue, getObjVal, getObjValue, isNullES} from "js-fast-way";
 
 const store = useAppStore(pinia)
 
@@ -28,33 +28,75 @@ export const userLogin = async (form) => {
         await getProjectContract()
         return Promise.resolve(res);
     } else {
-        return Promise.reject({
-            msg: message,
-            res: response
-        });
+        uni.showToast({title: message, icon: 'error'});
+        return Promise.reject({msg: message, res: response});
     }
 }
 
 //获取默认项目信息
 export const getProjectContract = async () => {
+    const { error, data } = await projectApi.getProjectAndContract()
+    const projectList = getArrValue(data)
+    if (error || projectList.length <= 0) {
+        uni.showToast({title: '没有相关项目权限', icon: 'error'});
+        return false
+    }
+    //获取默认项目合同段数据
+    const defaultProject = await getDefaultProject()
+    let projectInfo = {}, contractInfo = {}
+    if (defaultProject.code === 200) {
+        projectInfo = defaultProject.project
+        contractInfo = defaultProject.contract
+    } else {
+        //过滤空合同段的项目合同段数据
+        const projectArr = projectList.filter(({contractInfoList}) => {
+            const contractList = getArrValue(contractInfoList)
+            return contractList.length > 0
+        })
+        if (projectArr.length <= 0) {
+            uni.showToast({title: '没有相关项目权限', icon: 'error'});
+            return false
+        }
+        //获取第一个项目的第一个合同段数据
+        const contractList = projectArr[0].contractInfoList
+        projectInfo = projectList[0]
+        contractInfo = contractList[0]
+    }
+    //设置项目合同段数据
+    store.setProjectInfo(projectInfo)
+    store.setProjectId(projectInfo.id)
+    store.setContractInfo(contractInfo)
+    store.setContractId(contractInfo.id)
+    return true
+}
+
+//获取默认项目信息
+const getDefaultProject = async () => {
     const {error, status, data} = await projectApi.getDefaultProject()
-    if (!error && status === 200) {
-        store.setProjectId(data.projectId)
-        store.setContractId(data.contractId)
-        //获取项目详情
-        await getProjectInfo(data.projectId)
-        await getContractInfo(data.contractId)
+    if (!error && status === 200 && !isNullES(data)) {
+        const {projectId, contractId} = getObjValue(data)
+        if (!projectId || !contractId) {
+            return {code: 300}
+        }
+        const projectInfo =  await getProjectInfo(projectId)
+        const contractInfo =  await getContractInfo(contractId)
+        if (isNullES(projectInfo) || isNullES(contractInfo)) {
+            return {code: 300}
+        }
+        return {code: 200, project: projectInfo, contract: contractInfo}
+    } else {
+        return {code: 300}
     }
 }
 
 //获取项目信息
 const getProjectInfo = async (projectId) => {
     const {data} = await projectApi.getProjectInfo(projectId)
-    store.setProjectInfo(getObjValue(data))
+    return getObjValue(data)
 }
 
 //获取合同段信息
 const getContractInfo = async (contractId) => {
     const {data} = await projectApi.getContractInfo(contractId)
-    store.setContractInfo(getObjValue(data))
+    return getObjValue(data)
 }