files.vue 13 KB

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