files.vue 14 KB

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