123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <template>
- <view class="indexBox">
- </view>
- </template>
- <script>
- import {
- mapState,
- mapMutations
- } from 'vuex';
- // #ifdef MP
- import {
- share
- } from '@/api/wx';
- // #endif
- import {
- loadIndexs,
- } from '@/api/index.js';
- export default {
- data() {
- return {
- };
- },
- computed: {
- ...mapState('user', ['hasLogin', 'userInfo']),
- },
- onLoad: function(option) {
- // #ifndef MP
- if (option.spread) {
- // 存储其他邀请人
- uni.setStorageSync('spread', option.spread);
- }
- // #endif
- // #ifdef MP
- if (option.scene) {
- // 存储小程序邀请人
- uni.setStorage({
- key: 'spread_code',
- data: option.scene
- });
- }
- this.share()
- // #endif
- },
- onShow() {
- this.loadIndexs();
- },
- onReady() {
- },
- // #ifdef MP
- onShareAppMessage(options) {
- // 设置菜单中的转发按钮触发转发事件时的转发内容
- let pages = getCurrentPages(); //获取加载的页面
- let currentPage = pages[pages.length - 1]; //获取当前页面的对象
- let url = currentPage.route; //当前页面url
- let item = currentPage.options; //如果要获取url中所带的参数可以查看options
- let shareObj = {
- title: this.shareData.title, // 默认是小程序的名称(可以写slogan等)
- path: url, // 默认是当前页面,必须是以‘/’开头的完整路径
- imageUrl: this.shareData.img,
- desc: this.shareData.synopsis,
- success: function(res) {
- // 转发成功之后的回调
- if (res.errMsg == 'shareAppMessage:ok') {}
- },
- fail: function() {
- // 转发失败之后的回调
- if (res.errMsg == 'shareAppMessage:fail cancel') {
- // 用户取消转发
- } else if (res.errMsg == 'shareAppMessage:fail') {
- // 转发失败,其中 detail message 为详细失败信息
- }
- }
- };
- // 判断是否可以邀请
- if (this.userInfo.uid) {
- shareObj.path += '&spread=' + this.userInfo.uid;
- }
- return shareObj;
- },
- // #endif
- methods: {
- // #ifdef MP
- share() {
- // console.log('加载分享');
- const that = this;
- // 请求获取默认数据
- share({}).then(({
- data
- }) => {
- // console.log('分享回调', data);
- that.shareData = data.data
- });
- },
- // #endif
- // 首页初始化
- loadIndexs() {
- const that = this;
- // 获取首页数据
- loadIndexs({
- store_id: that.shopDetail.id
- }).then((e) => {
- }).catch((e) => {
- })
- },
- navTo(url) {
- uni.navigateTo({
- url: url
- })
- }
- },
- };
- </script>
- <style lang="scss">
-
- </style>
|