album.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <template>
  2. <view class="container">
  3. <view id="topnav" class="topnav flex-start" :style="{'height':`${topbarOffsetHeight-statusBarHeight}px`,'padding-top':`${statusBarHeight}px`,'background-color':`rgba(21, 17, 38,${topNavAlpha})`}" v-if="!cover.isFullScreen">
  4. <view class="nav-item flex-center" @click="back">
  5. <image :src="`${assetsUrl}back.png`" mode="widthFix" class="nav-img"></image>
  6. </view>
  7. <view class="nav-text font32 fw600">
  8. {{pageName}}
  9. </view>
  10. <view class="nav-item"></view>
  11. </view>
  12. <uni-popup ref="modalPopup" type="center">
  13. <Popup :content1="popup.content1" :content2="popup.content2" :tip1="popup.tip1" :tip2="popup.tip2" :btntext="popup.btntext" @closePopup="closePopup" @toService="toService" :btnEvent="'toService'"></Popup>
  14. </uni-popup>
  15. <uni-popup ref="popup" type="bottom" @maskClick="popupMaskClick" :safe-area="false">
  16. <view class="popup" @touchmove.prevent>
  17. <view class="p-title-box flex-between">
  18. <view class="p-title font36 fw600">
  19. 上传相册
  20. </view>
  21. <image :src="`${assetsUrl}info-figure-close.png`" mode="aspectFill" class="p-close" @click="closePopup"></image>
  22. </view>
  23. <view class="p-title-tip font28 fw400">
  24. 上传清晰本人照片更容易交到好友哦
  25. </view>
  26. <view class="p-img-box flex-between">
  27. <view class="p-img">
  28. <image :src="`${assetsUrl}info-figure-img1.png`" mode="aspectFill" class="img"></image>
  29. <view class="p-text font22 fw400">
  30. 五官清晰
  31. </view>
  32. </view>
  33. <view class="p-img">
  34. <image :src="`${assetsUrl}info-figure-img2.png`" mode="aspectFill" class="img"></image>
  35. <view class="p-text font22 fw400">
  36. 半身照
  37. </view>
  38. </view>
  39. <view class="p-img">
  40. <image :src="`${assetsUrl}info-figure-img3.png`" mode="aspectFill" class="img"></image>
  41. <view class="p-text font22 fw400">
  42. 风景和人
  43. </view>
  44. </view>
  45. </view>
  46. <view style="height: 60rpx;">
  47. </view>
  48. </view>
  49. </uni-popup>
  50. <uni-popup ref="authPopup" type="bottom" @maskClick="authPopupMaskClick">
  51. <view class="auth-popup" @touchmove.prevent>
  52. <view class="ap-title">
  53. 请上传本人正面清晰照片
  54. </view>
  55. <view class="ap-imgs flex-start">
  56. <view class="ap-img-box">
  57. <image :src="`${assetsUrl}auth-ap1.png`" mode="aspectFill" class="ap-img"></image>
  58. <view class="ap-alpha flex-center">
  59. <image :src="`${assetsUrl}auth-right.png`" mode="aspectFill" class="ap-right"></image>
  60. <view class="ap-text font30 fw400">
  61. 清晰正脸
  62. </view>
  63. </view>
  64. </view>
  65. <view class="ap-img-box">
  66. <image :src="`${assetsUrl}auth-ap2.png`" mode="aspectFill" class="ap-img"></image>
  67. <view class="ap-alpha flex-center">
  68. <image :src="`${assetsUrl}auth-right.png`" mode="aspectFill" class="ap-right"></image>
  69. <view class="ap-text font30 fw400">
  70. 全身/半身
  71. </view>
  72. </view>
  73. </view>
  74. <view class="ap-img-box">
  75. <image :src="`${assetsUrl}auth-ap3.png`" mode="aspectFill" class="ap-img"></image>
  76. <view class="ap-alpha flex-center">
  77. <image :src="`${assetsUrl}auth-right.png`" mode="aspectFill" class="ap-right"></image>
  78. <view class="ap-text font30 fw400">
  79. 记得微笑
  80. </view>
  81. </view>
  82. </view>
  83. <view class="ap-img-box">
  84. <image :src="`${assetsUrl}auth-ap4.png`" mode="aspectFill" class="ap-img"></image>
  85. <view class="ap-alpha flex-center">
  86. <image :src="`${assetsUrl}auth-right.png`" mode="aspectFill" class="ap-right"></image>
  87. <view class="ap-text font30 fw400">
  88. 光线合适
  89. </view>
  90. </view>
  91. </view>
  92. </view>
  93. <view style="height: 60rpx;">
  94. </view>
  95. </view>
  96. </uni-popup>
  97. <scroll-view
  98. scroll-y="true"
  99. :style="{'height': `${scrollHeight}px`,'padding-top':`${topNavHeight}px`}"
  100. v-if="scrollHeight>0"
  101. lower-threshold="200"
  102. refresher-enabled="true"
  103. :refresher-triggered="scrollTriggered"
  104. :refresher-threshold="45"
  105. refresher-default-style="white"
  106. refresher-background="#151126"
  107. @refresherrefresh="scrollRefresh"
  108. @refresherpulling="scrollPulling"
  109. @refresherrestore="scrollRestore"
  110. @refresherabort="scrollAbort"
  111. @scrolltolower="scrollToBottom"
  112. class="scroll-view"
  113. >
  114. <drag-image :list="albumData" :number="1000" :custom="true" @addImage="toAddImg" @sortImage="sortImg" @delImage="deleteImg" :chooseImage="isChooseImage" @chooseEvent="chooseImageHandle"></drag-image>
  115. </scroll-view>
  116. <view class="btn-tip font24 fw400" v-if="!isChooseImage">
  117. 长按可拖动调整图片顺序
  118. </view>
  119. <view class="btn font32 fw600" @click="sure">
  120. {{btnText}}
  121. </view>
  122. </view>
  123. </template>
  124. <script>
  125. import TabBar from '@/components/TabBar/TabBar.vue';
  126. import Popup from '@/components/Popup/Popup.vue';
  127. import wxMap from '@/static/qqmap-wx-jssdk1.2/qqmap-wx-jssdk.min.js';
  128. import DragImage from '@/components/DragImage/DragImage.vue';
  129. import {getPolicy,computeSignature,getKey} from '@/util/oss.js';
  130. import {encode} from '@/util/base64.js'
  131. /**
  132. * 腾讯位置服务,手机账号:18996226740
  133. */
  134. const wxMapSdk=new wxMap({key:'E5SBZ-T2YC3-CBL3F-YGFQQ-26PP2-ERFII'})
  135. export default {
  136. components:{TabBar,Popup,DragImage},
  137. data() {
  138. return {
  139. btnText:'去认证',
  140. pageName:'编辑相册',
  141. isChooseImage:false,//是否为选择图片模式
  142. assetsUrl:this.$util.assetsUrl,
  143. scrollHeight:0,
  144. topNavHeight:0,
  145. scrollRefreshing:false,
  146. scrollTriggered:true,
  147. showNoData:false,
  148. albumData:[],
  149. authChooseImages:[],
  150. moveItemAlbum:{},
  151. moveItemIndex:null,
  152. currentIndex:0,
  153. isSort:false,
  154. popup:{
  155. content1:'',
  156. content2:'',
  157. tip1:'',
  158. tip2:'',
  159. btntext:''
  160. },
  161. };
  162. },
  163. computed: {
  164. statusBarHeight() {
  165. return this.$store.state.statusBarHeight;
  166. },
  167. topbarOffsetHeight() {
  168. return this.$store.state.topbarOffsetHeight;
  169. },
  170. imageCdn(){
  171. return this.$store.state.imageCdn;
  172. },
  173. videoCdn(){
  174. return this.$store.state.videoCdn;
  175. }
  176. },
  177. onLoad(options) {
  178. if(options.type==='auth'){
  179. this.isChooseImage=true;
  180. this.btnText='前往认证';
  181. this.pageName='选择照片';
  182. }else{
  183. this.isChooseImage=false;
  184. }
  185. this.computedScollviewHeight()
  186. this.getAlbumData();
  187. },
  188. mounted() {
  189. },
  190. onPageScroll(e) {
  191. },
  192. methods:{
  193. back(){
  194. uni.navigateBack({
  195. delta:1
  196. })
  197. },
  198. chooseImageHandle(data){
  199. this.authChooseImages=data;
  200. },
  201. toAddImg(){
  202. this.btnText='从相册上传';
  203. if(this.isChooseImage){
  204. this.$refs.authPopup.open();
  205. }
  206. else{
  207. this.$refs.popup.open();
  208. }
  209. },
  210. popupMaskClick(){
  211. this.btnText=this.isChooseImage?'前往认证':'去认证';
  212. },
  213. authPopupMaskClick(){
  214. this.btnText=this.isChooseImage?'前往认证':'去认证';
  215. },
  216. closePopup(){
  217. this.$refs.popup.close();
  218. this.$refs.modalPopup.close();
  219. this.$refs.authPopup.close();
  220. this.btnText=this.isChooseImage?'前往认证':'去认证';
  221. },
  222. sortImg(ids){
  223. let user=JSON.parse(uni.getStorageSync('user'));
  224. this.$api.public.albumSort({
  225. completeUser:user,
  226. mediaIdsInSeq:ids
  227. }).then(res=>{})
  228. },
  229. toService(){
  230. this.$refs.popup.close();
  231. uni.openCustomerServiceChat({
  232. extInfo:{
  233. url:'https://work.weixin.qq.com/kfid/kfca1b21d2f7e8a18e9',//客服链接
  234. },
  235. corpId:'wwa8f2a0d8a6dc0950',//企业ID
  236. fail(res){
  237. console.log(res)
  238. wx.showToast({
  239. title: '客服联系失败',
  240. icon:'none'
  241. })
  242. }
  243. })
  244. },
  245. /**
  246. * 计算scroll高度
  247. */
  248. computedScollviewHeight() {
  249. let query = uni.createSelectorQuery().in(this);
  250. let heightLeaf =0;
  251. query.select('#topnav').boundingClientRect(data => {
  252. this.topNavHeight=data.height;
  253. heightLeaf += data.height;
  254. }).exec(() => {
  255. let sysInfo = uni.getSystemInfoSync();
  256. this.scrollHeight = sysInfo.windowHeight - heightLeaf;
  257. });
  258. },
  259. /**
  260. * 推荐下拉刷新、加载更多
  261. */
  262. scrollRefresh(){
  263. if (this.scrollRefreshing)
  264. {
  265. return;
  266. }
  267. this.scrollRefreshing = true;
  268. setTimeout(() => {
  269. this.scrollTriggered = false;
  270. this.scrollRefreshing = false;
  271. }, 1000)
  272. this.getAlbumData();
  273. },
  274. scrollPulling(e) {},
  275. scrollRestore() {this.scrollTriggered = true;},
  276. scrollAbort() {},
  277. scrollToBottom(){
  278. },
  279. getAlbumData(){
  280. let user=JSON.parse(uni.getStorageSync('user'));
  281. this.$api.public.album({uurd:user.id}).then(res=>{
  282. for(let i=0;i<res.data.dms.length;i++){
  283. res.data.dms[i].isMove=false;
  284. }
  285. let arr=[];
  286. if(this.isChooseImage){
  287. for(let i=0;i<res.data.dms.length;i++){
  288. if(res.data.dms[i].cate==='Img'){
  289. arr.push(res.data.dms[i])
  290. }
  291. }
  292. this.albumData=arr;
  293. }
  294. else{
  295. this.albumData=res.data.dms;
  296. }
  297. })
  298. },
  299. deleteImg(index){
  300. this.$api.public.albumDelete({mediaId:this.albumData[index].mediaId}).then(res=>{})
  301. },
  302. sure(){
  303. if(this.btnText==='从相册上传'){
  304. this.addImg();
  305. }
  306. else{
  307. this.popup={
  308. content1:'进行认证流程需给客服回复关键词',
  309. content2:'「真人认证」',
  310. tip1:'',
  311. tip2:'',
  312. btntext:'联系客服去认证'
  313. }
  314. this.$refs.modalPopup.open();
  315. }
  316. },
  317. async addImg(){
  318. const that=this;
  319. this.closePopup();
  320. uni.chooseMedia({
  321. count: 9,
  322. mediaType: this.isChooseImage?['image']:['image','video'],
  323. sourceType: ['album', 'camera'],
  324. maxDuration: 30,
  325. camera: 'back',
  326. success(res) {
  327. uni.showLoading({
  328. mask:true,
  329. title:"正在上传···"
  330. })
  331. let arr=[],obj={},imageCdn='',videoCdn='';
  332. for(let i=0;i<res.tempFiles.length;i++){
  333. obj={
  334. cate:res.tempFiles[i].fileType==='image'?'Img':'Vdo',
  335. cdt:'General',
  336. env:'Album',
  337. url:null
  338. }
  339. const policyText=getPolicy();
  340. const policy=encode(JSON.stringify(policyText));
  341. const key=getKey(i,res.tempFiles[i].tempFilePath.split('.')[1]);
  342. that.$api.public.aliossToken({}).then(resuslt=>{
  343. let formData={
  344. key:key,
  345. policy:policy,
  346. OSSAccessKeyId:resuslt.data.accessKeyId,
  347. signature:computeSignature(resuslt.data.accessKeySecret,policy),
  348. 'x-oss-security-token':resuslt.data.securityToken,
  349. success_action_status:'200'
  350. }
  351. uni.uploadFile({
  352. url: 'https://zhenyanapp-gen.oss-cn-qingdao.aliyuncs.com',
  353. filePath: res.tempFiles[i].tempFilePath,
  354. name: 'file',
  355. header:{
  356. "Content-Type": "multipart/form-data"
  357. },
  358. formData: formData,
  359. success: (data) => {
  360. if (data.statusCode === 200) {
  361. if(obj.cate==='Img'){
  362. let link=`${that.imageCdn}/${key}`;
  363. obj.url=link;
  364. }
  365. else if(obj.cate==='Vdo'){
  366. let link=`${that.videoCdn}/${key}`;
  367. obj.url=link;
  368. }
  369. arr.push(obj);
  370. if(arr.length===res.tempFiles.length){
  371. that.$api.public.albumAdd({addMediaParamList:arr}).then(mapResult=>{
  372. if(mapResult.status==='Succ'){
  373. that.getAlbumData();
  374. uni.hideLoading();
  375. }
  376. })
  377. }
  378. }
  379. },
  380. fail: err => {
  381. console.log(err);
  382. }
  383. })
  384. })
  385. }
  386. }
  387. })
  388. },
  389. }
  390. }
  391. </script>
  392. <style lang="scss" scoped>
  393. .container{
  394. width: 100vw;
  395. height: 100vh;
  396. background-color: $bgcolor1;
  397. position: relative;
  398. .topnav {
  399. padding: 0 10rpx;
  400. position: fixed;
  401. top: 0;
  402. left: 0;
  403. width: 100vw;
  404. z-index: 100;
  405. backdrop-filter: blur(10px);
  406. .nav-item {
  407. width: 40rpx;
  408. height: 40rpx;
  409. margin-left: 16rpx;
  410. .nav-img{
  411. width: 40rpx;
  412. height: 40rpx;
  413. }
  414. }
  415. .nav-text{
  416. flex: 1;
  417. color: $fontcolor5;
  418. height: 40rpx;
  419. text-align: center;
  420. }
  421. }
  422. .popup{
  423. width: 100vw;
  424. box-sizing: border-box;
  425. padding: 56rpx 60rpx;
  426. background-color: $bgcolor3;
  427. .p-title-box{
  428. .p-title{
  429. color: $fontcolor5;
  430. }
  431. .p-close{
  432. width: 40rpx;
  433. height: 40rpx;
  434. }
  435. }
  436. .p-title-tip{
  437. color: $fontcolor3;
  438. margin-top: 16rpx;
  439. }
  440. .p-img-box{
  441. margin-top: 80rpx;
  442. padding-bottom: 100rpx;
  443. .p-img{
  444. .img{
  445. width: 200rpx;
  446. height: 200rpx;
  447. }
  448. .p-text{
  449. color: $fontcolor2;
  450. text-align: center;
  451. }
  452. }
  453. }
  454. }
  455. .auth-popup{
  456. background-color: bgcolor1;
  457. border-radius: 40rpx 40rpx 0rpx 0rpx;
  458. .ap-title{
  459. color: #ffffff;
  460. text-align: center;
  461. }
  462. .ap-imgs{
  463. flex-wrap: wrap;
  464. margin: 80rpx 64rpx 50rpx 64rpx;
  465. .ap-img-box{
  466. width: 306rpx;
  467. height: 306rpx;
  468. border-radius: 8rpx;
  469. overflow: hidden;
  470. margin-right: 10rpx;
  471. margin-bottom: 10rpx;
  472. position: relative;
  473. &:nth-of-type(2n){
  474. margin-right: 0rpx;
  475. }
  476. .ap-img{
  477. width: 306rpx;
  478. height: 306rpx;
  479. }
  480. .ap-alpha{
  481. position: absolute;
  482. width: 306rpx;
  483. height: 80rpx;
  484. bottom: 0;
  485. left: 0;
  486. background: rgba(0,0,0,0.3);
  487. .ap-right{
  488. width: 48rpx;
  489. height: 48rpx;
  490. }
  491. .ap-text{
  492. color: #ffffff;
  493. }
  494. }
  495. }
  496. }
  497. }
  498. .scroll-view{
  499. position: relative;
  500. padding: 0rpx 30rpx;
  501. box-sizing: border-box;
  502. .move-area{
  503. position: absolute;
  504. left: 0;
  505. top: 0;
  506. width: 100%;
  507. flex-wrap: wrap;
  508. align-items: flex-start !important;
  509. .img-box{
  510. width: 216rpx;
  511. height: 216rpx;
  512. border-radius: 8rpx;
  513. position: relative;
  514. z-index: 1;
  515. margin-right: 19rpx;
  516. margin-top: 20rpx;
  517. &:nth-of-type(3n){
  518. margin-right: 0rpx;
  519. }
  520. .img-add{
  521. width: 216rpx;
  522. height: 216rpx;
  523. border-radius: 8rpx;
  524. }
  525. .img-delete{
  526. position: absolute;
  527. right: 16rpx;
  528. top: 16rpx;
  529. width: 40rpx;
  530. height: 40rpx;
  531. }
  532. }
  533. }
  534. }
  535. .btn-tip{
  536. position: fixed;
  537. z-index: 1;
  538. left: 0;
  539. right: 0;
  540. bottom: 160rpx;
  541. margin: auto;
  542. width: 630rpx;
  543. height: 50rpx;
  544. color: #9A9ABF;
  545. text-align: center;
  546. line-height: 50rpx;
  547. }
  548. .btn{
  549. position: fixed;
  550. z-index: 999;
  551. left: 0;
  552. right: 0;
  553. bottom: 44rpx;
  554. margin: auto;
  555. width: 630rpx;
  556. height: 104rpx;
  557. border-radius: 52rpx;
  558. background-color: $primary;
  559. color: $fontcolor5;
  560. text-align: center;
  561. line-height: 104rpx;
  562. }
  563. }
  564. </style>