duy 9 ヶ月 前
コミット
0a08984a15
7 ファイル変更384 行追加127 行削除
  1. 12 4
      config/index.js
  2. 14 2
      pages.json
  3. 1 121
      pages/index/index.vue
  4. 113 0
      pages/login/login.vue
  5. 129 0
      store/user.js
  6. 112 0
      style/login/login.scoped.scss
  7. 3 0
      style/login/login.scss

+ 12 - 4
config/index.js

@@ -1,9 +1,9 @@
 export default {
     title: "芯片扫描",
-    key: 'hid_app',                 //配置主键,目前用于存储
-    clientId: 'hid_app',            // 客户端id
-    clientSecret: 'hid_app_secret', // 客户端密钥
-    platform: 'hid_app',            //app的key,用于检测升级
+    platform: 'client',         //app的key,用于检测升级
+    key: 'uni-app',             //配置主键,目前用于存储
+    clientId: 'uni-app',        // 客户端id
+    clientSecret: 'app_secret', // 客户端密钥
     tenantMode: true,               // 是否开启租户模式
     tenantId: "000000",             // 管理组租户编号
     captchaMode: false,             // 是否开启验证码模式
@@ -20,3 +20,11 @@ export default {
         host: '0.0.0.0'
     }
 }
+
+
+
+// title: "芯片扫描",
+//     key: 'hid_app',                 //配置主键,目前用于存储
+//     clientId: 'hid_app',            // 客户端id
+//     clientSecret: 'hid_app_secret', // 客户端密钥
+//     platform: 'hid_app',            //app的key,用于检测升级

+ 14 - 2
pages.json

@@ -1,9 +1,21 @@
 {
     "pages": [
-        {"path": "pages/index/index"}
+
+
+        // {
+        //     "path" : "pages/login/login",
+        //     "style" :
+        //     {
+        //         "navigationBarTitleText" : ""
+        //     }
+        // },
+{"path": "pages/login/login"},
+           {"path": "pages/index/index"}
+
+
     ],
     "globalStyle": {
-        "navigationStyle": "default",
+        "navigationStyle": "custom",
         "navigationBarTextStyle": "black",
         "navigationBarTitleText": "芯片扫描",
         "navigationBarBackgroundColor": "#FFFFFF",

+ 1 - 121
pages/index/index.vue

@@ -1,129 +1,9 @@
 <template>
     <view class="content">
-        <uni-table border stripe>
-            <uni-tr>
-                <uni-th width="150" align="center">EPC</uni-th>
-            </uni-tr>
-            <uni-tr v-for="(item, index) in scanDatas" :key="index">
-                <uni-td>{{ item }}</uni-td>
-            </uni-tr>
-        </uni-table>
+     2222222222222
     </view>
 </template>
 
 <script setup>
-import { ref } from "vue";
-import {onLoad, onReady, onUnload} from '@dcloudio/uni-app'
-import {getArrValue} from "js-fast-way";
 
-// 获取 module
-const rfidModule = uni.requireNativePlugin("DeviceModule_RFID");
-
-//渲染完成
-onReady(() => {
-    // #ifdef APP-PLUS
-    rfidModuleInit()
-    // #endif
-})
-
-//按键操作
-const isRfidInit = ref(true)
-const rfidModuleInit = () => {
-    isRfidInit.value = true
-    uni.showLoading({
-    	title: 'RFID模块加载中...',
-        mask: true,
-    });
-    /**
-        手机按键监听事件,可在此编写一些逻辑,如使用按键触发扫描,更多详细信息请查阅uni官方文档
-        需要注意:退出界面必须移除监听,否则再进入页面重复注册监听会出现多次触发、回调失效的问题
-    */
-    plus.key.addEventListener('keydown', keyListener);
-    //初始化
-    setTimeout(() => {
-        // 使用模块前必须先初始化RDIF模块
-        let { code } = rfidModule.init();
-        if (code === 0) {
-            uni.hideLoading();
-        } else if (code === -1) {
-            uni.hideLoading();
-            uni.showToast({
-                title: 'RFID模块加载失败',
-                icon: 'error',
-                duration: 3000
-            })
-        } else {
-            uni.hideLoading();
-        }
-        isRfidInit.value = false
-    }, 400);
-}
-
-//按键操作
-const keyListener = ({keyCode}) => {
-    if (keyCode === 293 || keyCode === 312) {
-        if (isScan.value) {
-            stopScan()
-        } else {
-            startScan()
-        }
-    }
-}
-
-//开始扫描
-const isScan = ref(false)
-const startScan = () => {
-    if (isRfidInit.value) return
-    isScan.value = true
-    rfidModule.startScan((res) => {
-        if (res.code === 0) {
-            uni.showToast({
-                icon: "success",
-                title: '开启扫描成功'
-            })
-        } else if (res.code === 1) {
-            startScanData(res.data)
-        }
-    })
-}
-
-//扫描结果处理
-const scanDatas = ref([])
-const startScanData = async (data) => {
-    const arr = getArrValue(data)
-    let epcs = scanDatas.value
-    for (let i = 0; i < arr.length; i++) {
-        const epc = arr[i].epc
-        if (epcs.indexOf(epc) === -1) {
-            epcs.push(epc)
-        }
-    }
-    scanDatas.value = epcs
-}
-
-//停止扫描
-const stopScan = () => {
-    const { code } = rfidModule.stopScan()
-    if (code === 0) {
-        isScan.value = false
-        uni.showToast({
-            icon: "success",
-            title: '关闭扫描成功'
-        })
-    } else {
-        uni.showToast({
-            icon: "error",
-            title: res.message
-        })
-    }
-}
-
-//页面卸载
-onUnload(()=>{
-    // #ifdef APP-PLUS
-    plus.key.removeEventListener('keydown', keyListener)
-    // 使用完毕必须释放RDIF模块
-    rfidModule.free();
-    // #endif
-})
 </script>

+ 113 - 0
pages/login/login.vue

@@ -0,0 +1,113 @@
+<template>
+    <view class="hc-login-box relative h-full p-4">
+        <view class="hc-dot-box">
+            <view un-absolute un-b-rounded-100 class="dot dot-1"/>
+            <view un-absolute un-b-rounded-100 class="dot dot-2"/>
+            <view un-absolute un-b-rounded-100 class="dot dot-3"/>
+        </view>
+
+        <view class="hc-login-container">
+            <view class="hc-login-center">
+                <view class="hc-login-title">欢迎登录</view>
+                <view class="hc-login-text">让每一个数据更具价值</view>
+                <view class="hc-login-form">
+                    <view class="hc-login-form-item">
+                        <input class="hc-login-input" v-model="formData.username" placeholder="请输入登录账户"/>
+                    </view>
+                    <view class="hc-login-form-item">
+                        <input type="password" class="hc-login-input" v-model="formData.password"
+                               placeholder="请输入登录密码"/>
+                    </view>
+                </view>
+                <button class="mt-16" :type="!formData.username || !formData.password ? 'info' : 'primary'" @click="submitClick">
+                    <text class="mr-5">登</text>
+                    <text class="ml-5">录</text>
+                </button>
+            </view>
+        </view>
+    </view>
+</template>
+
+<script setup>
+import {ref, onMounted} from "vue";
+import {onLoad, onUnload} from '@dcloudio/uni-app'
+import {getStorage, setStorage} from "@/utils/storage";
+import {useAppStore} from "@/store";
+import {userLogin} from "@/store/user";
+import {getObjVal} from "js-fast-way";
+
+//初始变量
+const store = useAppStore()
+
+onLoad(() => {
+    const user_info = getStorage('login_user_info');
+    if (getObjVal(user_info)) {
+        formData.value = user_info
+    }
+    //清除所有缓存
+    store.clearStoreData()
+
+})
+
+//渲染完成
+onMounted(() => {
+
+})
+
+
+//登录表单
+const formData = ref({
+    tenantId: "000000",
+    username: '',
+    password: '',
+    type: "account"
+})
+
+//登录
+const submitClick = () => {
+    const {username, password} = formData.value
+    if (!username) {
+        uni.showToast({
+            title: '请先输入登录账户',
+            icon: 'none',
+            duration: 3000
+        });
+    } else if (!password) {
+        uni.showToast({
+            title: '请先输入登录密码',
+            icon: 'none',
+            duration: 3000
+        });
+    } else {
+        userLogin(formData.value).then((res) => {
+            uni.showToast({
+                title: '登录成功',
+                duration: 2000,
+                mask: true
+            });
+            //跳转登录
+            setTimeout(() => {
+                uni.switchTab({
+                    url: '/pages/index/index'
+                })
+            }, 2000);
+        })
+    }
+}
+
+onUnload(()=>{
+
+})
+</script>
+
+<style lang="scss" scoped>
+page {
+    height: 100%;
+}
+
+@import "@/style/login/login.scoped.scss";
+</style>
+
+<style lang="scss">
+@import "@/style/login/login.scss";
+</style>

+ 129 - 0
store/user.js

@@ -0,0 +1,129 @@
+import pinia from "@/store/init"
+import {useAppStore} from "@/store";
+import {getStorage, setStorage} from "@/utils/storage";
+import userApi from '~api/user/index';
+import menuApi from '~api/menu';
+import projectApi from "~api/user/project";
+import {setToken, setRefreshToken} from '@/httpApi/util/auth';
+import {getArrValue, getObjVal, getObjValue, isNullES, ArrToOneObj} from "js-fast-way";
+
+const store = useAppStore(pinia)
+
+//账号密码登录
+export const userLogin = async (form) => {
+    console.log(form,'form');
+    const {error, status, res, response, message} = await userApi.userLogin(form);
+    if (!error && status === 200) {
+        //设置全局状态
+        const {access_token, refresh_token, tenant_id} = res;
+        setToken(access_token)
+        setRefreshToken(refresh_token)
+        store.setTenantId(tenant_id)
+        store.setUserInfo(res)
+        //设置登录信息的缓存
+        setStorage('login_user_info', {
+            tenantId: tenant_id,
+            username: form.username,
+            password: form.password,
+            type: form.type
+        });
+        //await getProjectContract()
+        return Promise.resolve(res);
+    } else {
+        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]
+    }
+    //获取按钮权限
+    await initButtons()
+    //设置项目合同段数据
+    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 && !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)
+    return getObjValue(data)
+}
+
+//获取合同段信息
+const getContractInfo = async (contractId) => {
+    const {data} = await projectApi.getContractInfo(contractId)
+    return getObjValue(data)
+}
+
+
+//按钮初始化
+export const initButtons = async () => {
+    const value = getStorage('buttons')
+    if (!value) {
+        const { error, data } = await menuApi.getButtons()
+        if (error) return Promise.reject('error')
+        const buttons = getArrValue(data)
+        const buttonsArr = await setButtonsData(buttons)
+        store.setButtons(buttonsArr)
+        return Promise.resolve(true)
+    } else {
+        return Promise.resolve(true)
+    }
+}
+
+//设置按钮
+const setButtonsData = async (data) => {
+    let buttonsArr = {}
+    await ArrToOneObj(data, 'code', buttonsArr)
+    return buttonsArr
+}

+ 112 - 0
style/login/login.scoped.scss

@@ -0,0 +1,112 @@
+.hc-login-box {
+  .hc-dot-box {
+    position: absolute;
+    top: 0;
+    left: 0;
+    right: 0;
+    bottom: 0;
+    .dot {
+      opacity: 1;
+      background-color: rgba(85, 77, 132, 0.1);
+    }
+    .dot-1 {
+      left: 30px;
+      top: 42px;
+      width: 33px;
+      height: 33px;
+      transform-origin: 16.5px 16.5px;
+      animation-duration: 1s;
+      animation-iteration-count: 1;
+      animation-fill-mode: backwards;
+      animation-name: animationDot1;
+    }
+    .dot-2 {
+      right: -43px;
+      top: -43px;
+      width: 110px;
+      height: 110px;
+      transform-origin: 55px 54.5px;
+      animation-duration: 1s;
+      animation-iteration-count: 1;
+      animation-fill-mode: backwards;
+      animation-name: animationDot2;
+    }
+    .dot-3 {
+      left: 85px;
+      top: 90px;
+      width: 12px;
+      height: 12px;
+      transform-origin: 6px 6px;
+      animation-duration: 1s;
+      animation-iteration-count: 1;
+      animation-fill-mode: backwards;
+      animation-name: animationDot1;
+    }
+  }
+  .hc-login-container {
+    position: relative;
+    height: 100%;
+    padding: 0 14px;
+    display: flex;
+    justify-content: center;
+    align-items: center;
+    .hc-login-center {
+      position: relative;
+      margin-top: -6rem;
+      flex: 1;
+      .hc-login-title {
+        font-size: 20px;
+        font-weight: 500;
+        color: #101010;
+      }
+      .hc-login-text {
+        color: #8E8E93;
+        font-size: 14px;
+        margin-top: 8px;
+      }
+      .hc-login-form {
+        position: relative;
+        margin-top: 60px;
+        .hc-login-form-item {
+          position: relative;
+          margin-top: 14px;
+          .hc-login-input {
+            padding: 10px;
+            font-size: 14px;
+            line-height: initial;
+            min-height: initial;
+            height: initial;
+            border-bottom: 1px solid #E5E5EA;
+          }
+        }
+      }
+    }
+  }
+}
+
+//动画
+@keyframes animationDot1 {
+  0% {
+    transform-origin: left bottom;
+    transform: rotate3d(0, 0, 1, -45deg);
+    opacity: 0;
+  }
+  100% {
+     transform-origin: left bottom;
+     transform: none;
+     opacity: 1;
+   }
+}
+
+@keyframes animationDot2 {
+  0% {
+    transform-origin: right bottom;
+    transform: rotate3d(0, 0, 1, 45deg);
+    opacity: 0;
+  }
+  100% {
+    transform-origin: right bottom;
+    transform: none;
+    opacity: 1;
+  }
+}

+ 3 - 0
style/login/login.scss

@@ -0,0 +1,3 @@
+.hc-login-box {
+
+}