index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <view class="container" @click="show_share">
  3. <image class="bg" :src="bgUrl"></image>
  4. <view class="yinying" v-if="isShare">
  5. <image class="share_bg" :src="bgUrl"></image>
  6. <view class="ul_panel">
  7. <ul>
  8. <li class="left">
  9. <button class="share_button" open-type="share"></button>
  10. <image src="/static/wx.png"></image>
  11. <text>微信好友</text>
  12. </li>
  13. <li class="right">
  14. <image src="/static/image.png" @click.stop="saveImg"></image>
  15. <text>保存海报</text>
  16. </li>
  17. </ul>
  18. </view>
  19. <view class="cannel" @click.stop="hide_share">
  20. <view class="main">取消</view>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import {
  27. mapMutations
  28. } from 'vuex';
  29. export default {
  30. data() {
  31. return {
  32. bgUrl: '',
  33. isShare: false,
  34. shareData: {
  35. title: '八十一坊|更实惠!',
  36. path: '/pages/index/index?id=1' // 分享的页面路径
  37. }
  38. };
  39. },
  40. onLoad(e) {
  41. this.getposter()
  42. },
  43. methods:{
  44. async getposter(){
  45. let [error, loginRes] = await uni.login({
  46. provider: 'weixin'
  47. });
  48. let access_token = uni.getStorageSync('access_token');
  49. let res = await this.$api.request('/poster/poster', 'POST',{access_token:access_token});
  50. this.bgUrl = res.base64;
  51. },
  52. ...mapMutations(['logout']),
  53. show_share () {
  54. this.isShare = true;
  55. },
  56. hide_share () {
  57. this.isShare = false;
  58. },
  59. navTo(url){
  60. uni.navigateTo({
  61. url:url
  62. });
  63. },
  64. //退出登录
  65. toLogout(){
  66. uni.showModal({
  67. content: '确定要退出登录么',
  68. success: (e)=>{
  69. if(e.confirm){
  70. this.logout();
  71. setTimeout(()=>{
  72. uni.navigateBack();
  73. }, 200)
  74. }
  75. }
  76. });
  77. },
  78. //switch
  79. switchChange(e){
  80. let statusTip = e.detail.value ? '打开': '关闭';
  81. this.$api.msg(`${statusTip}消息推送`);
  82. },
  83. onShareAppMessage(res) {
  84. return {
  85. title: '这是分享页面',
  86. imageUrl: 'https://81f.dev.ytxxjs.cn/uploads/20220722/66ece9ed81674a79e12be6a28c238f98.png',
  87. path: '/pages/index/index'
  88. }
  89. },
  90. saveImg(){
  91. const that = this;
  92. uni.showLoading({
  93. title: '保存中'
  94. });
  95. uni.downloadFile({
  96. url:this.bgUrl,
  97. success: res => {
  98. if (res.statusCode === 200) {
  99. uni.saveImageToPhotosAlbum({
  100. filePath: res.tempFilePath,
  101. success: function() {
  102. that.$api.msg('保存成功');
  103. that.hide_share();
  104. },
  105. fail: function() {
  106. that.$api.msg('保存失败,请稍后重试');
  107. }
  108. });
  109. } else {
  110. that.$api.msg('下载失败');
  111. }
  112. }
  113. });
  114. }
  115. }
  116. }
  117. </script>
  118. <style lang='scss'>
  119. page{
  120. background: $page-color-base;
  121. }
  122. .bg {
  123. position: fixed;
  124. left: 0;
  125. top: 0;
  126. width: 100%;
  127. height: 100%;
  128. z-index: -1;
  129. }
  130. .jiu {
  131. margin: 45% auto 0;
  132. display: block;
  133. }
  134. .ewm {
  135. margin: 17% auto;
  136. height: 220rpx;
  137. width: 220rpx;
  138. display: block;
  139. }
  140. .yinying {
  141. width: 100%;
  142. height: 100%;
  143. background:#00000050;
  144. position: fixed;
  145. }
  146. .yinying .share_bg {
  147. margin: 10% auto;
  148. display: block;
  149. width: 90%;
  150. height: 68%;
  151. }
  152. .yinying .cannel {
  153. position: fixed;
  154. margin: 0 auto;
  155. width: 100%;
  156. height: 130rpx;
  157. bottom: 0;
  158. text-align: center;
  159. }
  160. .yinying .ul_panel {
  161. position: fixed;
  162. bottom: 170rpx;
  163. width: 100%;
  164. height: 200rpx;
  165. }
  166. .yinying .ul_panel ul {
  167. margin: 0 auto;
  168. padding: 0 60rpx;
  169. width: 90%;
  170. height: 100%;
  171. background: #ffffff;
  172. border-radius: 10rpx;
  173. display: flex;
  174. align-items: center;
  175. justify-content: space-between;
  176. }
  177. .yinying .ul_panel ul li {
  178. position: relative;
  179. }
  180. .yinying .ul_panel ul li.left {
  181. float: left;
  182. }
  183. .yinying .ul_panel ul li.right {
  184. float: right;
  185. }
  186. .yinying .ul_panel ul li .share_button{
  187. opacity: 0;
  188. position: absolute;
  189. width: 100%;
  190. height: 100%;
  191. }
  192. .yinying .ul_panel ul li image {
  193. margin: 0 auto;
  194. display: block;
  195. width: 90rpx;
  196. height: 90rpx;
  197. }
  198. .yinying .ul_panel ul li text {
  199. display: block;
  200. text-align: center;
  201. color: #999;
  202. font-size: 28rpx;
  203. margin-top: 8rpx;
  204. }
  205. .yinying .cannel .main {
  206. margin: 0 auto;
  207. width: 90%;
  208. height: 80rpx;
  209. line-height: 80rpx;
  210. background: #ffffff;
  211. border-radius: 10rpx;
  212. }
  213. </style>