ZaiZai 1 gadu atpakaļ
vecāks
revīzija
5dad5cf81e
3 mainītis faili ar 100 papildinājumiem un 14 dzēšanām
  1. 77 11
      pages/image/form.vue
  2. 6 2
      pages/image/position.vue
  3. 17 1
      utils/utils.js

+ 77 - 11
pages/image/form.vue

@@ -3,7 +3,7 @@
         <uni-notice-bar text="请上传MP4、MOV格式的视频文件,文件大小不超过500M,只能上传1个视频文件" v-if="formData.type === 1"/>
         <uni-notice-bar text="请上传JPG、JPEG、PNG格式的图片文件,大小不超过30M,最多10张图片文件" v-if="formData.type === 2"/>
         <view class="relative bg-white mt-1 hc-p">
-            <!-- 文件上传 -->
+            <!-- 图片文件上传 -->
             <view class="hc-flex flex-wrap pb-3 mb-5" un-border-b="1 solid gray-2" v-if="formData.type === 2">
                 <template v-for="(item, index) in fileList" :key="index">
                     <view class="hc-flex h-120 w-120 b-rounded mr-2 mt-2" @click="previewImg(index)">
@@ -19,6 +19,22 @@
                     </view>
                 </template>
             </view>
+            <!-- 视频文件上传 -->
+            <view class="hc-flex pb-3 mb-5" un-border-b="1 solid gray-2" v-if="formData.type === 1">
+                <template v-for="(item, index) in fileList" :key="index">
+                    <view class="hc-flex h-120 w-full b-rounded">
+                        <video class="w-full h-full b-rounded" :src="item"/>
+                        <view class="hc-tr bg-red-5 text-white text-center w-38 h-38 b-rounded-lb-1 b-rounded-tr-1 z-24" @click.stop="delFileClick(index)">
+                            <text class="relative cuIcon-close top--2 text-24"/>
+                        </view>
+                    </view>
+                </template>
+                <template v-if="fileList.length < 1">
+                    <view class="hc-flex-center h-120 w-full b-rounded" un-border="2 dashed gray-2" @click="addVideoFileClick">
+                        <text class="i-iconoir-plus text-70 text-gray-4"/>
+                    </view>
+                </template>
+            </view>
             <!-- 表单 -->
             <uni-forms ref="formRef" :rules="formRules" :modelValue="formData" :label-width="82">
                 <uni-forms-item label="题名" required name="title">
@@ -54,10 +70,10 @@
         <hc-tabbars class="flex items-center">
             <template v-if="!dataId">
                 <view class="flex-1 mr-2">
-                    <button hover-class="none" class="cu-btn block bg-orange text-white">继续新增</button>
+                    <button hover-class="none" class="cu-btn block bg-orange text-white" @click="continueAdd">继续新增</button>
                 </view>
                 <view class="flex-1 ml-2">
-                    <button hover-class="none" class="cu-btn block bg-purple-8 text-white">提交保存</button>
+                    <button hover-class="none" class="cu-btn block bg-purple-8 text-white" @click="saveAdd">提交保存</button>
                 </view>
             </template>
             <template v-else>
@@ -71,13 +87,20 @@
 import {ref} from "vue";
 import mainApi from '~api/image/index';
 import {uploadApi} from '~api/upload';
-import {getObjValue} from "js-fast-way";
+import {getObjValue, isString} from "js-fast-way";
 import {errorToast, formValidate, successToast} from "@/utils/tools";
 import {onLoad, onReady} from '@dcloudio/uni-app'
-import {chooseImage} from "@/utils/utils";
+import {chooseImage, chooseVideo} from "@/utils/utils";
+import {useAppStore} from "@/store";
 import dayjs from "dayjs";
 
 //初始变量
+const store = useAppStore()
+const userInfo = ref(store.userInfo);
+const projectId = ref(store.projectId);
+const contractId = ref(store.contractId);
+
+//基础变量
 const dataId = ref('');
 const fileList = ref([])
 const pdfList = ref([])
@@ -93,7 +116,18 @@ onLoad((options) => {
         getInfoApi()
     } else {
         const nodes = node ? JSON.parse(decodeURIComponent(node)) : {};
-        console.log(nodes)
+        const {real_name} = userInfo.value
+        formData.value = {
+            projectId: projectId.value,
+            contractId: contractId.value,
+            classifyId: nodes.id,
+            type: nodes.fileType,
+            wbsId: nodes.treeId,
+            uploadTime: dateEnd.value,
+            shootingTimeStr: dateEnd.value,
+            shootingUser: real_name
+        }
+        getFileTitleNamedata(nodes.treeId)
         uni.setNavigationBarTitle({title: '新增声像文件'})
     }
 })
@@ -103,6 +137,14 @@ onReady(() => {
     formRef.value?.setRules(formRules)
 })
 
+//获取题名
+const getFileTitleNamedata = async (wbsId) => {
+    const { data } = await mainApi.getFileTitleName({
+        pKeyId: wbsId
+    })
+    formData.value.title = isString(data) ? data: ''
+}
+
 //获取详情
 const getInfoApi = async () => {
     formData.value = {}
@@ -130,18 +172,30 @@ const addFileClick = async () => {
         uni.showLoading({title: '上传文件中...', mask: true});
     }
     for (let i = 0; i < tempFiles.length; i++) {
-        await uploadFile(tempFiles[i]);
+        await uploadFile(tempFiles[i].path);
     }
     uni.hideLoading();
 }
 
+//选择视频文件
+const addVideoFileClick = async () => {
+    const {tempFilePath} = await chooseVideo()
+    if (tempFilePath) {
+        uni.showLoading({title: '上传文件中...', mask: true});
+        await uploadFile(tempFilePath);
+        uni.hideLoading();
+    }
+}
+
 //上传文件
-const uploadFile = async (item) => {
-    const {error, msg, data} = await uploadApi(item.path || item.tempFilePath)
+const uploadFile = async (file) => {
+    const {error, msg, data} = await uploadApi(file)
     if (!error) {
         const { link, pdfUrl } = getObjValue(data)
         fileList.value.push(link)
-        pdfList.value.push(pdfUrl)
+        if (pdfUrl) {
+            pdfList.value.push(pdfUrl)
+        }
     } else {
         errorToast(msg)
     }
@@ -150,7 +204,9 @@ const uploadFile = async (item) => {
 //删除文件
 const delFileClick = (index) => {
     fileList.value.splice(index, 1)
-    pdfList.value.splice(index, 1)
+    if (pdfList.value.length > 0) {
+        pdfList.value.splice(index, 1)
+    }
 }
 
 //预览图片
@@ -247,4 +303,14 @@ const addImageData = async () => {
         errorToast('新增失败: ' + msg)
     }
 }
+
+//继续新增
+const continueAdd = async () => {
+    console.log(formData.value)
+}
+
+//新增保存
+const saveAdd = async () => {
+
+}
 </script>

+ 6 - 2
pages/image/position.vue

@@ -74,7 +74,11 @@ const getAllLoad = async (node, resolve) => {
 //树节点被点击
 const treeItem = ref({})
 const nodeAllTap = ({data}) => {
-    treeItem.value = getObjValue(data);
+    if (data?.leaf) {
+        treeItem.value = getObjValue(data);
+    } else {
+        treeItem.value = {};
+    }
 }
 
 //数据类型
@@ -86,7 +90,7 @@ const bindTypeChange = ({detail}) => {
 const viewClick = () => {
     const {primaryKeyId} = treeItem.value
     if (!primaryKeyId) {
-        errorToast('请先选择一个树节点')
+        errorToast('请先选择最后的一个树节点')
         return false;
     }
     //准备跳转路由

+ 17 - 1
utils/utils.js

@@ -9,7 +9,7 @@ export const getUserName = (name) => {
     }
 }
 
-//选择文件
+//选择图片文件
 export const chooseImage = (count) => {
     return new Promise((resolve) => {
         uni.chooseImage({
@@ -25,3 +25,19 @@ export const chooseImage = (count) => {
         });
     })
 }
+
+
+//选择视频文件
+export const chooseVideo = () => {
+    return new Promise((resolve) => {
+        uni.chooseVideo({
+            sourceType: ['camera', 'album'],
+            success: (res) => {
+                resolve(res);
+            },
+            fail: () => {
+                resolve({});
+            }
+        });
+    })
+}