files.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. <template>
  2. <view class="content-box">
  3. <view class="info-box">
  4. <view class="img-container">
  5. <label for="img">上传文件</label>
  6. <view class="note-image-box">
  7. <view class="note-image-item" v-for="(item,index) in uploadList" :key="item.id">
  8. <!-- //右上角删除图标 -->
  9. <view class="close-icon" @click="delFile(index)">
  10. <uni-icons type="closeempty" size="18" color="#fff"></uni-icons>
  11. </view>
  12. <view class="image-box display-evenly-column" @click="()=>openFile(item.url)">
  13. <image :src=" fileType[item.type] ||'../../../static/file.png'" mode="aspectFill" style="width: 70rpx;height: 70rpx;"></image>
  14. <view class="file-font-box">{{item.name}}</view>
  15. </view>
  16. </view>
  17. <view v-if="uploadList.length < 3" class="note-image-item" @click="chooseFile()">
  18. <!-- //添加图片按钮 -->
  19. <view class="image-box">
  20. <uni-icons type="plusempty" size="50" color="#eee"></uni-icons>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="info-box">
  27. <view class="info-title-box">
  28. <!-- <image src="/static/require-icon.png" mode="aspectFill"></image> -->
  29. <text>文件备注</text>
  30. </view>
  31. <view class="info-value-box">
  32. <textarea type="text" class="textarea-box" v-model="contentDesc"></textarea>
  33. </view>
  34. </view>
  35. <view class="footer-box">
  36. <!-- <button type="primary" class="submit-bth" style="background-color: #aaaaaa;" @click="goStep()">清空</button> -->
  37. <button type="primary" class="submit-bth" style="background-color: #169bd5;" @click="addOrEditActiveFiles()">提交</button>
  38. </view>
  39. <!-- <view class="mask-share-box" v-if="isShowShare">
  40. <image src="/static/share-arrow.png" mode="aspectFit"></image>
  41. <view>点击右上角分享</view>
  42. <button @click="closeShare">关闭</button>
  43. </view> -->
  44. <!-- <share-modal @closeShare="closeShare" :isShowShare="isShowShareModal"></share-modal> -->
  45. </view>
  46. </template>
  47. <script>
  48. import md5 from "@/common/md5.js";
  49. import shareModal from '@/components/share-modal/share-modal.vue'
  50. // var graceChecker = require("../../../common/graceChecker.js");
  51. export default {
  52. components: {
  53. "share-modal": shareModal,
  54. },
  55. data() {
  56. return {
  57. globalUrl:getApp().globalData.shareUrl,
  58. branchId:'',
  59. activeId:'',
  60. recordId:'',
  61. recordObj:{},
  62. fileIdList: [],
  63. uploadList:[],
  64. contentDesc:'',
  65. type:'add',
  66. isShowShareModal:false,
  67. fileType:{
  68. 'docx':'../../../static/files-icon/word.png',
  69. 'doc':'../../../static/files-icon/word.png',
  70. 'pdf':'../../../static/files-icon/pdf.png',
  71. 'xlsx':'../../../static/files-icon/excel.png',
  72. 'xls':'../../../static/files-icon/excel.png',
  73. 'pptx':'../../../static/files-icon/ppt.png',
  74. }
  75. }
  76. },
  77. onLoad(option) {
  78. console.log(option)
  79. this.branchId = option.bId;
  80. this.activeId = option.aId;
  81. this.type = option.types;
  82. if(option.types === 'edit'){
  83. this.getInfos(option.id)
  84. }
  85. },
  86. onShow() {
  87. },
  88. onShareAppMessage() {
  89. return {
  90. title: '农工笔记',
  91. path:'/pages/index/activity/activity'
  92. }
  93. },
  94. methods: {
  95. closeShare(e){
  96. this.isShowShareModal = false;
  97. uni.showToast({
  98. title: "上传成功",
  99. icon: "none",
  100. duration: 2500,
  101. });
  102. setTimeout(()=>{uni.navigateBack({})},500)
  103. },
  104. splitFileNameList(fileList){
  105. let arr = fileList;
  106. arr.forEach((item,index)=>{
  107. item.type = item.name.split('.').pop().toLowerCase();
  108. })
  109. return arr;
  110. },
  111. getInfos(id){
  112. let md5Sign = md5(
  113. "method=" +"activity" + "&timestamp=" + getApp().globalData.globalTimestamp +
  114. "&secret=" + getApp().globalData.secret
  115. );
  116. let url = getApp().globalData.shareUrl +"api/api.php" +"?method=activity&action=files_info_by_id&timestamp=" +
  117. getApp().globalData.globalTimestamp + "&sign=" + md5Sign;
  118. uni.request({
  119. url: url,
  120. method: "POST",
  121. header: {
  122. "content-type": "application/x-www-form-urlencoded",
  123. },
  124. data: {
  125. openid:getApp().globalData.open_id,
  126. id:id
  127. },
  128. success: (res) => {
  129. if (res.data.code === 200) {
  130. let obj = res.data.data;
  131. this.recordId = obj.id;
  132. this.contentDesc = obj.content;
  133. obj.file_list.forEach((item)=>{
  134. this.fileIdList.push(item.id)
  135. })
  136. let fileArr = obj.file_list;
  137. console.log(fileArr)
  138. this.uploadList = this.splitFileNameList(fileArr);
  139. console.log(this.uploadList)
  140. }
  141. },
  142. fail: () => {
  143. console.log("连接失败");
  144. },
  145. });
  146. },
  147. addOrEditActiveFiles(){
  148. let url,data;
  149. let md5Sign = md5(
  150. "method=" +"activity" + "&timestamp=" + getApp().globalData.globalTimestamp +
  151. "&secret=" + getApp().globalData.secret
  152. );
  153. if(this.type === 'add'){
  154. url = getApp().globalData.shareUrl +"api/api.php" +"?method=activity&action=files_add&timestamp=" +
  155. getApp().globalData.globalTimestamp + "&sign=" + md5Sign;
  156. data = {
  157. openid:getApp().globalData.open_id,
  158. branch_id:this.branchId,
  159. activity_id:this.activeId,
  160. content:this.contentDesc,
  161. attach_ids:this.fileIdList.join()
  162. }
  163. }else {
  164. url = getApp().globalData.shareUrl +"api/api.php" +"?method=activity&action=files_update&timestamp=" +
  165. getApp().globalData.globalTimestamp + "&sign=" + md5Sign;
  166. data = {
  167. openid:getApp().globalData.open_id,
  168. id:this.recordId,
  169. branch_id:this.branchId,
  170. activity_id:this.activeId,
  171. content:this.contentDesc,
  172. attach_ids:this.fileIdList.join()
  173. }
  174. }
  175. uni.request({
  176. url: url,
  177. method: "POST",
  178. header: {
  179. "content-type": "application/x-www-form-urlencoded",
  180. },
  181. data:data,
  182. success: (res) => {
  183. if (res.data.code === 200) {
  184. if(this.type === 'edit'){
  185. uni.showToast({
  186. title: "修改成功",
  187. icon: "none",
  188. duration: 2500,
  189. });
  190. let pages = getCurrentPages(); // 获取当前页面栈的实例,以数组形式按栈的顺序给出,第一个元素为首页,最后一个元素为当前页面。
  191. let nowPage = pages[pages.length - 1]; //当前页页面实例
  192. let prevPage = pages[pages.length - 2]; //上一页页面实例
  193. prevPage.$vm.pageShowShare('edit','files')
  194. setTimeout(()=>{uni.navigateBack({})},500)
  195. }else {
  196. let types = 'add';
  197. let pages = getCurrentPages(); // 获取当前页面栈的实例,以数组形式按栈的顺序给出,第一个元素为首页,最后一个元素为当前页面。
  198. let nowPage = pages[pages.length - 1]; //当前页页面实例
  199. let prevPage = pages[pages.length - 2]; //上一页页面实例
  200. prevPage.$vm.pageShowShare(types,'files')
  201. uni.showToast({
  202. title: "上传成功",
  203. icon: "none",
  204. duration: 2500,
  205. });
  206. setTimeout(()=>{uni.navigateBack({delta:1})},500)
  207. //this.isShowShareModal = true
  208. }
  209. }
  210. },
  211. fail: () => {
  212. console.log("连接失败");
  213. },
  214. });
  215. },
  216. openFile(files){
  217. uni.showLoading({
  218. mask:true,
  219. title:'加载中...',
  220. icon:'none'
  221. })
  222. uni.downloadFile({
  223. url: getApp().globalData.shareUrl + files,
  224. success: function(res) {
  225. var filePath = res.tempFilePath;
  226. //打开文件有效值 doc, xls, ppt, pdf, docx, xlsx, pptx
  227. uni.openDocument({
  228. filePath:filePath,
  229. success: function(res) {
  230. uni.hideLoading();
  231. //that.downloadFile_onoff = true;
  232. },
  233. fail(res) {
  234. uni.showToast({
  235. title: '暂不支持此类型',
  236. icon:'none',
  237. duration: 2000
  238. });
  239. uni.hideLoading();
  240. //that.downloadFile_onoff = true;
  241. }
  242. });
  243. }
  244. });
  245. },
  246. chooseFile(){
  247. //chooseMessageFile
  248. let that = this;
  249. uni.chooseMessageFile({
  250. count: 3,
  251. type: 'file',
  252. success (res) {
  253. for(let i=0;i<res.tempFiles.length;i++){
  254. res.tempFiles[i].size = (res.tempFiles[i].size/1024) ;
  255. res.tempFiles[i].size = Math.trunc(res.tempFiles[i].size);
  256. let msg = {name:res.tempFiles[i].name,textValue:res.tempFiles[i].path,size:res.tempFiles[i].size};
  257. that.uploadFileRequest(msg)
  258. }
  259. }
  260. })
  261. console.log('文件上传')
  262. },
  263. splitFileName(param){
  264. let obj = param;
  265. obj.type = param.name.split('.').pop().toLowerCase();
  266. return obj;
  267. },
  268. uploadFileRequest(fileVal){
  269. let that = this;
  270. uni.showLoading({
  271. mask:true,
  272. title:'上传中...',
  273. icon:'none'
  274. })
  275. let md5Sign = md5(
  276. "method=" +"activity_file_upload" +"&timestamp=" +
  277. getApp().globalData.globalTimestamp +"&secret=" +getApp().globalData.secret
  278. );
  279. let url = getApp().globalData.shareUrl + "api/api.php" +"?method=activity_file_upload&timestamp=" +
  280. getApp().globalData.globalTimestamp +"&sign=" + md5Sign;
  281. uni.uploadFile({
  282. url:url, //需要设置为全局
  283. filePath:fileVal.textValue,
  284. name:'file',
  285. formData: {
  286. openid: getApp().globalData.open_id,
  287. file:fileVal.textValue,
  288. branch_id:this.branchId,
  289. file_name:fileVal.name
  290. },
  291. success: res => {
  292. this.fileObj = JSON.parse(res.data);
  293. this.fileObj.data = this.splitFileName(this.fileObj.data);
  294. this.fileObj.data.url = getApp().globalData.shareUrl + this.fileObj.data.url;
  295. this.uploadList.push(this.fileObj.data);
  296. this.fileIdList.push(this.fileObj.data.id);
  297. uni.hideLoading();
  298. },
  299. fail:res=>{
  300. console.log("上传请求失败");
  301. console.log(res);
  302. }
  303. });
  304. },
  305. delFile(idx) {
  306. this.uploadList.splice(idx, 1);
  307. this.fileIdList.splice(idx, 1);
  308. console.log(this.fileIdList)
  309. },
  310. }
  311. }
  312. </script>
  313. <style lang="scss" scoped>
  314. .content {
  315. &_list{
  316. display: flex;
  317. flex-direction: row;
  318. align-items: center;
  319. justify-content:space-around;
  320. &_lable{
  321. }
  322. &_content{
  323. flex: 1;
  324. width: auto;
  325. text-align: right;
  326. }
  327. }
  328. }
  329. .content-box {
  330. width: 100%;
  331. /* height: 100%; */
  332. display: flex;
  333. flex-direction: column;
  334. align-items: center;
  335. /* justify-content: center; */
  336. }
  337. .header-box {
  338. width: 85%;
  339. height:80rpx;
  340. border: .5px dotted #00A1B4;
  341. border-radius: 50rpx;
  342. display: flex;
  343. justify-content: center;
  344. align-items: center;
  345. font-size: 24rpx;
  346. color:#00A1B4 ;
  347. /* font-family: PingFangSC-Regular; */
  348. margin-top: 2%;
  349. }
  350. .header-box image {
  351. width: 36rpx;
  352. height: 36rpx;
  353. margin-right: 1%;
  354. }
  355. .self-title-box {
  356. width: 90%;
  357. display: flex;
  358. align-items: center;
  359. font-size: 32rpx;
  360. letter-spacing: 2rpx;
  361. color:#3C3C3C ;
  362. /* font-family: SimHei; */
  363. margin: 4% auto;
  364. font-weight: bold;
  365. height: 50rpx;
  366. line-height: 50rpx;
  367. }
  368. .self-title-box image {
  369. width: 6rpx;
  370. height: 32rpx;
  371. margin-right: 2%;
  372. }
  373. .info-box {
  374. width: 90%;
  375. margin: 3% auto;
  376. display: flex;
  377. flex-direction: column;
  378. // align-items: center;
  379. // height: 180rpx;
  380. }
  381. .info-title-box {
  382. display: flex;
  383. align-items: center;
  384. font-size: 28rpx;
  385. }
  386. .info-title-box image{
  387. width: 15rpx;
  388. height: 15rpx;
  389. margin-right: 2%;
  390. }
  391. .info-value-box {
  392. width: 100%;
  393. }
  394. .info-value-box input {
  395. height: 88rpx;
  396. background: #f7f7f7;
  397. font-size: 26rpx;
  398. padding-left: 4%;
  399. margin: 2% auto;
  400. }
  401. .info-value-box picker {
  402. position: relative;
  403. }
  404. .info-value-box picker image {
  405. position: absolute;
  406. width: 25rpx;
  407. height: 25rpx;
  408. right: 10px;
  409. top: 30rpx;
  410. }
  411. .select-box {
  412. height: 80rpx;
  413. background: #f7f7f7;
  414. font-size: 26rpx;
  415. padding-left: 4%;
  416. margin: 2% auto;
  417. color: #888;
  418. line-height: 88rpx;
  419. }
  420. .info-gender-box {
  421. width: 75%;
  422. font-size: 28rpx;
  423. }
  424. .form-radio {
  425. transform: scale(0.6);
  426. }
  427. .padding-left-2 {
  428. // padding-left: 2%;
  429. }
  430. .margin-right-10 {
  431. margin-right: 10%;
  432. }
  433. .border-line-box {
  434. width: 100%;
  435. height: 20rpx;
  436. background: #f7f7f7;
  437. }
  438. .picker-box{
  439. display: flex;
  440. align-items: center;
  441. justify-content: space-between;
  442. height: 60rpx;
  443. line-height: 60rpx;
  444. background: #f7f7f7;
  445. height: 88rpx;
  446. line-height: 88rpx;
  447. background: #f7f7f7;
  448. font-size: 28rpx;
  449. padding-left: 4%;
  450. }
  451. .uni-input image {
  452. width: 40rpx;
  453. height: 40rpx;
  454. margin-right: 2%;
  455. float: right;
  456. }
  457. .textarea-box {
  458. background: #f7f7f7;
  459. min-height: 120rpx;
  460. font-size: 28rpx;
  461. margin: 5% auto;
  462. padding: 4%;
  463. margin-bottom: 8%;
  464. }
  465. .upload-box {
  466. display: flex;
  467. flex-flow: column;
  468. width: 22%;
  469. height: 100rpx;
  470. border-radius: 10rpx;
  471. padding-top: 15rpx;
  472. }
  473. image {
  474. width: 100rpx;
  475. height:100rpx;
  476. }
  477. .upload-box-photo {
  478. width: 25%;
  479. height: 100rpx;
  480. border-radius: 10rpx;
  481. padding-top: 15rpx;
  482. position: relative;
  483. margin-left: 20rpx;
  484. margin-right: 20rpx;
  485. }
  486. .del-icon {
  487. position: absolute;
  488. right: -15rpx;
  489. width: 30rpx;
  490. height: 30rpx;
  491. }
  492. .update_button {
  493. text-align: center;
  494. display: flex;
  495. flex-wrap: wrap;
  496. }
  497. .picker-class {
  498. border-radius: 10rpx;
  499. padding: 10rpx;
  500. width: 73%;
  501. font-size: 28rpx;
  502. background: #f5f5f5;
  503. }
  504. .picker-class image {
  505. width: 26rpx;
  506. height: 26rpx;
  507. }
  508. .submit-bth {
  509. width: 25%;
  510. font-size: 26rpx;
  511. margin: 0 0 5% 0;
  512. color: #fff;
  513. }
  514. .select-member {
  515. input {
  516. margin: 2% 2% 2% 0;
  517. height: 80rpx;
  518. line-height: 80rpx;
  519. }
  520. button {
  521. background-color: #169bd5;
  522. margin: 0;
  523. height: 60rpx;
  524. line-height: 60rpx;
  525. width: 20%;
  526. }
  527. }
  528. .check-class {
  529. margin-right:10rpx;
  530. transform:scale(.8);
  531. width: 48%;
  532. margin-top: 2%;
  533. }
  534. .step-box {
  535. display: flex;
  536. justify-content: space-evenly;
  537. align-items: center;
  538. width: 90%;
  539. margin: 5% 0 5% 0;
  540. }
  541. .step-1 {
  542. width: 60rpx;
  543. height: 60rpx;
  544. border-radius: 50%;
  545. background-color:#aaaaaa;
  546. text-align: center;
  547. line-height: 60rpx;
  548. color: #fff;
  549. }
  550. .footer-box {
  551. margin-top: 5%;
  552. width: 90%;
  553. display: flex;
  554. justify-content: space-evenly;
  555. }
  556. .textarea-box {
  557. background: #f7f7f7;
  558. min-height: 120rpx;
  559. font-size: 28rpx;
  560. margin: 3% auto;
  561. padding: 4%;
  562. }
  563. .img-container{
  564. width: 90%;
  565. font-size: 26rpx;
  566. .note-image-box{
  567. margin-top: 5px;
  568. display: flex;
  569. flex-wrap: wrap;
  570. padding: 10px;
  571. .note-image-item{
  572. position: relative;
  573. //这两个百分比很关键
  574. width: 33.33%;
  575. height: 0;
  576. padding-top: 33.33%;
  577. box-sizing: border-box;
  578. .close-icon{
  579. display: flex;
  580. justify-content: center;
  581. align-items: center;
  582. position: absolute;
  583. right: 0;
  584. top: 0;
  585. width: 22px;
  586. height: 22px;
  587. border-radius: 50%;
  588. background-color: #d5d5d5;
  589. z-index: 2;
  590. }
  591. .image-box{
  592. display: flex;
  593. justify-content: center;
  594. align-items: center;
  595. position: absolute;
  596. top: 5px;
  597. right: 5px;
  598. bottom: 5px;
  599. left: 5px;
  600. border: 1px #eee solid;
  601. border-radius: 5px;
  602. overflow: hidden;
  603. image{
  604. width: 100%;
  605. height: 100%;
  606. }
  607. }
  608. }
  609. }
  610. }
  611. .file-font-box {
  612. margin-top: 10rpx;
  613. width: 60%;
  614. white-space: nowrap;
  615. overflow: hidden;
  616. text-overflow: ellipsis;
  617. font-size: 24rpx;
  618. }
  619. </style>