wzshare.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <view class="content">
  3. <view class="box">
  4. <view class="title flex">
  5. <view class="title-font">分享文案</view>
  6. <view class="title-btn" @click="comfirm()">复制文案</view>
  7. </view>
  8. <view class="box-info">
  9. <view class="info-title">{{ info.title }}</view>
  10. <view class="info-tip">{{ info.synopsis }}</view>
  11. <view class="info-url">{{ url }}</view>
  12. </view>
  13. <view class="title flex" style="margin-top: 20rpx;">
  14. <view class="title-font">
  15. 分享素材
  16. <text>(已选{{ nowlen }}/{{ alllen }})</text>
  17. </view>
  18. </view>
  19. <view class="image-box">
  20. <view class="image-item" v-for="(item, index) in imageBox" @click="change(item)">
  21. <image :src="item.url" mode=""></image>
  22. <view class="isxuan" v-if="item.isxuan"></view>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="btn" @click="onDown()">下载</view>
  27. </view>
  28. </template>
  29. <script>
  30. import { details } from '@/api/user.js';
  31. import sunuiGrand from '@/components/sunui-grand/sunui-grand.vue';
  32. import { reply_detail, short_link } from '@/api/activity.js';
  33. import uniCopy from '@/js_sdk/xb-copy/uni-copy.js';
  34. export default {
  35. data() {
  36. return {
  37. info: {},
  38. url: '',
  39. imageBox: [],
  40. alllen: '',
  41. nowlen: ''
  42. };
  43. },
  44. components: {
  45. sunuiGrand
  46. },
  47. onLoad(opt) {
  48. this.id = opt.id;
  49. },
  50. onShow() {
  51. this.imageBox = [];
  52. this.loadData();
  53. },
  54. onReachBottom() {},
  55. onReady() {},
  56. methods: {
  57. loadData() {
  58. const obj = this;
  59. details({}, this.id).then(({ data }) => {
  60. data.share_images.forEach(e => {
  61. let u = {
  62. isxuan: true,
  63. url: e
  64. };
  65. obj.imageBox.push(u);
  66. });
  67. this.alllen = obj.imageBox.length;
  68. this.nowlen = obj.imageBox.length;
  69. this.info = data;
  70. });
  71. short_link({ url: 'pages/zc/wzDetail?id=' + this.id }).then(({ data }) => {
  72. this.url = data.link;
  73. });
  74. },
  75. change(opt) {
  76. if (opt.isxuan) {
  77. opt.isxuan = false;
  78. this.nowlen -= 1;
  79. } else {
  80. opt.isxuan = true;
  81. this.nowlen += 1;
  82. }
  83. },
  84. comfirm() {
  85. let text = this.info.synopsis + this.url;
  86. const result = uniCopy(text);
  87. if (result === false) {
  88. uni.showToast({
  89. title: '不支持'
  90. });
  91. } else {
  92. uni.showToast({
  93. title: '复制成功',
  94. icon: 'none'
  95. });
  96. }
  97. },
  98. onDown() {
  99. let that = this;
  100. let index = 0;
  101. let list = [];
  102. that.imageBox.forEach(e => {
  103. if (e.isxuan) {
  104. list.push(e.url);
  105. }
  106. });
  107. // console.log('触发下载图片');
  108. // 第一步,先调用授权功能
  109. uni.authorize({
  110. scope: 'scope.writePhotosAlbum',
  111. success() {
  112. // 1 授权成功遍历所有要下载的图片
  113. if (list && list.length > 0) {
  114. // console.log(that.pathList, '============查看有没有图片数据=============>');
  115. let i = 1;
  116. list.forEach(item => {
  117. uni.showLoading({
  118. title: '下载第' + i + '图片中,共' + list.length + '张'
  119. });
  120. // 1.1 调用下载api方法
  121. uni.downloadFile({
  122. url: item, // 获取要下载的服务器里的图片地址
  123. success: res => {
  124. // 1.2 获取远程图片地址后,将图片地址缓存到本地
  125. if (res.statusCode === 200) {
  126. // console.log(res, '============下载后的图片地址=============>');
  127. uni.saveImageToPhotosAlbum({
  128. filePath: res.tempFilePath, // 把远程的图片地址及图片保存到本地
  129. success: function(res) {
  130. // 1.3保存成功后弹框提示保存成功
  131. i += 1;
  132. uni.showToast({
  133. title: '保存成功',
  134. icon: 'none'
  135. });
  136. },
  137. fail: function(res) {
  138. // console.log(res, '============fail=============>');
  139. // 1.4保存失败给用户弹框提示
  140. uni.showToast({
  141. title: '保存失败',
  142. icon: 'none'
  143. });
  144. if (res.errMsg == 'saveImageToPhotosAlbum:fail cancel') {
  145. return;
  146. }
  147. }
  148. });
  149. }
  150. }
  151. });
  152. });
  153. } else {
  154. uni.showToast({
  155. title: '暂无数据',
  156. icon: 'none'
  157. });
  158. }
  159. },
  160. fail() {
  161. // 2、授权失败 弹框再次要求授权
  162. uni.showModal({
  163. title: '您需要授权相册权限',
  164. success(res) {
  165. // 2.1点击确认按钮就调取授权设置页面
  166. if (res.confirm) {
  167. // 2.2 开启授权设置页面
  168. uni.openSetting({
  169. success(res) {},
  170. fail(res) {}
  171. });
  172. }
  173. }
  174. });
  175. }
  176. });
  177. }
  178. }
  179. };
  180. </script>
  181. <style lang="scss">
  182. page,
  183. .content {
  184. min-height: 100%;
  185. height: auto;
  186. background: #f8f8f8;
  187. }
  188. .box {
  189. width: 730rpx;
  190. margin: 20rpx auto 0;
  191. border-radius: 20rpx;
  192. background: #ffffff;
  193. padding: 20rpx;
  194. .title {
  195. .title-font {
  196. font-size: 32rpx;
  197. font-family: PingFang SC;
  198. font-weight: 800;
  199. color: #303030;
  200. text {
  201. display: inline-block;
  202. margin-left: 10rpx;
  203. color: #999999;
  204. font-size: 28rpx;
  205. font-family: PingFang SC;
  206. font-weight: 500;
  207. }
  208. }
  209. .title-btn {
  210. width: 150rpx;
  211. height: 50rpx;
  212. display: flex;
  213. justify-content: center;
  214. align-items: center;
  215. border: 1px solid #e66f6f;
  216. border-radius: 30rpx;
  217. color: #e66f6f;
  218. }
  219. }
  220. .box-info {
  221. background: #f6f6f6;
  222. width: 700rpx;
  223. padding: 20rpx;
  224. margin: 20rpx auto 0;
  225. .info-title {
  226. font-size: 28rpx;
  227. font-family: PingFang SC;
  228. font-weight: 800;
  229. color: #303030;
  230. }
  231. .info-tip {
  232. font-size: 26rpx;
  233. font-family: PingFang SC;
  234. font-weight: 500;
  235. color: #303030;
  236. }
  237. .info-url {
  238. margin-top: 20rpx;
  239. font-size: 26rpx;
  240. font-family: PingFang SC;
  241. font-weight: 500;
  242. color: #666666;
  243. }
  244. }
  245. .image-box {
  246. margin-top: 20rpx;
  247. display: flex;
  248. align-items: center;
  249. flex-wrap: wrap;
  250. .image-item {
  251. margin: 10rpx;
  252. position: relative;
  253. width: 32%;
  254. height: 300rpx;
  255. .isxuan {
  256. position: absolute;
  257. top: 20rpx;
  258. right: 20rpx;
  259. width: 30rpx;
  260. height: 30rpx;
  261. border-radius: 50%;
  262. background: #e04b4b;
  263. }
  264. image {
  265. width: 100%;
  266. height: 100%;
  267. }
  268. }
  269. }
  270. }
  271. .btn {
  272. margin: 0 auto;
  273. position: fixed;
  274. bottom: 20rpx;
  275. left: 0;
  276. right: 0;
  277. width: 710rpx;
  278. height: 80rpx;
  279. display: flex;
  280. justify-content: center;
  281. align-items: center;
  282. background: #e04b4b;
  283. color: #ffffff;
  284. font-size: 26rpx;
  285. font-family: PingFang SC;
  286. font-weight: 500;
  287. border-radius: 50rpx;
  288. }
  289. </style>