uploadEditMyHonor.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. <template>
  2. <view class="page_body">
  3. <!-- 头部 -->
  4. <nav-bar height="96" :title="state.title" :onlyTitle="true" :showHeaderborder="true" @GoBack="GoBack"></nav-bar>
  5. <view :class="['page_content',{'view':state.type=='view'}]">
  6. <uni-forms ref="valiForm" :class="['forms_style',{'view':state.type=='view'}]" :rules="rules" :model="state.formData" border labelWidth="160rpx" label-align="right">
  7. <uni-forms-item label="荣誉类型:" required name="honorTypeValue">
  8. <template v-if="state.type=='view'">{{state.formData.honorTypeValue}}</template>
  9. <uni-data-select v-else v-model="state.formData.honorTypeValue" :clear="false" placeholder="请选择荣誉类型" :disabled="state.type=='upload'?false:true" :localdata="state.honorTypeData" style="width: 400rpx;" @change="ChangeDataSelect"></uni-data-select>
  10. </uni-forms-item>
  11. <template v-for="item in state.dynamicFormData">
  12. <uni-forms-item :label="`${item.dictName}:`" required :name="`input_${item.id}`">
  13. <template v-if="state.type=='view'">
  14. <template v-if="item.dictType == 1 || item.dictType == 2">{{state.formData[`${item.dictShowType}_${item.id}`]}}</template>
  15. <uni-dateformat v-else :date="state.formData[`${item.dictShowType}_${item.id}`]" format="yyyy-MM-dd"></uni-dateformat>
  16. </template>
  17. <template v-else>
  18. <uni-easyinput v-if="item.dictType == 1" v-model="state.formData[`${item.dictShowType}_${item.id}`]" :disabled="item.onlyRead == 1" :maxlength="100" :placeholder="`请输入${item.dictName}`" :style="{width: item.dictName=='获奖人'?'400rpx':''}" />
  19. <uni-data-select v-else-if="item.dictType == 2" v-model="state.formData[`${item.dictShowType}_${item.id}`]" :clear="false" :placeholder="`请选择${item.dictName}`" :localdata="item.dictList" style="width: 400rpx;"></uni-data-select>
  20. <uni-datetime-picker v-else type="date" :end="todayStr" :clear-icon="false" v-model="state.formData[`${item.dictShowType}_${item.id}`]" placeholder=" " style="width: 400rpx;" />
  21. </template>
  22. </uni-forms-item>
  23. </template>
  24. <uni-forms-item label="荣誉证书:" required name="certPicDatas">
  25. <uv-upload :maxCount="state.type=='view'?state?.formData?.certPicDatas?.length:50" :deletable="state.type!='view'" :fileList="state.formData.certPicDatas" width="240rpx" height="140rpx" multiple :previewFullImage="true" @AfterRead="AfterRead" @delete="DeletePic">
  26. <view class="upload_btn" v-if="state.type!='view'">
  27. <uni-icons class="upload_btn_icon" type="plusempty"></uni-icons>
  28. <view class="upload_btn_text">上传荣誉证书</view>
  29. </view>
  30. </uv-upload>
  31. </uni-forms-item>
  32. <uni-forms-item label="佐证材料:">
  33. <template v-if="state.type=='view'">
  34. <view class="upload_file_list_item" v-for="item in state.formData.docDatas" :key="item.createdAt">
  35. <image class="list_item_icon" src="/static/image/icon/file.png"></image>
  36. <view class="list_item_content">
  37. <view class="item_content_title">{{item.documentName}}</view>
  38. <view class="item_content_info">
  39. <view class="size">{{item.fileSize}}</view>
  40. <view class="time">{{item.createdAt}}</view>
  41. </view>
  42. </view>
  43. <!-- #ifdef APP-PLUS -->
  44. <!-- app端处理 -->
  45. <template v-if="['word','excel','pdf','txt'].includes(getFileTypeBySuffix(item?.documentName?.split('.')?.[1] || ''))">
  46. <cjx-previewOffice :value="item.documentUrl" :name="item.documentName" :type="getFileTypeBySuffix(item?.documentName?.split('.')?.[1] || '')">
  47. <view class="list_item_preview" @click="OpenPreviewFileDialog(item)">预览</view>
  48. </cjx-previewOffice>
  49. </template>
  50. <view v-else class="list_item_preview" @click="OpenPreviewFileDialog(item)">预览</view>
  51. <!-- #endif -->
  52. <!-- #ifndef APP-PLUS -->
  53. <!-- 不包含app端 -->
  54. <view class="list_item_preview" @click="OpenPreviewFileDialog(item)">预览</view>
  55. <!-- #endif -->
  56. </view>
  57. </template>
  58. <template v-else>
  59. <!-- maxSize:单文件上限 MB;0 表示不限制 maxCount:列表最多文件数 -->
  60. <kex-file-uploader ref="fileUploader" mode="headless" :multiple="false" :upload-url="`${apiBaseUrl}/api/v1/teach/oss/file/oss/upload_filesSele`"
  61. :upload-options="{
  62. name: 'file',
  63. header: {
  64. Authorization: token
  65. }
  66. }"
  67. :auto-upload="true" :max-count="20" :maxSize="100" @uploadSuccess="onUploadSuccess"></kex-file-uploader>
  68. <view class="upload_file_btn" @click="FileChooseUploader">
  69. <uni-icons class="upload_file_btn_icon" type="plusempty"></uni-icons>
  70. <view class="upload_file_btn_text">上传佐证材料</view>
  71. </view>
  72. <view class="upload_file_list_item" v-for="(item,i) in state.formData.docDatas" :key="item.createdAt">
  73. <image class="list_item_icon" src="/static/image/icon/file.png"></image>
  74. <view class="list_item_content">
  75. <view class="item_content_title">{{item.documentName}}</view>
  76. <view class="item_content_info">
  77. <view class="size">{{item.fileSize}}</view>
  78. <view class="time">{{item.createdAt}}</view>
  79. </view>
  80. </view>
  81. <uni-icons class="list_item_close" type="close" @click.stop="state.formData.docDatas.splice(i, 1)"></uni-icons>
  82. </view>
  83. </template>
  84. </uni-forms-item>
  85. <uni-forms-item label="驳回原因 :" v-if="state.formData.overruleContent">
  86. {{state.formData.overruleContent}}
  87. </uni-forms-item>
  88. <uni-forms-item label="审核人:" v-if="state.type=='view'">
  89. {{state.formData.reviewTeacherName}}
  90. </uni-forms-item>
  91. </uni-forms>
  92. </view>
  93. <view class="page_foot" v-if="state.type!='view'"><button class="btn_submit" type="primary" :loading="state.loading" @click="honorTypeConfirm">确认</button></view>
  94. </view>
  95. <!-- 图片 视频预览 -->
  96. <popupPreviewFile ref="imgVideoPreview" :fileType="state.previewPopup.fileType" :fileName="state.previewPopup.fileName" :filePath="state.previewPopup.filePath" @ToDownloadFile="ToDownloadFile"></popupPreviewFile>
  97. <!-- 默认指H5端 此插件只支持h5 PDF、Word、Excel、PPTX、TXT预览-->
  98. <!-- #ifdef H5 -->
  99. <wg-h5-preview-file ref="webPreviewFile" />
  100. <!-- #endif -->
  101. <!-- 文件、图片下载 -->
  102. <ss-download ref="ssdownload"></ss-download>
  103. </template>
  104. <script setup>
  105. import navBar from '@/components/navBar.vue';
  106. import uniForms from '@/uni_modules/uni-forms/components/uni-forms/uni-forms.vue';
  107. import uniFormsItem from '@/uni_modules/uni-forms/components/uni-forms-item/uni-forms-item.vue';
  108. import uniEasyinput from '@/uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue';
  109. import uniDataSelect from '@/uni_modules/uni-data-select/components/uni-data-select/uni-data-select.vue';
  110. import uniDatetimePicker from '@/uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.vue';
  111. import uniDateformat from '@/uni_modules/uni-dateformat/components/uni-dateformat/uni-dateformat.vue';
  112. import uvUpload from '@/uni_modules/uv-upload/components/uv-upload/uv-upload.vue';
  113. import uniIcons from '@/uni_modules/uni-icons/components/uni-icons/uni-icons.vue';
  114. import ssDownload from '@/uni_modules/ss-download/components/ss-download/ss-download.vue';
  115. import popupPreviewFile from '@/components/popupPreviewFile.vue';//图片 音视频 zip等预览
  116. // #ifdef H5
  117. import wgH5PreviewFile from '@/components/wg-h5-preview-file/wg-h5-preview-file.vue';//web端文件预览 'word','excel','pptx','pdf','txt'
  118. // #endif
  119. // #ifdef APP-PLUS
  120. import cjxPreviewOffice from '@/uni_modules/cjx-previewOffice/components/cjx-previewOffice/cjx-previewOffice.vue';//APP端文件预览 'word','excel','pdf','txt'
  121. // #endif
  122. import {queryHonorTypeDictList,queryHonorDataDetailById,addHonorCertData,updateHonorCertData} from '@/reqApi/teacherHonor.js';
  123. import { unioformDateTransform,fileSizeConvert,getFileTypeBySuffix } from '@/common/common.js';
  124. import config from '@/config.js'; // 引入配置文件
  125. import {
  126. reactive,
  127. ref,
  128. onMounted,
  129. nextTick
  130. } from 'vue';
  131. import { onLoad } from '@dcloudio/uni-app';
  132. const state = reactive({
  133. id:'',//荣誉类型id
  134. title:'',//标题
  135. type:'',
  136. formData: {
  137. honorTypeValue: '',//荣誉类型id
  138. certPicDatas:[],//荣誉证书
  139. docDatas:[],//佐证材料
  140. overruleContent:'',//驳回原因
  141. reviewTeacherName:''//审核人
  142. },
  143. honorTypeData:[],//荣誉类型下拉
  144. dynamicFormData:[],//动态表单
  145. dictDatas:[],//动态表单传参
  146. loading:false,
  147. previewPopup:{//文件预览弹框
  148. fileType:'',
  149. filePath:'',
  150. fileName:''
  151. }
  152. })
  153. const todayStr = ref(new Date().toISOString().split('T')[0]);
  154. const rules = ref({
  155. honorTypeValue: { rules: [{ required: true, errorMessage: '请选择荣誉类型' }] },
  156. certPicDatas: { rules: [{ required: true, errorMessage: '请上传荣誉证书' }] },
  157. });
  158. const fileUploader = ref(null);
  159. const ssdownload = ref(null);
  160. const imgVideoPreview = ref(null);//图片 视频
  161. const webPreviewFile = ref(null);//web端文件预览
  162. const appPreviewOfficeRef = ref(null);//APP端文件预览
  163. const token = ref(uni.getStorageSync('token'));
  164. const apiBaseUrl = ref('');
  165. onLoad(async(option) => {
  166. state.id = option.id;
  167. state.type = option.type;
  168. getApiBaseUrl();
  169. uni.setStorageSync('isLoadMyHonorList', false);//返回列表页是否重新加载我的荣誉列表
  170. await GetHonorTypeDictList(option.type);//查询荣誉类型下拉数据
  171. if(option.type == 'upload'){
  172. state.title = '上传荣誉';
  173. }else{
  174. if(option.type == 'edit'){
  175. state.title = '修改荣誉';
  176. }else {
  177. state.title = decodeURIComponent(option.honorName);
  178. }
  179. GetHonorDataDetailById();
  180. }
  181. })
  182. //上传接口地址
  183. const getApiBaseUrl = () => {
  184. if (process.env.NODE_ENV === 'development') {//本地开发环境
  185. const SYSTEM_INFO = uni.getSystemInfoSync();//获取系统信息的同步接口
  186. apiBaseUrl.value = SYSTEM_INFO.uniPlatform === 'web' ? config.proxyBaseUrl:config.apiBaseUrl;//读取配置文件的apiBaseUrl变量
  187. } else {//生产/测试环境
  188. apiBaseUrl.value = config.apiBaseUrl
  189. }
  190. }
  191. //查询荣誉类型下拉数据
  192. const GetHonorTypeDictList = async (type) => {
  193. await queryHonorTypeDictList().then(res=>{
  194. if(res.code == 200){
  195. const honorTypeData = res?.data?.honorTypeDictBOS || [];
  196. honorTypeData.forEach(item=>{
  197. item.value = item.id;
  198. item.text = item.honorTypeName;
  199. const honorTypeDictData = item?.honorTypeDictBOS || [];
  200. honorTypeDictData.forEach(itemList=>{
  201. if(itemList.dictType == 2){//单选
  202. itemList.dictShowType = 'radio';
  203. const dictList = itemList?.dictList || [];
  204. dictList.forEach(dic=>{
  205. dic.text = dic.dictName;
  206. dic.value = dic.id
  207. })
  208. }else if(itemList.dictType == 1){//输入框
  209. itemList.dictShowType = 'input';
  210. }else{//日期
  211. itemList.dictShowType = 'datetime';
  212. }
  213. })
  214. })
  215. state.honorTypeData = honorTypeData;//荣誉类型下拉数据;
  216. if(type == 'upload'){//荣誉类型默认值
  217. state.formData.honorTypeValue = honorTypeData?.[0].value || '';//荣誉类型默认值
  218. const honorTypeDictData = honorTypeData?.[0]?.honorTypeDictBOS || [];
  219. SetDynamicFormData(honorTypeDictData);//设置动态表单
  220. }
  221. }else{
  222. state.honorTypeData = [];
  223. }
  224. })
  225. }
  226. //设置动态表单的值
  227. const SetDynamicFormData = (honorTypeDictData) => {
  228. const defaultRules = ['honorTypeValue','certPicDatas'];
  229. const defaultFormData = ['honorTypeValue','certPicDatas','docDatas','overruleContent','reviewTeacherName'];
  230. for (let key in state.formData) {
  231. if (!defaultFormData.includes(key)) delete state.formData[key];
  232. }
  233. for (let key in rules.value) {
  234. if (!defaultRules.includes(key)) delete rules.value[key];
  235. }
  236. rules.value = {...state.defaultRules}
  237. honorTypeDictData.forEach(item=>{
  238. if(item.dictType == 2){//单选
  239. state.formData[`${item.dictShowType}_${item.id}`] = '';
  240. rules.value[`${item.dictShowType}_${item.id}`] = { rules: [{ required: true, errorMessage: `请选择${item.dictName}` }] };
  241. }else {//输入框 日期
  242. const value = item?.dictList?.[0]?.dictName || '';
  243. state.formData[`${item.dictShowType}_${item.id}`] = value;
  244. const placeholder = item.dictType == 1 ? '请输入' : '请选择';
  245. rules.value[`${item.dictShowType}_${item.id}`] = { rules: [{ required: true, errorMessage: `${placeholder}${item.dictName}` }] };
  246. }
  247. })
  248. state.dynamicFormData = honorTypeDictData;//动态表单
  249. }
  250. //改变荣誉类型
  251. const ChangeDataSelect = (val) => {
  252. const selectedHonorType = state.honorTypeData.find(item=>item.id == val);
  253. const honorTypeDictData = selectedHonorType?.honorTypeDictBOS || [];
  254. SetDynamicFormData(honorTypeDictData)
  255. }
  256. //查看荣誉详情接口
  257. const GetHonorDataDetailById = () => {
  258. queryHonorDataDetailById(state.id).then(res=>{
  259. if(res.code == 200){
  260. const honorTypeId = res?.data?.honorTypeId || '';
  261. const honorTypeName = res?.data?.honorTypeName || '';
  262. state.formData.honorTypeValue = state.type=='view'?honorTypeName:honorTypeId;//荣誉类型默认值
  263. //给动态表单设置值
  264. const selectedHonorType = state.honorTypeData.find(item=>item.id == honorTypeId);
  265. const honorTypeDictData = selectedHonorType?.honorTypeDictBOS || [];
  266. state.dynamicFormData = honorTypeDictData;//动态表单
  267. const honorDataList = res?.data?.honorDataList || '';
  268. honorDataList.forEach(item=>{
  269. if(item.dictType == 2){//单选
  270. state.formData[`radio_${item.honorDictLibNameId}`] = state.type!='view'?item.honorDictLibValueId:item.honorDictLibValue;
  271. }else {//输入框 日期
  272. const type = item.dictType == 1 ? 'input' : 'datetime';
  273. state.formData[`${type}_${item.honorDictLibNameId}`] = item.honorDictLibValue;
  274. }
  275. })
  276. const honorDataCertList = res?.data?.honorDataCertList || [];//荣誉证书
  277. state.formData.certPicDatas = honorDataCertList.map(item=>({
  278. ...item,
  279. url:item.picUrl
  280. }));//荣誉证书
  281. state.formData.docDatas = res?.data?.supportDocumentList || [];//佐证材料
  282. state.formData.overruleContent = res?.data?.overruleContent || '';//驳回原因
  283. state.formData.reviewTeacherName = res?.data?.reviewTeacherName || '';//审核人
  284. }
  285. })
  286. }
  287. //提交
  288. const honorTypeConfirm = () => {
  289. console.log(state.formData,rules.value)
  290. for (const key in rules.value) {
  291. if (state.formData?.[key] === "" || state.formData?.[key] === null || state.formData?.[key]&&state.formData?.[key]?.length === 0) {
  292. const errorMessage = rules.value[key].rules[0].errorMessage;
  293. uni.showToast({
  294. title: errorMessage,
  295. icon: 'none'
  296. })
  297. return false
  298. }
  299. }
  300. state.loading = true;
  301. const certPicDatas = state.formData.certPicDatas.map(item=>({
  302. name:item.picName,
  303. url:item.url,
  304. fileSize:item?.fileSize || '',
  305. time:item?.time || '',
  306. }))
  307. const docDatas = state.formData.docDatas.map(item=>({
  308. name:item.documentName,
  309. url:item.documentUrl,
  310. fileSize:item.fileSize,
  311. time:item.createdAt,
  312. }))
  313. const dictDatas = [];
  314. state.dynamicFormData.forEach(item=>{
  315. if(item.dictType == 2){//单选
  316. const valueData = state.formData[`${item.dictShowType}_${item.id}`];
  317. const dictList = item?.dictList || [];
  318. const valueName = dictList.find(dic=>dic.id == valueData);
  319. dictDatas.push({
  320. keyId: item.id,
  321. keyName: item.dictName,
  322. valueId: valueData,
  323. valueName: valueName?.dictName || ''
  324. })
  325. }else{
  326. let valueData = state.formData[`${item.dictShowType}_${item.id}`];
  327. if(state.type == 'upload' && Number(item.dictType) === 0){
  328. valueData = valueData + ' 00:00:00'
  329. }
  330. const dictList = item?.dictList || [];
  331. dictDatas.push({
  332. keyId: item.id,
  333. keyName: item.dictName,
  334. valueId: dictList?.[0]?.id,
  335. valueName: valueData
  336. })
  337. }
  338. })
  339. let params = {
  340. certPicDatas: certPicDatas,
  341. dictDatas: dictDatas,
  342. docDatas:docDatas,
  343. honorTypeId: state.formData.honorTypeValue
  344. }
  345. if(state.id){
  346. params.id = state.id;
  347. updateHonorCertData(params).then(res=>{
  348. if(res.code == 200){
  349. uni.showToast({
  350. title: '修改成功!',
  351. icon: 'none'
  352. })
  353. uni.setStorageSync('isLoadMyHonorList', true);//返回列表页是否重新加载我的荣誉列表
  354. GoBack();
  355. }
  356. }).finally(()=>{
  357. state.loading = false;
  358. })
  359. }else{//新建
  360. addHonorCertData(params).then(res=>{
  361. if(res.code == 200){
  362. uni.showToast({
  363. title: '上传成功!',
  364. icon: 'none'
  365. })
  366. uni.setStorageSync('isLoadMyHonorList', true);//返回列表页是否重新加载我的荣誉列表
  367. GoBack();
  368. }
  369. }).finally(()=>{
  370. state.loading = false;
  371. })
  372. }
  373. }
  374. // 删除图片
  375. const DeletePic = (event) => {
  376. state.formData.certPicDatas.splice(event.index, 1);
  377. }
  378. // 新增图片
  379. const AfterRead = async(event) => {
  380. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  381. let lists = [].concat(event.file);
  382. let fileListLen = state.formData.certPicDatas.length;
  383. lists.map((item) => {
  384. state.formData.certPicDatas.push({
  385. ...item,
  386. status: 'uploading',
  387. message: '上传中1'
  388. })
  389. })
  390. for (let i = 0; i < lists.length; i++) {
  391. const result = await uploadFilePromise(lists[i].url);
  392. if(result.code == 200){
  393. let item = state.formData.certPicDatas[fileListLen]
  394. state.formData.certPicDatas.splice(fileListLen, 1, Object.assign(item, {
  395. status: 'success',
  396. message: '',
  397. picName: result?.data?.fileName,
  398. url:result?.data?.url,
  399. fileSize:fileSizeConvert(lists?.[i]?.size || 0),
  400. time:unioformDateTransform(new Date())
  401. }))
  402. fileListLen++
  403. }
  404. }
  405. }
  406. const uploadFilePromise = (url) => {
  407. return new Promise((resolve, reject) => {
  408. let a = uni.uploadFile({
  409. url: `${apiBaseUrl.value}/api/v1/teach/oss/file/oss/upload_filesSele`,
  410. filePath: url,
  411. name: 'file',
  412. header:{
  413. Authorization:token.value
  414. },
  415. success: (res) => {
  416. const resdata = JSON.parse(res.data);
  417. resolve(resdata)
  418. }
  419. });
  420. })
  421. }
  422. //上传 图片 视频 文档
  423. const FileChooseUploader = () => {
  424. fileUploader.value && fileUploader.value.choose();
  425. // fileUploader.value.chooseFile({//选择上传文件
  426. // count: 1,
  427. // success: (files) => {
  428. // fileUploader.value.upload({//上传单个文件
  429. // url:`${apiBaseUrl.value}/api/v1/teach/oss/file/oss/upload_filesSele`,
  430. // file: files[0],
  431. // name: 'file',
  432. // header: {Authorization: token.value},
  433. // method: 'POST',
  434. // // withCredentials: true, // iOS 本地测远程且要带 cookie
  435. // success: (res) => {
  436. // const result = JSON.parse(res.result);
  437. // state.formData.docDatas.push({
  438. // documentName:result.data.fileName,
  439. // documentUrl:result.data.url,
  440. // fileSize:fileSizeConvert(files?.[0]?.size || 0),
  441. // createdAt:unioformDateTransform(new Date())
  442. // })
  443. // },
  444. // fail: (e) => console.log(e,`${apiBaseUrl.value}/api/v1/teach/oss/file/oss/upload_filesSele`,9999)
  445. // });
  446. // // const fileItem = files[0]
  447. // // // 不使用 fileUploader.value.upload,改用uni原生上传API
  448. // // uni.uploadFile({
  449. // // url: `${apiBaseUrl.value}/api/v1/teach/oss/file/oss/upload_filesSele`,
  450. // // filePath: fileItem.path,
  451. // // name: 'file', //后端接收文件字段名
  452. // // header: {
  453. // // Authorization: token.value
  454. // // },
  455. // // timeout: 120000, //上传超时时间,大文件2分钟
  456. // // success: (res) => {
  457. // // console.log('上传成功',res, res.statusCode, res.data)
  458. // // const result = JSON.parse(res.data);
  459. // // state.formData.docDatas.push({
  460. // // documentName: result.data.fileName,
  461. // // documentUrl: result.data.url,
  462. // // fileSize: fileSizeConvert(fileItem?.size || 0),
  463. // // createdAt: unioformDateTransform(new Date())
  464. // // })
  465. // // },
  466. // // fail: (err) => {
  467. // // //这里打印iOS原生真实错误,不再是组件包装后的“网络错误”
  468. // // console.error('uni.uploadFile原生失败', err)
  469. // // }
  470. // // })
  471. // }
  472. // })
  473. }
  474. //上传成功
  475. const onUploadSuccess = ({
  476. index,
  477. file, // 当前文件
  478. url, // 优先为解析出的远程地址
  479. statusCode,
  480. data, // 解析后的服务端 JSON(失败则为原始字符串)
  481. res, // 原始回调
  482. fileList // 当前全部
  483. }) => {
  484. const result = JSON.parse(res.data || res.result);
  485. const fileObj = result?.data;
  486. if(fileObj){
  487. state.formData.docDatas.push({
  488. documentName:fileObj.fileName,
  489. documentUrl:fileObj.url,
  490. fileSize:fileSizeConvert(file?.size || 0),
  491. createdAt:unioformDateTransform(new Date())
  492. })
  493. }
  494. }
  495. //预览
  496. const OpenPreviewFileDialog = (item) => {
  497. const fileNameSuffix = item?.documentName?.split('.')?.[1] || '';
  498. const fileType = getFileTypeBySuffix(fileNameSuffix);
  499. console.log(fileType,899)
  500. state.previewPopup.fileType = fileType?fileType:fileNameSuffix;
  501. state.previewPopup.filePath = item.documentUrl;
  502. state.previewPopup.fileName = item.documentName;
  503. if(['word','excel','pptx','pdf','txt'].includes(fileType)){
  504. // #ifdef H5
  505. nextTick(()=>{//h5文件预览
  506. webPreviewFile.value && webPreviewFile.value.preview({
  507. url: item.documentUrl,
  508. type: fileType
  509. });
  510. })
  511. // #endif
  512. // #ifdef APP-PLUS
  513. if(fileType == 'pptx'){
  514. imgVideoPreview.value.OpenDialog();
  515. }
  516. // #endif
  517. }else{
  518. imgVideoPreview.value.OpenDialog();
  519. }
  520. }
  521. //下载
  522. const ToDownloadFile = (item) => {
  523. const fileType = getFileTypeBySuffix(item.fileType);//文件类型
  524. let type = '';
  525. if(fileType == 'image'){
  526. type = '1';//1:图片 2 文档
  527. }else if(['word','excel','pptx','pdf','txt'].includes(fileType)){
  528. type = '2';
  529. }else if(fileType == 'video'){
  530. type = '3';
  531. }else {
  532. type = '';
  533. }
  534. ssdownload?.value?.toDownload({
  535. type:type,
  536. src:item.filePath,
  537. fileName:item.fileName
  538. });
  539. }
  540. const GoBack = () => {
  541. uni.navigateBack({
  542. delta: 1
  543. });
  544. }
  545. </script>
  546. <style lang="scss" scoped>
  547. .page_body{
  548. height: 100%;
  549. min-height: auto;
  550. overflow: hidden;
  551. }
  552. .page_content{
  553. height: calc(100% - 250rpx);
  554. overflow: auto;
  555. &.view{
  556. height: calc(100% - 96rpx);
  557. }
  558. }
  559. .forms_style{
  560. &.view{
  561. :deep(.uni-forms-item){
  562. &.uni-forms-item--border{
  563. .uni-forms-item__label{
  564. padding-top: 0rpx;
  565. }
  566. }
  567. }
  568. }
  569. :deep(.uni-forms-item){
  570. &.uni-forms-item--border{
  571. border-top: 0;
  572. border-bottom: 2rpx solid #F3F3F3;
  573. .uni-forms-item__label{
  574. align-items: flex-start;
  575. padding-top: 16rpx;
  576. }
  577. }
  578. .uv-upload__wrap{
  579. // flex-direction: row-reverse;
  580. gap: 24rpx 32rpx;
  581. .uv-upload__wrap__preview{
  582. background-color: #FFFFFF;
  583. border-radius: 20rpx;
  584. border: 2rpx solid #CED1D8;
  585. box-sizing: border-box;
  586. margin: 0;
  587. .uv-upload__deletable{
  588. top:10rpx;
  589. right: 10rpx;
  590. background-color: transparent;
  591. height: 32rpx;
  592. width: 32rpx;
  593. border: 2rpx solid #999999;
  594. border-radius: 50%;
  595. .uvicon-close{
  596. color:#999999 !important;
  597. font-size: 11rpx !important;
  598. }
  599. }
  600. .uv-upload__deletable__icon{
  601. transform: scale(1);
  602. top:50%;
  603. right: 50%;
  604. transform: translate(50%, -50%);
  605. }
  606. .uv-upload__success{
  607. border-width: 20rpx;
  608. }
  609. }
  610. .upload_btn{
  611. width: 240rpx;
  612. height: 140rpx;
  613. background-color: #FAFBFF;
  614. border-radius: 20rpx;
  615. border: 2rpx solid #CCCED4;
  616. box-sizing: border-box;
  617. display: flex;
  618. flex-direction: column;
  619. align-items: center;
  620. justify-content: center;
  621. .upload_btn_icon{
  622. font-size: 40rpx !important;
  623. color: #CCCED4 !important;
  624. }
  625. .upload_btn_text{
  626. margin-top: 16rpx;
  627. font-weight: 400;
  628. font-size: 24rpx;
  629. color: #CCCED4;
  630. }
  631. }
  632. }
  633. .upload_file_btn{
  634. width: 100%;
  635. height: 120rpx;
  636. display: flex;
  637. justify-content: center;
  638. flex-direction: column;
  639. align-items: center;
  640. background-color: #FAFBFF;
  641. border-radius: 20rpx;
  642. border: 2rpx dashed #CCCED4;
  643. .upload_file_btn_icon{
  644. font-size: 40rpx !important;
  645. color: #CCCED4 !important;
  646. }
  647. .upload_file_btn_text{
  648. font-weight: 400;
  649. font-size: 24rpx;
  650. color: #CCCED4;
  651. margin-top: 8rpx;
  652. }
  653. }
  654. .upload_file_list_item{
  655. display: flex;
  656. align-items: center;
  657. width: 100%;
  658. min-height: 120rpx;
  659. padding: 20rpx 24rpx;
  660. background-color: #FFFFFF;
  661. border-radius: 20rpx;
  662. border: 2rpx solid #EBEEF5;
  663. box-sizing: border-box;
  664. margin-top: 24rpx;
  665. .list_item_icon {
  666. width: 80rpx;
  667. height: 80rpx;
  668. margin-right: 20rpx;
  669. flex-shrink: 0;
  670. }
  671. .list_item_content {
  672. flex: 1;
  673. // width: 0;
  674. // overflow: hidden;
  675. .item_content_title {
  676. width: 100%;
  677. font-weight: 500;
  678. font-size: 28rpx;
  679. color: #333333;
  680. word-break: break-all;
  681. text-align: left;
  682. // white-space: nowrap;
  683. // overflow: hidden;
  684. // text-overflow: ellipsis;
  685. // word-break: keep-all; /* ✅ 防止意外换行 */
  686. }
  687. .item_content_info {
  688. display: flex;
  689. flex-wrap: wrap;
  690. align-items: center;
  691. gap: 4rpx 20rpx;
  692. margin-top: 8rpx;
  693. .size {
  694. font-weight: 400;
  695. font-size: 24rpx;
  696. color: #999999;
  697. flex-shrink: 0;
  698. }
  699. .time {
  700. font-size: 24rpx;
  701. color: #999999;
  702. flex-shrink: 0;
  703. }
  704. }
  705. }
  706. .list_item_close {
  707. flex-shrink: 0;
  708. color: #999999 !important;
  709. font-size: 48rpx !important;
  710. }
  711. .container{
  712. width: auto;
  713. .file_content{
  714. width: auto;
  715. }
  716. }
  717. .list_item_preview{
  718. flex-shrink: 0;
  719. font-weight: 400;
  720. font-size: 28rpx;
  721. color: #2E64FA;
  722. }
  723. }
  724. }
  725. }
  726. .page_foot{
  727. position: fixed;
  728. left:0;
  729. right: 0;
  730. bottom: 0;
  731. padding: 20rpx 24rpx;
  732. background-color:#FFFFFF;
  733. .btn_submit{
  734. width: 100%;
  735. height: 88rpx;
  736. display: flex;
  737. justify-content: center;
  738. align-items: center;
  739. background-color: #2E64FA !important;
  740. border-radius: 20rpx;
  741. color: #FFFFFF;
  742. font-size: 28rpx;
  743. }
  744. }
  745. </style>