index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view>
  3. <!-- #ifdef MP-ALIPAY -->
  4. <u-navbar title="分享" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" leftIconSize="0" />
  5. <!-- #endif -->
  6. <!-- #ifdef MP-WEIXIN -->
  7. <u-navbar title="分享" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
  8. <!-- #endif -->
  9. <!-- #ifndef MP-WEIXIN || MP-ALIPAY -->
  10. <view v-if="pagesNum > 1">
  11. <u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" :border="true" title="分享" />
  12. </view>
  13. <view v-else>
  14. <u-navbar leftIconSize="0" :placeholder="true" bgColor="#fff" :border="true" title="分享">
  15. <view class="nav-left flex" slot="left" @click="$toIndex()">
  16. <u-icon name="arrow-left" size="20" color="#333"></u-icon>
  17. </view>
  18. </u-navbar>
  19. </view>
  20. <!-- #endif -->
  21. <view class="flex invitation">
  22. <view class="flex invitation-user">
  23. <image src="../../static/public/share_bg.png" mode="aspectFit"></image>
  24. <view class="title">盲票</view>
  25. <image class="avatar" :src="avatar" mode="scaleToFill"></image>
  26. </view>
  27. <view class="invitation-name">{{ userInfo.nickName }}</view>
  28. <view class="invitation-name-tip">邀请您一起来刮盲票</view>
  29. <view class="flex invitation-code">
  30. <image :src="codeUrl" mode="aspectFill"></image>
  31. </view>
  32. <view class="invitation-code-tip">长按识别二维码</view>
  33. <view class="invitation-bottom-tip">盲票,玩的就是有趣</view>
  34. </view>
  35. <view class="flex btn">
  36. <button type="default" open-type="share">分享链接给好友</button>
  37. <button type="default" @click="saveImg">保存海报</button>
  38. </view>
  39. <share-code ref="shareCode" :posterData.sync="posterData" />
  40. </view>
  41. </template>
  42. <script>
  43. import env from '../../config/env.js'
  44. import $http from '@/utils/request.js'
  45. import appId from '@/config/appId.js'
  46. import ShareCode from "../components/share-code/share-code.vue"
  47. export default {
  48. components: {
  49. ShareCode
  50. },
  51. data() {
  52. return {
  53. codeUrl: '',
  54. userInfo: {},
  55. avatar: '',
  56. boxId: '',
  57. pagesNum: '',
  58. // 图片数据
  59. posterData: {
  60. poster: {
  61. //根据屏幕大小自动生成图片背景大小
  62. url: "https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/mp.png", //图片地址
  63. r: 15, //圆角半径
  64. w: 340, //图片宽度
  65. h: 447, //图片高度
  66. p: 20 //图片内边距padding
  67. },
  68. mainImg: {
  69. // 头像
  70. url: "", //图片地址
  71. r: 33, //圆角半径
  72. w: 66, //宽度
  73. h: 66, //高度
  74. mt: 40
  75. },
  76. title: {
  77. // 昵称
  78. text: "", //文本
  79. fontSize: 26, //字体大小
  80. color: "#4F4F4F", //颜色
  81. lineHeight: 37, //行高#4F4F4F 100%
  82. mt: 30, //margin-top
  83. w: 300,
  84. align: "center"
  85. },
  86. codeImg: {
  87. // 小程序码
  88. url: "", //图片地址
  89. w: 124, //宽度
  90. h: 124, //高度
  91. mt: 20, //margin-top
  92. r: 62, //圆角半径
  93. mt: 55
  94. },
  95. tips: [
  96. ]
  97. }
  98. };
  99. },
  100. onLoad(options) {
  101. this.boxId = options.boxId
  102. },
  103. onShow() {
  104. this.pagesNum = getCurrentPages().length
  105. this.getUrl()
  106. this.getBaseInfo()
  107. },
  108. methods: {
  109. getBaseInfo() {
  110. uni.showLoading({
  111. title: '加载中'
  112. });
  113. $http.post('/api/v1/mp/user/getLoginUserinfo', { appSource: appId }).then(res => {
  114. uni.hideLoading();
  115. if (res.code == 0) {
  116. this.userInfo = res.data
  117. this.avatar = this.posterData.mainImg.url = env.filePublic + res.data.avatar
  118. this.posterData.title.text = res.data.nickName
  119. }
  120. }).catch(() => {
  121. uni.hideLoading();
  122. })
  123. },
  124. getUrl() {
  125. $http.post('/api/v1/mp/user/share/code/generate', {
  126. boxId: this.boxId,
  127. type: "1",
  128. appSource: appId,
  129. }).then(res => {
  130. this.codeUrl = this.posterData.codeImg.url = env.filePublic + res.data
  131. })
  132. },
  133. saveImg() {
  134. this.$refs.shareCode.posterShow()
  135. },
  136. },
  137. onShareAppMessage(res) {
  138. return {
  139. title: '分享盲票',
  140. path: `/pages/ticketBox/detail?boxId=${ this.boxId }&userId=${ this.userInfo.userId }&type=1`,
  141. type: 2,
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. .invitation {
  148. flex-direction: column;
  149. margin: 50rpx 30rpx;
  150. padding: 0 0 80rpx;
  151. border: 1px solid rgba(236, 236, 236, 100);
  152. border-radius: 20rpx;
  153. background-color: #FFFFFF;
  154. &-user {
  155. position: relative;
  156. width: 100%;
  157. margin-bottom: 80rpx;
  158. image {
  159. width: 100%;
  160. height: 188rpx;
  161. border-top-left-radius: 20rpx;
  162. border-top-right-radius: 20rpx;
  163. }
  164. .title {
  165. position: absolute;
  166. font-size: 52rpx;
  167. color: #FFFFFF;
  168. top: 20rpx;
  169. }
  170. .avatar {
  171. position: absolute;
  172. width: 134rpx;
  173. height: 134rpx;
  174. border-radius: 50%;
  175. top: 120rpx;
  176. }
  177. }
  178. .invitation-name {
  179. font-size: 52rpx;
  180. margin-bottom: 40rpx;
  181. }
  182. .invitation-name-tip {
  183. font-size: 36rpx;
  184. color: rgba(134, 134, 134, 100);
  185. margin-bottom: 20rpx;
  186. }
  187. .invitation-code {
  188. image {
  189. width: 250rpx;
  190. height: 250rpx;
  191. margin-bottom: 20rpx;
  192. }
  193. }
  194. .invitation-code-tip {
  195. font-size: 34rpx;
  196. color: rgba(181, 181, 181, 100);
  197. margin-bottom: 60rpx;
  198. }
  199. .invitation-bottom-tip {
  200. font-size: 28rpx;
  201. }
  202. }
  203. .tip {
  204. text-align: center;
  205. }
  206. .btn {
  207. padding: 40rpx 20rpx;
  208. .ge {
  209. height: 40rpx;
  210. }
  211. ::v-deep button {
  212. line-height: 60rpx;
  213. font-size: 28rpx;
  214. height: 60rpx;
  215. color: #fff;
  216. background-color: $uni-bg-color;
  217. border: none;
  218. border-radius: 8rpx;
  219. }
  220. }
  221. </style>