uploadEditMyHonor.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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 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. state.formData.docDatas = res?.data?.supportDocumentList || [];//佐证材料
  283. state.formData.overruleContent = res?.data?.overruleContent || '';//驳回原因
  284. state.formData.reviewTeacherName = res?.data?.reviewTeacherName || '';//审核人
  285. }
  286. })
  287. }
  288. //提交
  289. const honorTypeConfirm = () => {
  290. console.log(state.formData,rules.value)
  291. for (const key in rules.value) {
  292. if (state.formData?.[key] === "" || state.formData?.[key] === null || state.formData?.[key]&&state.formData?.[key]?.length === 0) {
  293. const errorMessage = rules.value[key].rules[0].errorMessage;
  294. uni.showToast({
  295. title: errorMessage,
  296. icon: 'none'
  297. })
  298. return false
  299. }
  300. }
  301. state.loading = true;
  302. const certPicDatas = state.formData.certPicDatas.map(item=>({
  303. name:item.picName,
  304. url:item.url,
  305. fileSize:item?.fileSize || '',
  306. time:item?.time || '',
  307. }))
  308. const docDatas = state.formData.docDatas.map(item=>({
  309. name:item.documentName,
  310. url:item.documentUrl,
  311. fileSize:item.fileSize,
  312. time:item.createdAt,
  313. }))
  314. const dictDatas = [];
  315. state.dynamicFormData.forEach(item=>{
  316. if(item.dictType == 2){//单选
  317. const valueData = state.formData[`${item.dictShowType}_${item.id}`];
  318. const dictList = item?.dictList || [];
  319. const valueName = dictList.find(dic=>dic.id == valueData);
  320. dictDatas.push({
  321. keyId: item.id,
  322. keyName: item.dictName,
  323. valueId: valueData,
  324. valueName: valueName?.dictName || ''
  325. })
  326. }else{
  327. let valueData = state.formData[`${item.dictShowType}_${item.id}`];
  328. if(state.type == 'upload' && Number(item.dictType) === 0){
  329. valueData = valueData + ' 00:00:00'
  330. }
  331. const dictList = item?.dictList || [];
  332. dictDatas.push({
  333. keyId: item.id,
  334. keyName: item.dictName,
  335. valueId: dictList?.[0]?.id,
  336. valueName: valueData
  337. })
  338. }
  339. })
  340. let params = {
  341. certPicDatas: certPicDatas,
  342. dictDatas: dictDatas,
  343. docDatas:docDatas,
  344. honorTypeId: state.formData.honorTypeValue
  345. }
  346. if(state.id){
  347. params.id = state.id;
  348. updateHonorCertData(params).then(res=>{
  349. if(res.code == 200){
  350. uni.showToast({
  351. title: '修改成功!',
  352. icon: 'none'
  353. })
  354. uni.setStorageSync('isLoadMyHonorList', true);//返回列表页是否重新加载我的荣誉列表
  355. GoBack();
  356. }
  357. }).finally(()=>{
  358. state.loading = false;
  359. })
  360. }else{//新建
  361. addHonorCertData(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. }
  374. }
  375. // 删除图片
  376. const DeletePic = (event) => {
  377. state.formData.certPicDatas.splice(event.index, 1);
  378. }
  379. // 新增图片
  380. const AfterRead = async(event) => {
  381. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  382. let lists = [].concat(event.file);
  383. let fileListLen = state.formData.certPicDatas.length;
  384. lists.map((item) => {
  385. state.formData.certPicDatas.push({
  386. ...item,
  387. status: 'uploading',
  388. message: '上传中1'
  389. })
  390. })
  391. for (let i = 0; i < lists.length; i++) {
  392. const result = await uploadFilePromise(lists[i].url);
  393. if(result.code == 200){
  394. let item = state.formData.certPicDatas[fileListLen]
  395. state.formData.certPicDatas.splice(fileListLen, 1, Object.assign(item, {
  396. status: 'success',
  397. message: '',
  398. picName: result?.data?.fileName,
  399. url:result?.data?.url,
  400. fileSize:fileSizeConvert(lists?.[i]?.size || 0),
  401. time:unioformDateTransform(new Date())
  402. }))
  403. fileListLen++
  404. }
  405. }
  406. }
  407. const uploadFilePromise = (url) => {
  408. return new Promise((resolve, reject) => {
  409. let a = uni.uploadFile({
  410. url: `${apiBaseUrl.value}/api/v1/teach/oss/file/oss/upload_filesSele`,
  411. filePath: url,
  412. name: 'file',
  413. header:{
  414. Authorization:token.value
  415. },
  416. success: (res) => {
  417. const resdata = JSON.parse(res.data);
  418. resolve(resdata)
  419. }
  420. });
  421. })
  422. }
  423. //上传 图片 视频 文档
  424. const FileChooseUploader = () => {
  425. fileUploader.value && fileUploader.value.choose();
  426. // fileUploader.value.chooseFile({//选择上传文件
  427. // count: 1,
  428. // success: (files) => {
  429. // fileUploader.value.upload({//上传单个文件
  430. // url:`${apiBaseUrl.value}/api/v1/teach/oss/file/oss/upload_filesSele`,
  431. // file: files[0],
  432. // name: 'file',
  433. // header: {Authorization: token.value},
  434. // method: 'POST',
  435. // // withCredentials: true, // iOS 本地测远程且要带 cookie
  436. // success: (res) => {
  437. // const result = JSON.parse(res.result);
  438. // state.formData.docDatas.push({
  439. // documentName:result.data.fileName,
  440. // documentUrl:result.data.url,
  441. // fileSize:fileSizeConvert(files?.[0]?.size || 0),
  442. // createdAt:unioformDateTransform(new Date())
  443. // })
  444. // },
  445. // fail: (e) => console.log(e,`${apiBaseUrl.value}/api/v1/teach/oss/file/oss/upload_filesSele`,9999)
  446. // });
  447. // // const fileItem = files[0]
  448. // // // 不使用 fileUploader.value.upload,改用uni原生上传API
  449. // // uni.uploadFile({
  450. // // url: `${apiBaseUrl.value}/api/v1/teach/oss/file/oss/upload_filesSele`,
  451. // // filePath: fileItem.path,
  452. // // name: 'file', //后端接收文件字段名
  453. // // header: {
  454. // // Authorization: token.value
  455. // // },
  456. // // timeout: 120000, //上传超时时间,大文件2分钟
  457. // // success: (res) => {
  458. // // console.log('上传成功',res, res.statusCode, res.data)
  459. // // const result = JSON.parse(res.data);
  460. // // state.formData.docDatas.push({
  461. // // documentName: result.data.fileName,
  462. // // documentUrl: result.data.url,
  463. // // fileSize: fileSizeConvert(fileItem?.size || 0),
  464. // // createdAt: unioformDateTransform(new Date())
  465. // // })
  466. // // },
  467. // // fail: (err) => {
  468. // // //这里打印iOS原生真实错误,不再是组件包装后的“网络错误”
  469. // // console.error('uni.uploadFile原生失败', err)
  470. // // }
  471. // // })
  472. // }
  473. // })
  474. }
  475. //上传成功
  476. const onUploadSuccess = ({
  477. index,
  478. file, // 当前文件
  479. url, // 优先为解析出的远程地址
  480. statusCode,
  481. data, // 解析后的服务端 JSON(失败则为原始字符串)
  482. res, // 原始回调
  483. fileList // 当前全部
  484. }) => {
  485. const result = JSON.parse(res.data || res.result);
  486. const fileObj = result?.data;
  487. if(fileObj){
  488. state.formData.docDatas.push({
  489. documentName:fileObj.fileName,
  490. documentUrl:fileObj.url,
  491. fileSize:fileSizeConvert(file?.size || 0),
  492. createdAt:unioformDateTransform(new Date())
  493. })
  494. }
  495. }
  496. //预览
  497. const OpenPreviewFileDialog = (item) => {
  498. const fileNameSuffix = item?.documentName?.split('.')?.[1] || '';
  499. const fileType = getFileTypeBySuffix(fileNameSuffix);
  500. console.log(fileType,899)
  501. state.previewPopup.fileType = fileType?fileType:fileNameSuffix;
  502. state.previewPopup.filePath = item.documentUrl;
  503. state.previewPopup.fileName = item.documentName;
  504. if(['word','excel','pptx','pdf','txt'].includes(fileType)){
  505. // #ifdef H5
  506. nextTick(()=>{//h5文件预览
  507. webPreviewFile.value && webPreviewFile.value.preview({
  508. url: item.documentUrl,
  509. type: fileType
  510. });
  511. })
  512. // #endif
  513. // #ifdef APP-PLUS
  514. if(fileType == 'pptx'){
  515. imgVideoPreview.value.OpenDialog();
  516. }
  517. // #endif
  518. }else{
  519. imgVideoPreview.value.OpenDialog();
  520. }
  521. }
  522. //下载
  523. const ToDownloadFile = (item) => {
  524. const fileType = getFileTypeBySuffix(item.fileType);//文件类型
  525. let type = '';
  526. if(fileType == 'image'){
  527. type = '1';//1:图片 2 文档
  528. }else if(['word','excel','pptx','pdf','txt'].includes(fileType)){
  529. type = '2';
  530. }else if(fileType == 'video'){
  531. type = '3';
  532. }else {
  533. type = '';
  534. }
  535. ssdownload?.value?.toDownload({
  536. type:type,
  537. src:item.filePath,
  538. fileName:item.fileName
  539. });
  540. }
  541. const GoBack = () => {
  542. uni.navigateBack({
  543. delta: 1
  544. });
  545. }
  546. </script>
  547. <style lang="scss" scoped>
  548. .page_body{
  549. height: 100%;
  550. min-height: auto;
  551. overflow: hidden;
  552. }
  553. .page_content{
  554. height: calc(100% - 250rpx);
  555. overflow: auto;
  556. &.view{
  557. height: calc(100% - 96rpx);
  558. }
  559. }
  560. .forms_style{
  561. &.view{
  562. :deep(.uni-forms-item){
  563. &.uni-forms-item--border{
  564. .uni-forms-item__label{
  565. padding-top: 0rpx;
  566. }
  567. }
  568. }
  569. }
  570. :deep(.uni-forms-item){
  571. &.uni-forms-item--border{
  572. border-top: 0;
  573. border-bottom: 2rpx solid #F3F3F3;
  574. .uni-forms-item__label{
  575. align-items: flex-start;
  576. padding-top: 16rpx;
  577. }
  578. }
  579. .uv-upload__wrap{
  580. // flex-direction: row-reverse;
  581. gap: 24rpx 32rpx;
  582. .uv-upload__wrap__preview{
  583. background-color: #FFFFFF;
  584. border-radius: 20rpx;
  585. border: 2rpx solid #CED1D8;
  586. box-sizing: border-box;
  587. margin: 0;
  588. .uv-upload__deletable{
  589. top:10rpx;
  590. right: 10rpx;
  591. background-color: transparent;
  592. height: 32rpx;
  593. width: 32rpx;
  594. border: 2rpx solid #999999;
  595. border-radius: 50%;
  596. .uvicon-close{
  597. color:#999999 !important;
  598. font-size: 11rpx !important;
  599. }
  600. }
  601. .uv-upload__deletable__icon{
  602. transform: scale(1);
  603. top:50%;
  604. right: 50%;
  605. transform: translate(50%, -50%);
  606. }
  607. .uv-upload__success{
  608. border-width: 20rpx;
  609. }
  610. }
  611. .upload_btn{
  612. width: 240rpx;
  613. height: 140rpx;
  614. background-color: #FAFBFF;
  615. border-radius: 20rpx;
  616. border: 2rpx solid #CCCED4;
  617. box-sizing: border-box;
  618. display: flex;
  619. flex-direction: column;
  620. align-items: center;
  621. justify-content: center;
  622. .upload_btn_icon{
  623. font-size: 40rpx !important;
  624. color: #CCCED4 !important;
  625. }
  626. .upload_btn_text{
  627. margin-top: 16rpx;
  628. font-weight: 400;
  629. font-size: 24rpx;
  630. color: #CCCED4;
  631. }
  632. }
  633. }
  634. .upload_file_btn{
  635. width: 100%;
  636. height: 120rpx;
  637. display: flex;
  638. justify-content: center;
  639. flex-direction: column;
  640. align-items: center;
  641. background-color: #FAFBFF;
  642. border-radius: 20rpx;
  643. border: 2rpx dashed #CCCED4;
  644. .upload_file_btn_icon{
  645. font-size: 40rpx !important;
  646. color: #CCCED4 !important;
  647. }
  648. .upload_file_btn_text{
  649. font-weight: 400;
  650. font-size: 24rpx;
  651. color: #CCCED4;
  652. margin-top: 8rpx;
  653. }
  654. }
  655. .upload_file_list_item{
  656. display: flex;
  657. align-items: center;
  658. width: 100%;
  659. min-height: 120rpx;
  660. padding: 20rpx 24rpx;
  661. background-color: #FFFFFF;
  662. border-radius: 20rpx;
  663. border: 2rpx solid #EBEEF5;
  664. box-sizing: border-box;
  665. margin-top: 24rpx;
  666. .list_item_icon {
  667. width: 80rpx;
  668. height: 80rpx;
  669. margin-right: 20rpx;
  670. flex-shrink: 0;
  671. }
  672. .list_item_content {
  673. flex: 1;
  674. // width: 0;
  675. // overflow: hidden;
  676. .item_content_title {
  677. width: 100%;
  678. font-weight: 500;
  679. font-size: 28rpx;
  680. color: #333333;
  681. word-break: break-all;
  682. text-align: left;
  683. // white-space: nowrap;
  684. // overflow: hidden;
  685. // text-overflow: ellipsis;
  686. // word-break: keep-all; /* ✅ 防止意外换行 */
  687. }
  688. .item_content_info {
  689. display: flex;
  690. flex-wrap: wrap;
  691. align-items: center;
  692. gap: 4rpx 20rpx;
  693. margin-top: 8rpx;
  694. .size {
  695. font-weight: 400;
  696. font-size: 24rpx;
  697. color: #999999;
  698. flex-shrink: 0;
  699. }
  700. .time {
  701. font-size: 24rpx;
  702. color: #999999;
  703. flex-shrink: 0;
  704. }
  705. }
  706. }
  707. .list_item_close {
  708. flex-shrink: 0;
  709. color: #999999 !important;
  710. font-size: 48rpx !important;
  711. }
  712. .container{
  713. width: auto;
  714. .file_content{
  715. width: auto;
  716. }
  717. }
  718. .list_item_preview{
  719. flex-shrink: 0;
  720. font-weight: 400;
  721. font-size: 28rpx;
  722. color: #2E64FA;
  723. }
  724. }
  725. }
  726. }
  727. .page_foot{
  728. position: fixed;
  729. left:0;
  730. right: 0;
  731. bottom: 0;
  732. padding: 20rpx 24rpx;
  733. background-color:#FFFFFF;
  734. .btn_submit{
  735. width: 100%;
  736. height: 88rpx;
  737. display: flex;
  738. justify-content: center;
  739. align-items: center;
  740. background-color: #2E64FA !important;
  741. border-radius: 20rpx;
  742. color: #FFFFFF;
  743. font-size: 28rpx;
  744. }
  745. }
  746. </style>