uploadEditMyHonor.vue 26 KB

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