share-model.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. <template>
  2. <view class="content">
  3. <view class="tile">{{pageData.title}}</view>
  4. <view class="hflex acenter " style="box-sizing: border-box;padding: 0 30rpx;">
  5. <view class="img_box">
  6. <image :src="pageData.src" mode="aspectFill" class="img"></image>
  7. <view class="type">V</view>
  8. </view>
  9. <view class="text_style1">{{pageData.name}}</view>
  10. </view>
  11. <u-parse :content="pageData.content" style="box-sizing: border-box;padding: 0 30rpx;"></u-parse>
  12. <view class="box hflex acenter jbetween">
  13. <view class="hflex acenter ">
  14. <image class="box_icon" src="https://ship-expert.zhousi.hdlkeji.com/common/icon_pdf.png"></image>
  15. <view class="text_style1">{{pageData.fujian}}</view>
  16. </view>
  17. <view class="down hflex acenter jcenter">
  18. <u-icon name="download" color="#FFFFFF" size="20"></u-icon>
  19. </view>
  20. </view>
  21. <view class="date">发布于{{pageData.date}}</view>
  22. <view class="bottom hflex acenter jbetween">
  23. <view class="hflex acenter" @click="collect">
  24. <u-icon name="star" color="#444444" size="20" v-if="pageData.is_collect == 0"></u-icon>
  25. <u-icon name="star-fill" color="#506DFF" size="20" v-else></u-icon>
  26. <view class="text_style1">收藏</view>
  27. </view>
  28. <view class="btn" @click="share">分享</view>
  29. </view>
  30. <view class="share_content" v-if="share_show">
  31. <my-canvas :isDraw="true" :canvasData="canvasData" :imageSize="{width: 375, height: 667}" @generateImageSuccessful="generateImageSuccessful"></my-canvas>
  32. <view class="share_bottom">
  33. <view class="hflex acenter jbetween">
  34. <button class="vflex acenter jcenter bottom_item" open-type="share">
  35. <image src="https://ship-expert.zhousi.hdlkeji.com/common/wx.png" class="item_icon"></image>
  36. <view class="item_text">微信好友</view>
  37. </button>
  38. <!-- <button class="vflex acenter jcenter bottom_item" open-type="share">
  39. <image src="https://ship-expert.zhousi.hdlkeji.com/common/moments.png" class="item_icon"></image>
  40. <view class="item_text">朋友圈</view>
  41. </button> -->
  42. <view class="vflex acenter jcenter bottom_item" @click="saveImg">
  43. <image src="https://ship-expert.zhousi.hdlkeji.com/common/download.png" class="item_icon"></image>
  44. <view class="item_text">保存图片</view>
  45. </view>
  46. </view>
  47. <view class="share_cancel" @click="cancel">取消</view>
  48. </view>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import $api from '@/static/js/api.js'
  54. var that = ''
  55. export default {
  56. data() {
  57. return {
  58. pageData: {
  59. title: '在高质量发展中扎实推动共同富裕!',
  60. src: 'https://ship-expert.zhousi.hdlkeji.com/common/avatar1.jpg',
  61. name: '船百知官方账号',
  62. is_collect: 0,
  63. content: `洗脸,是我们日常生活中每天都要进行的活动。俗话说得好:勤梳头,\n勤洗脸,有点儿倒霉也不显。光洁的脸庞不仅透露出积极向上的精神\n面貌。也是外在美最直接的表现形式。网络疯传的洗脸教育帖转发率\n之高,书店里出售的洗脸书销量之大,都反映出人们对于洗脸的重`,
  64. date: '2021年09月05日',
  65. fujian: '在发展中扎实推动共同富裕.pdf',
  66. code: '',
  67. },
  68. share_show: false,
  69. canvasData: [
  70. ],
  71. tempImage: "",
  72. }
  73. },
  74. onLoad() {
  75. that = this
  76. that.canvasData = [
  77. {
  78. type: 'rect',
  79. attr: {
  80. color: '#fff',
  81. x: 0,
  82. y: 0,
  83. width: 325,
  84. height: 384,
  85. radian_1: 10,
  86. }
  87. },
  88. {
  89. type: 'text',
  90. attr: {
  91. text: that.pageData.title,
  92. x: 10,
  93. y: 15,
  94. color: '#222',
  95. size: 9,
  96. weight: '500',
  97. writingMode: 'initial' ,
  98. }
  99. },
  100. {
  101. type: 'image',
  102. attr: {
  103. image: that.pageData.src,
  104. x: 10,
  105. y: 20,
  106. width: 14,
  107. height: 14,
  108. radian_1: 7,
  109. radian_2: 7,
  110. radian_3: 7,
  111. radian_4: 7
  112. }
  113. },
  114. {
  115. type: 'text',
  116. attr: {
  117. text: that.pageData.name,
  118. x: 30,
  119. y: 28,
  120. color: '#444',
  121. size: 8,
  122. weight: '400',
  123. writingMode: 'initial' ,
  124. }
  125. },
  126. {
  127. type: 'text',
  128. attr: {
  129. text: that.pageData.content,
  130. x: 10,
  131. y: 45,
  132. color: '#444',
  133. size: 7,
  134. weight: '400',
  135. writingMode: 'initial' ,
  136. }
  137. },
  138. {
  139. type: 'text',
  140. attr: {
  141. text: '扫码查看更多',
  142. color: '#444',
  143. size: 5,
  144. x: 65,
  145. y: 105,
  146. weight: '400',
  147. writingMode: 'initial' ,
  148. }
  149. },
  150. {
  151. type: 'line',
  152. attr: {
  153. color: '#C3C3C3',
  154. x: 20,
  155. y: 115,
  156. width: 1,
  157. height: 120
  158. }
  159. },
  160. {
  161. type: 'text',
  162. attr: {
  163. text: '船百知',
  164. color: '#222222',
  165. size: 8,
  166. x: 10,
  167. y: 130,
  168. weight: '400',
  169. writingMode: 'initial' ,
  170. }
  171. },
  172. {
  173. type: 'text',
  174. attr: {
  175. text: '船百知伴您一起扬帆起航,驶向成功彼岸。',
  176. color: '#999999',
  177. size: 5,
  178. x: 10,
  179. y: 140,
  180. weight: '400',
  181. writingMode: 'initial' ,
  182. }
  183. },
  184. {
  185. type: 'image',
  186. attr: {
  187. image: that.pageData.src,
  188. x: 110,
  189. y: 120,
  190. width: 34,
  191. height: 34,
  192. }
  193. },
  194. ]
  195. },
  196. onShareAppMessage(res) {
  197. console.log(res);
  198. if (res.from === 'button') {// 来自页面内分享按钮
  199. console.log(res.target)
  200. }
  201. return {
  202. title: '船百知', //分享的名称
  203. }
  204. },
  205. onShareTimeline(res) {
  206. console.log(res);
  207. return {
  208. title: '船百知',
  209. type: 0,
  210. summary: "",
  211. }
  212. },
  213. methods: {
  214. // 收藏
  215. collect() {
  216. if(that.pageData.is_collect == 0) {
  217. that.pageData.is_collect = 1
  218. $api.info('收藏成功')
  219. } else {
  220. that.pageData.is_collect = 0
  221. $api.info('取消收藏')
  222. }
  223. },
  224. // 分享
  225. share() {
  226. that.share_show = true
  227. const ctx = uni.createCanvasContext('myCanvas')
  228. ctx.draw()
  229. },
  230. generateImageSuccessful(image) {
  231. console.log(image);
  232. this.tempImage = image;
  233. },
  234. saveImg() {
  235. uni.authorize({
  236. scope: 'scope.writePhotosAlbum',
  237. success() {
  238. uni.saveImageToPhotosAlbum({
  239. filePath: that.tempImage,
  240. success: function () {
  241. console.log('save success');
  242. $api.info('保存成功')
  243. that.cancel()
  244. }
  245. });
  246. }
  247. })
  248. },
  249. // 取消
  250. cancel() {
  251. that.share_show = false
  252. },
  253. },
  254. }
  255. </script>
  256. <style lang="scss" scoped>
  257. .content::v-deep {
  258. position: relative;
  259. .tile {
  260. box-sizing: border-box;
  261. padding: 24rpx 30rpx;
  262. font-size: 40rpx;
  263. font-weight: 500;
  264. color: #333333;
  265. line-height: 56rpx;
  266. }
  267. .img_box {
  268. width: 56rpx;
  269. height: 56rpx;
  270. position: relative;
  271. .img {
  272. width: 56rpx;
  273. height: 56rpx;
  274. border-radius: 50%;
  275. }
  276. .type {
  277. position: absolute;
  278. right: 0rpx;
  279. bottom: 0rpx;
  280. width: 28rpx;
  281. height: 28rpx;
  282. background: #506DFF;
  283. border-radius: 12rpx 4rpx 12rpx 4rpx;
  284. font-size: 20rpx;
  285. color: #fff;
  286. text-align: center;
  287. line-height: 28rpx;
  288. }
  289. }
  290. .text_style1 {
  291. margin-left: 16rpx;
  292. font-size: 26rpx;
  293. font-weight: 400;
  294. color: #222222;
  295. line-height: 36rpx;
  296. }
  297. .box {
  298. margin: 24rpx 30rpx;
  299. height: 116rpx;
  300. background: #F4F4F4;
  301. border-radius: 16rpx;
  302. box-sizing: border-box;
  303. padding: 24rpx 28rpx;
  304. .box_icon {
  305. width: 56rpx;
  306. height: 68rpx;
  307. }
  308. .down {
  309. width: 48rpx;
  310. height: 48rpx;
  311. border-radius: 50%;
  312. background: #506DFF;
  313. }
  314. }
  315. .date {
  316. margin-bottom: 186rpx;
  317. box-sizing: border-box;
  318. padding: 0 30rpx;
  319. font-size: 26rpx;
  320. font-weight: 400;
  321. color: #989898;
  322. line-height: 18px;
  323. }
  324. .bottom {
  325. width: 100%;
  326. z-index: 9;
  327. position: fixed;
  328. bottom: 0;
  329. height: 166rpx;
  330. background: #FFFFFF;
  331. box-sizing: border-box;
  332. padding: 8rpx 30rpx 74rpx;
  333. .btn {
  334. width: 510rpx;
  335. height: 80rpx;
  336. background: #506DFF;
  337. border-radius: 42rpx;
  338. font-size: 32rpx;
  339. font-weight: 500;
  340. color: #FFFFFF;
  341. line-height: 80rpx;
  342. text-align: center;
  343. }
  344. }
  345. .cCanvas {
  346. position: absolute;
  347. top: 188rpx;
  348. left: 50rpx;
  349. background-color: #fff;
  350. z-index: 100;
  351. border-radius: 20rpx;
  352. }
  353. .share_content {
  354. position: absolute;
  355. top: 0;
  356. left: 0;
  357. z-index: 99;
  358. width: 100vw;
  359. height: 100vh;
  360. background: rgba(0,0,0,0.5);
  361. backdrop-filter: blur(5px);
  362. .share_box {
  363. margin: 148rpx auto;
  364. width: 650rpx;
  365. background: #FFFFFF;
  366. border-radius: 20rpx;
  367. box-sizing: border-box;
  368. padding: 0 40rpx;
  369. .box_bottom {
  370. width: 100%;
  371. padding: 34rpx 0 16rpx;
  372. border-top: 1rpx dashed #C3C3C3;
  373. .bottom_left1 {
  374. font-size: 32rpx;
  375. font-weight: 500;
  376. color: #222222;
  377. line-height: 44rpx;
  378. padding-bottom: 20rpx;
  379. }
  380. .bottom_left2 {
  381. font-size: 22rpx;
  382. font-weight: 400;
  383. color: #999999;
  384. line-height: 32rpx;
  385. }
  386. .bottom_right {
  387. width: 136rpx;
  388. height: 136rpx;
  389. }
  390. }
  391. }
  392. .canvas {
  393. position: absolute;
  394. top: 188rpx;
  395. left: 50rpx;
  396. width: 650rpx;
  397. min-height: 494rpx;
  398. background: #FFFFFF;
  399. border-radius: 20rpx;
  400. }
  401. .share_bottom {
  402. position: fixed;
  403. bottom: 0;
  404. width: 100%;
  405. height: 388rpx;
  406. background: #F5F7FF;
  407. border-radius: 40rpx 40rpx 0px 0px;
  408. .bottom_item {
  409. width: 33%;
  410. margin: 50rpx 0 90rpx;
  411. border: none !important;
  412. background-color: #F5F7FF !important;
  413. .item_icon {
  414. width: 76rpx;
  415. height: 76rpx;
  416. }
  417. .item_text {
  418. font-size: 26rpx;
  419. font-weight: 400;
  420. color: #333333;
  421. line-height: 36rpx;
  422. margin-top: 12rpx;
  423. }
  424. }
  425. button::after {
  426. border: none !important;
  427. }
  428. .share_cancel {
  429. width: 100%;
  430. text-align: center;
  431. font-size: 32rpx;
  432. font-weight: 400;
  433. color: #333333;
  434. line-height: 44rpx;
  435. }
  436. }
  437. }
  438. }
  439. </style>