use-poster.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <view>
  3. <u-modal confirmText="关闭" ref="posterModal" :show="show" :title="title" :closeOnClickOverlay="true"
  4. @close="close" @confirm="close">
  5. <view class="slot-content">
  6. <u-poster @success="success" ref="posterRef" :palette="value" :width="width"></u-poster>
  7. <view class="flex1 btn-container dflex-b">
  8. <view class="btn btn-warn" @click.stop="save()">保存相册</view>
  9. <button open-type="share" class="btn btn-base" @click.stop="share()">分享好友</button>
  10. </view>
  11. </view>
  12. </u-modal>
  13. </view>
  14. </template>
  15. <script>
  16. export default {
  17. data() {
  18. return {
  19. show: false,
  20. title: '分享好友',
  21. width: 255,
  22. value: {},
  23. file:'',
  24. }
  25. },
  26. methods: {
  27. close() {
  28. this.show = false;
  29. },
  30. save() {
  31. if (this.Dever.env == 2) {
  32. const link = document.createElement('a')
  33. link.href = this.file
  34. link.download = 'share.png'
  35. link.click()
  36. uni.showToast({
  37. title: '已保存到相册',
  38. icon: 'none'
  39. })
  40. } else if (this.Dever.env == 3) {
  41. uni.showToast({
  42. title: '请长按保存到相册',
  43. icon: 'none'
  44. })
  45. } else {
  46. uni.saveImageToPhotosAlbum({
  47. filePath: this.file,
  48. success: () => {
  49. uni.showToast({
  50. title: '已保存到相册',
  51. icon: 'success'
  52. })
  53. },
  54. fail: (err) => {
  55. console.error('保存失败:', err)
  56. // 可能是没有权限
  57. uni.showModal({
  58. title: '提示',
  59. content: '请开启相册权限后重试',
  60. showCancel: false
  61. })
  62. }
  63. })
  64. }
  65. },
  66. share() {
  67. var share = {};
  68. share.path = this.fetch.path;
  69. share.name = this.fetch.name;
  70. share.pic = this.fetch.logo;
  71. this.$emit('setShare', share)
  72. },
  73. success(file) {
  74. this.file = file;
  75. },
  76. open(name, title, info, logo, avatar, pic, param) {
  77. if (!param) {
  78. param = {}
  79. }
  80. this.DeverApi.get(this, 'user.code', param, res => {
  81. this.show = true;
  82. var views = []
  83. this.fetch.name = title;
  84. this.fetch.logo = logo;
  85. views.push({
  86. "type": "rect",
  87. "style": {
  88. "width": "356px",
  89. "height": "473px",
  90. "top": "11px",
  91. "left": "8px",
  92. "background": "#fff",
  93. "borderRadius": "10px",
  94. "zindex": 1,
  95. "color": "#fff"
  96. }
  97. });
  98. views.push({
  99. "type": "image",
  100. "url": avatar,
  101. "style": {
  102. "width": "59px",
  103. "height": "59px",
  104. "top": "34px",
  105. "left": "42px",
  106. "borderColor": "transparent",
  107. "borderRadius": "50px",
  108. "zindex": 10,
  109. "borderWidth": "1px",
  110. "mode": "scaleToFill"
  111. }
  112. })
  113. if (pic) {
  114. views.push({
  115. "type": "image",
  116. "url": pic,
  117. "style": {
  118. "width": "277px",
  119. "height": "277px",
  120. "top": "108px",
  121. "left": "48px",
  122. "borderColor": "transparent",
  123. "borderRadius": "8px",
  124. "zindex": 10,
  125. "mode": "scaleToFill"
  126. }
  127. })
  128. } else {
  129. if (this.Dever.env == 5) {
  130. views.push({
  131. "type": "image",
  132. "url": res.qrcode,
  133. "style": {
  134. "width": "277px",
  135. "height": "277px",
  136. "top": "108px",
  137. "left": "48px",
  138. "borderColor": "transparent",
  139. "borderRadius": "8px",
  140. "zindex": 10,
  141. "mode": "scaleToFill"
  142. }
  143. })
  144. } else {
  145. views.push({
  146. "type": "qrcode",
  147. "content": res.link,
  148. "style": {
  149. "width": "277px",
  150. "height": "277px",
  151. "top": "108px",
  152. "left": "48px",
  153. "background": "#ffffff",
  154. "color": "#000000",
  155. "zindex": 10,
  156. }
  157. })
  158. }
  159. }
  160. views.push({
  161. "type": "text",
  162. "text": "长按或扫一扫加入",
  163. "style": {
  164. "width": "172px",
  165. "height": "23px",
  166. "top": "422px",
  167. "left": "110px",
  168. "background": "transparent",
  169. "borderColor": "transparent",
  170. "zindex": 11,
  171. "color": "#000000",
  172. "fontSize": "18px",
  173. "lineHeight": 1.16,
  174. "maxLines": "2",
  175. "fontFamily": "Arial"
  176. }
  177. });
  178. views.push({
  179. "type": "text",
  180. "text": name,
  181. "style": {
  182. "width": "213px",
  183. "height": "23px",
  184. "top": "41px",
  185. "left": "110px",
  186. "background": "transparent",
  187. "borderColor": "transparent",
  188. "zindex": 11,
  189. "color": "#000000",
  190. "fontSize": "18px",
  191. "lineHeight": 1.16,
  192. "maxLines": "2",
  193. "fontFamily": "Arial"
  194. }
  195. })
  196. views.push({
  197. "type": "text",
  198. "text": info,
  199. "style": {
  200. "width": "224px",
  201. "height": "23px",
  202. "top": "66px",
  203. "left": "110px",
  204. "background": "transparent",
  205. "borderColor": "transparent",
  206. "zindex": 11,
  207. "color": "#000000",
  208. "fontSize": "18px",
  209. "lineHeight": 1.16,
  210. "maxLines": "2",
  211. "fontFamily": "Arial"
  212. }
  213. })
  214. if (pic) {
  215. if (this.Dever.env == 5) {
  216. views.push({
  217. "type": "image",
  218. "url": res.qrcode,
  219. "style": {
  220. "width": "58px",
  221. "height": "58px",
  222. "top": "404px",
  223. "left": "286px",
  224. "background": "#ffffff",
  225. "color": "#000000",
  226. "zindex": 100
  227. }
  228. })
  229. } else {
  230. views.push({
  231. "type": "qrcode",
  232. "content": res.link,
  233. "style": {
  234. "width": "58px",
  235. "height": "58px",
  236. "top": "404px",
  237. "left": "286px",
  238. "background": "#ffffff",
  239. "color": "#000000",
  240. "zindex": 100
  241. }
  242. })
  243. }
  244. }
  245. this.value = {
  246. "width": "375px",
  247. "height": "500px",
  248. "background": "#fff",
  249. "views": views
  250. }
  251. });
  252. }
  253. }
  254. }
  255. </script>
  256. <style>
  257. .btn-container {
  258. margin-top: 20rpx;
  259. gap: 20rpx;
  260. /* 按钮之间留点间距 */
  261. }
  262. .btn {
  263. flex: 1;
  264. text-align: center;
  265. padding: 20rpx 0;
  266. border-radius: 50rpx;
  267. /* 圆角胶囊效果 */
  268. font-size: 28rpx;
  269. font-weight: 600;
  270. color: #fff;
  271. box-shadow: 0 6rpx 12rpx rgba(0, 0, 0, 0.15);
  272. /* 阴影增强层次感 */
  273. transition: all 0.3s;
  274. }
  275. /* 悬停/点击时稍微缩小,增加交互感 */
  276. .btn:active {
  277. transform: scale(0.96);
  278. opacity: 0.9;
  279. }
  280. .btn-warn {
  281. background: linear-gradient(135deg, #ff7b47 0%, #ff4e50 100%);
  282. }
  283. .btn-base {
  284. background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  285. }
  286. </style>