index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. console.log(this.bgUrl);
  52. },
  53. ...mapMutations(['logout']),
  54. show_share () {
  55. this.isShare = true;
  56. },
  57. hide_share () {
  58. this.isShare = false;
  59. },
  60. navTo(url){
  61. uni.navigateTo({
  62. url:url
  63. });
  64. },
  65. //退出登录
  66. toLogout(){
  67. uni.showModal({
  68. content: '确定要退出登录么',
  69. success: (e)=>{
  70. if(e.confirm){
  71. this.logout();
  72. setTimeout(()=>{
  73. uni.navigateBack();
  74. }, 200)
  75. }
  76. }
  77. });
  78. },
  79. //switch
  80. switchChange(e){
  81. let statusTip = e.detail.value ? '打开': '关闭';
  82. this.$api.msg(`${statusTip}消息推送`);
  83. },
  84. onShareAppMessage(res) {
  85. return {
  86. title: '这是分享页面',
  87. imageUrl: 'https://81f.dev.ytxxjs.cn/uploads/20220722/66ece9ed81674a79e12be6a28c238f98.png',
  88. path: '/pages/index/index'
  89. }
  90. },
  91. saveImg(){
  92. const that = this;
  93. uni.showLoading({
  94. title: '保存中'
  95. });
  96. uni.downloadFile({
  97. url:this.bgUrl,
  98. success: res => {
  99. if (res.statusCode === 200) {
  100. uni.saveImageToPhotosAlbum({
  101. filePath: res.tempFilePath,
  102. success: function() {
  103. that.$api.msg('保存成功');
  104. that.hide_share();
  105. },
  106. fail: function() {
  107. that.$api.msg('保存失败,请稍后重试');
  108. }
  109. });
  110. } else {
  111. that.$api.msg('下载失败');
  112. }
  113. }
  114. });
  115. }
  116. }
  117. }
  118. </script>
  119. <style lang='scss'>
  120. page{
  121. background: $page-color-base;
  122. }
  123. .bg {
  124. position: fixed;
  125. left: 0;
  126. top: 0;
  127. width: 100%;
  128. height: 100%;
  129. z-index: -1;
  130. }
  131. .jiu {
  132. margin: 45% auto 0;
  133. display: block;
  134. }
  135. .ewm {
  136. margin: 17% auto;
  137. height: 220rpx;
  138. width: 220rpx;
  139. display: block;
  140. }
  141. .yinying {
  142. width: 100%;
  143. height: 100%;
  144. background:#00000050;
  145. position: fixed;
  146. }
  147. .yinying .share_bg {
  148. margin: 10% auto;
  149. display: block;
  150. width: 90%;
  151. height: 68%;
  152. }
  153. .yinying .cannel {
  154. position: fixed;
  155. margin: 0 auto;
  156. width: 100%;
  157. height: 130rpx;
  158. bottom: 0;
  159. text-align: center;
  160. }
  161. .yinying .ul_panel {
  162. position: fixed;
  163. bottom: 170rpx;
  164. width: 100%;
  165. height: 200rpx;
  166. }
  167. .yinying .ul_panel ul {
  168. margin: 0 auto;
  169. padding: 0 60rpx;
  170. width: 90%;
  171. height: 100%;
  172. background: #ffffff;
  173. border-radius: 10rpx;
  174. }
  175. .yinying .ul_panel ul li {
  176. position: relative;
  177. }
  178. .yinying .ul_panel ul li.left {
  179. float: left;
  180. }
  181. .yinying .ul_panel ul li.right {
  182. float: right;
  183. }
  184. .yinying .ul_panel ul li .share_button{
  185. opacity: 0;
  186. position: absolute;
  187. width: 100%;
  188. height: 100%;
  189. }
  190. .yinying .ul_panel ul li image {
  191. margin: 0 auto;
  192. display: block;
  193. width: 90rpx;
  194. height: 90rpx;
  195. }
  196. .yinying .ul_panel ul li text {
  197. display: block;
  198. text-align: center;
  199. }
  200. .yinying .cannel .main {
  201. margin: 0 auto;
  202. width: 90%;
  203. height: 80rpx;
  204. line-height: 80rpx;
  205. background: #ffffff;
  206. border-radius: 10rpx;
  207. }
  208. </style>