Browse Source

修改app表单

ZaiZai 1 year ago
parent
commit
e61b7dc183
4 changed files with 305 additions and 42 deletions
  1. 1 33
      index.html
  2. 45 0
      public/plugins/app.js
  3. 236 0
      src/views/uni-app/components/log-form.vue
  4. 23 9
      src/views/uni-app/table-form.vue

+ 1 - 33
index.html

@@ -13,39 +13,7 @@
     <body>
         <div id="app"></div>
         <script type="text/javascript" src="/plugins/uni.webview.1.5.5.js"></script>
-        <script>
-            //监听uni-app的事件
-            window.appType = {};
-            document.addEventListener('UniAppJSBridgeReady', () => {
-                uni.getEnv(res => {
-                    window.appType = res;
-                });
-                //接受子页面传递过来的消息数据
-                window.addEventListener('message', (event) => {
-                    if (event.data.source === 'web') {
-                        uni.postMessage({
-                            data: event.data
-                        });
-                    }
-                });
-            });
-            //app改变显示模式
-            function editTypeClick(type) {
-                window?.postMessage({
-                    type: 'editTypeClick',
-                    source: 'app',
-                    data: type,
-                })
-            }
-            //app的表单提交保存
-            function formSave() {
-                window?.postMessage({
-                    type: 'formSave',
-                    source: 'app',
-                    data: {},
-                })
-            }
-        </script>
+        <script type="text/javascript" src="/plugins/app.js"></script>
         <script type="module" src="/src/main.js"></script>
     </body>
 </html>

+ 45 - 0
public/plugins/app.js

@@ -0,0 +1,45 @@
+//监听uni-app的事件
+window.appType = {};
+document.addEventListener('UniAppJSBridgeReady', () => {
+    uni.getEnv(res => {
+        window.appType = res;
+    });
+    //接受子页面传递过来的消息数据
+    window.addEventListener('message', (event) => {
+        if (event.data.source === 'web') {
+            uni.postMessage({
+                data: event.data
+            });
+        }
+    });
+});
+
+//app改变显示模式
+function editTypeClick(type)
+{
+    window?.postMessage({
+        type: 'editTypeClick',
+        source: 'app',
+        data: type,
+    })
+}
+
+//app的表单提交保存
+function formSave()
+{
+    window?.postMessage({
+        type: 'formSave',
+        source: 'app',
+        data: {},
+    })
+}
+
+//切换日志填报的页码
+function pageTap(index)
+{
+    window?.postMessage({
+        type: 'pageTap',
+        source: 'app',
+        data: index,
+    })
+}

+ 236 - 0
src/views/uni-app/components/log-form.vue

@@ -0,0 +1,236 @@
+<template>
+    <div v-loading="loading" class="hc-uni-app-table-form" :class="[editType]">
+        <hc-table-form ref="tableFormRef" :form="tableFormInfo" :html="excelHtml" :scroll="false" :pkey="appItem.excelId" @render="tableFormRender" />
+    </div>
+</template>
+
+<script setup>
+import { onMounted, ref, watch } from 'vue'
+import wbsApi from '~api/data-fill/wbs'
+import { useAppStore } from '~src/store'
+import queryApi from '~api/ledger/query'
+import { getArrValue, getObjVal, getObjValue, isString } from 'js-fast-way'
+
+const props = defineProps({
+    option: {
+        type: Object,
+        default: () => ({}),
+    },
+})
+
+//初始变量
+const useAppState = useAppStore()
+
+//基础变量
+const appItem = ref(props.option)
+const tableFormRef = ref(null)
+const editType = ref('form')
+const loading = ref(false)
+
+//深度监听
+watch(() => [
+    props.option,
+], ([option]) => {
+    appItem.value = getObjValue(option)
+    getDataApi()
+}, { deep: true })
+
+//渲染完成
+onMounted(() => {
+    //设置主题
+    useAppState.setTheme('light')
+    useAppState.setThemeVal('light')
+    if (getObjVal(appItem.value)) {
+        getDataApi()
+    }
+    editTypeClick('form')
+    //接受app传递过来的消息
+    window.addEventListener('message', (event) => {
+        if (event.data.source === 'app') {
+            setMessage(event.data)
+        }
+    })
+})
+
+//设置消息
+const setMessage = ({ data, type }) => {
+    if (type === 'editTypeClick') {
+        editTypeClick(data)
+    } else if (type === 'formSave') {
+        toSaveClick()
+    } else if (type === 'pageTap') {
+        console.log(data)
+    }
+}
+
+
+const getDataApi = async () => {
+    const { excelId } = appItem.value
+    console.log('appItem', appItem.value)
+    if (excelId) {
+        loading.value = true
+        await getTableFormInfo()
+        await getExcelHtml()
+        loading.value = false
+    }
+}
+
+//获取表单初始数据
+const getFormDataInit = (data = {}) => {
+    const { projectId, contractId, excelId, date } = appItem.value
+    return {
+        linkTabIds: [],
+        ...data,
+        projectId: projectId,
+        contractId: contractId,
+        recordTime: date,
+        pkeyId: excelId,
+        isTheLog: '1',
+        theLogId: '',
+        classify: 1,
+    }
+}
+
+//获取已填写的数据
+const formLogDataList = ref([])
+const getTableFormInfo = async () => {
+    const { contractId, excelId, pkeyId, date } = appItem.value
+    const { data } = await queryApi.getTheLogBusinessData({
+        contractId: contractId,
+        pkeyId: excelId,
+        nodePrimaryKeyId: pkeyId,
+        recordTime: date,
+        theLogId: '',
+    }, false)
+    let res = getArrValue(data), formArrData = []
+    window?.postMessage({
+        type: 'formLength',
+        source: 'web',
+        data: res.length,
+    })
+    if (res.length > 0) {
+        for (let i = 0; i < res.length; i++) {
+            formArrData.push(getFormDataInit(res[i]))
+        }
+    } else {
+        formArrData.push(getFormDataInit())
+    }
+    formLogDataList.value = formArrData
+    getBussDataInfo()
+}
+
+//获取表单初始数据
+const formLogIndex = ref(0)
+const tableFormInfo = ref({})
+const getBussDataInfo = (index = 0) => {
+    const formLog = formLogDataList.value
+    const info = getObjValue(formLog[index])
+    formLogIndex.value = index
+    if (getObjVal(info)) {
+        tableFormInfo.value = info
+    } else {
+        tableFormInfo.value = {}
+    }
+    window?.postMessage({
+        type: 'formIndex',
+        source: 'web',
+        data: {
+            id: info?.id ?? '',
+            page: index + 1,
+        },
+    })
+    //tableFormRef.value?.setExcelHtml()
+    //queryCurrentLogSelectProcessList(info?.id ?? '')
+}
+
+//获取当前日志资料关联的工序节点信息
+const queryCurrentLogSelectProcessList = async (bid) => {
+    const index = formLogIndex.value
+    if (bid) {
+        const { contractId } = appItem.value
+        const { data } = await queryApi.queryCurrentLogSelectProcessList({
+            contractId: contractId,
+            businessId: bid ?? '',
+        }, false)
+        //处理数据
+        formLogDataList.value[index]['linkTabIds'] = getArrValue(data)
+    } else {
+        //const formData = formLogDataList.value[index]
+        //processDataList.value = getArrValue(formData?.linkTabIds)
+    }
+}
+
+//获取模板标签数据
+const excelHtml = ref('')
+const isTableForm = ref(false)
+const getExcelHtml = async () => {
+    const { contractId, excelId } = appItem.value
+    if (excelId) {
+        //获取数据
+        const { error, code, data } = await queryApi.getExcelHtml({
+            contractId: contractId,
+            pkeyId: excelId,
+        }, false)
+        //处理数据
+        const resData = isString(data) ? data || '' : ''
+        if (!error && code === 200 && resData) {
+            excelHtml.value = resData
+            isTableForm.value = true
+        } else {
+            excelHtml.value = ''
+            isTableForm.value = false
+            window?.$message?.warning('暂无表单')
+        }
+    } else {
+        isTableForm.value = false
+        window?.$message?.error(`excelId: ${excelId || '-1 或 空'}`)
+    }
+}
+
+//渲染完成
+const tableFormRender = (form) => {
+    tableFormInfo.value = form
+}
+
+//切换显示模式
+const tableWidth = ref(0)
+const editTypeClick = (type) => {
+    let metaEle = document.getElementsByName('viewport')[0]
+    if (type === 'form') {
+        metaEle.setAttribute('content', 'width=device-width,user-scalable=no,initial-scale=1.0')
+        tableWidth.value = 0
+    } else if (type === 'table') {
+        metaEle.setAttribute('content', 'width=1080, initial-scale=0.5,user-scalable=yes')
+        tableWidth.value = document.body.offsetWidth
+    }
+    editType.value = type
+}
+
+//保存表单
+const toSaveClick = async () => {
+    const { pkeyId, status } = appItem.value
+    if (!pkeyId) {
+        window?.$message?.warning('pkeyId为空')
+        return
+    } else if (status === '3') {
+        window?.$message?.warning('已上报的资料,不允许保存。')
+        return
+    }
+    const formData = tableFormRef.value?.getFormData()
+    const { error, code, msg } = await wbsApi.saveExcelBussData(formData, false)
+    if (!error && code === 200) {
+        window?.$message?.success('保存成功')
+        window?.postMessage({
+            type: 'saveSuccess',
+            source: 'web',
+            data: {},
+        })
+    } else {
+        window?.$message?.error(msg)
+    }
+}
+</script>
+
+<style lang="scss">
+@import "~src/styles/uni-app/table-form.scss";
+</style>

+ 23 - 9
src/views/uni-app/table-form.vue

@@ -1,5 +1,5 @@
 <template>
-    <div v-if="isType === ''" v-loading="loading" class="hc-body-loading" element-loading-text="授权登录中...">
+    <div v-if="isType === ''" v-loading="loading" class="hc-body-loading" element-loading-text="加载数据中...">
         <div v-if="isErrorShow" class="error-page">
             <div class="img" :style="`background-image: url(${svg403});`" />
             <div class="content">
@@ -9,20 +9,22 @@
         </div>
     </div>
     <HcDataForm v-if="isType === 'data-fill'" :option="formNode" />
+    <HcLogForm v-if="isType === 'log-fill'" :option="formNode" />
 </template>
 
 <script setup>
 import { onMounted, ref } from 'vue'
 import { useAppStore } from '~src/store'
-import { useAppLogin } from '~sto/user'
 import { useRoute } from 'vue-router'
 import svg403 from '~src/assets/view/403.svg'
 import { isNullES } from 'js-fast-way'
 import HcDataForm from './components/data-form.vue'
+import HcLogForm from './components/log-form.vue'
+import { userLogin } from '~api/user'
 
 //初始变量
 const useRoutes = useRoute()
-const useAppState = useAppStore()
+const store = useAppStore()
 
 //变量
 const loading = ref(true)
@@ -35,7 +37,7 @@ onMounted(() => {
     const { user, source } = useRoutes.query
     if (!isNullES(user)) {
         const userInfo = JSON.parse(decodeURIComponent(user))
-        useAppState.setIsSource(source)
+        store.setIsSource(source)
         useAppLoginApi(userInfo)
     } else {
         loading.value = false
@@ -46,17 +48,22 @@ onMounted(() => {
 //请求授权登录
 const useAppLoginApi = async (form) => {
     loading.value = true
-    const { error, status } = await useAppLogin(form)
+    const { error, status, res } = await userLogin(form)
     if (!error && status === 200) {
+        //设置token和用户信息
+        store.setTokenVal(res['access_token'])
+        store.setRefreshTokenVal(res['refresh_token'])
+        store.setTenantId(res['tenant_id'])
+        store.setUserInfo(res)
         //设置主题
-        useAppState.setTheme('light')
-        useAppState.setThemeVal('light')
+        store.setTheme('light')
+        store.setThemeVal('light')
         //处理其他数据
         setTimeout(() => {
             setFormType()
+            loading.value = false
+            isErrorShow.value = false
         }, 1000)
-        loading.value = false
-        isErrorShow.value = false
     } else {
         window.$message?.error('身份验证异常')
         isErrorShow.value = true
@@ -64,6 +71,7 @@ const useAppLoginApi = async (form) => {
     }
 }
 
+//处理数据
 const setFormType = () => {
     const { type, node } = useRoutes.query
     if (isNullES(type)) {
@@ -81,3 +89,9 @@ const setFormType = () => {
 <style lang="scss" scoped>
 @import "../../styles/error/app-auth.scss";
 </style>
+
+<style lang="scss">
+html, body, #app {
+    background-color: white;
+}
+</style>