From 8fed55e64c8809ca5406a835675986974b742910 Mon Sep 17 00:00:00 2001 From: huliyong <2783385703@qq.com> Date: Wed, 2 Jul 2025 09:19:09 +0800 Subject: [PATCH] 1 --- main.js | 3 +++ mixins/configList.js | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ pages/index/index.vue | 30 +++++++++++------------ store/store.js | 4 ++- utils/utils.js | 10 ++++++++ 5 files changed, 99 insertions(+), 16 deletions(-) create mode 100644 mixins/configList.js diff --git a/main.js b/main.js index 3bade57..62452df 100644 --- a/main.js +++ b/main.js @@ -10,6 +10,9 @@ Vue.config.productionTip = false App.mpType = 'app' import store from '@/store/store' +import configList from '@/mixins/configList' + +Vue.mixin(configList) import './config' import './utils/index.js' diff --git a/mixins/configList.js b/mixins/configList.js new file mode 100644 index 0000000..07197b7 --- /dev/null +++ b/mixins/configList.js @@ -0,0 +1,68 @@ + + +import { mapState } from 'vuex' +export default { + data() { + return { + // 默认的全局分享内容 + Gshare: { + title: '遗产里的景徳镇', + path: '/pages_order/auth/wxLogin', // 全局分享的路径,比如 首页 + // imageUrl: '/static/image/login/logo.png', // 全局分享的图片(可本地可网络) + } + } + }, + computed: { + ...mapState(['configList', 'userInfo']), + currentPagePath() { + const pages = getCurrentPages(); + const currentPage = pages[pages.length - 1]; + let path = `/${currentPage.route}`; + + // 获取当前页面的参数 + const options = currentPage.options; + if (options && Object.keys(options).length > 0) { + const params = this.$utils.objectToUrlParams(options); + path += `?${params}`; + } + + return path; + }, + }, + onLoad(query) { + if (query.shareId) { + uni.setStorageSync('shareId', query.shareId) + } + }, + // 定义全局分享 + // 1.发送给朋友 + onShareAppMessage(res) { + let o = { + ...this.Gshare, + } + if(this.userInfo.id){ + if(this.Gshare.path.includes('?')){ + o.path += '&shareId=' + this.userInfo.id + }else{ + o.path += '?shareId=' + this.userInfo.id + } + } + return o + }, + //2.分享到朋友圈 + onShareTimeline(res) { + let o = { + ...this.Gshare, + } + if(this.userInfo.id){ + if(this.Gshare.path.includes('?')){ + o.path += '&shareId=' + this.userInfo.id + }else{ + o.path += '?shareId=' + this.userInfo.id + } + } + return o + }, + methods: { + } +} \ No newline at end of file diff --git a/pages/index/index.vue b/pages/index/index.vue index 4b30cd7..0f385d2 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -95,11 +95,11 @@ data() { return { baseList : [ - // { - // icon : '/static/image/home/g1.png', - // title : '申遗历程', - // path : '/pages_order/service/applyRelic', - // }, + { + icon : '/static/image/home/g1.png', + title : '申遗历程', + path : '/pages_order/service/applyRelic', + }, { icon : '/static/image/home/g2.png', title : '遗产概况', @@ -110,11 +110,11 @@ title : '遗产讲述', path : '/pages_order/service/tellList?type=tell', }, - { - icon : '/static/image/home/g4.png', - title : '达人同游', - path : '/pages_order/service/tellList?type=travel', - }, + // { + // icon : '/static/image/home/g4.png', + // title : '达人同游', + // path : '/pages_order/service/tellList?type=travel', + // }, { icon : '/static/image/home/g5.png', title : '遗产路径', @@ -145,11 +145,11 @@ // title : '无忧服务', // path : '/pages_order/service/carefree', // }, - { - icon : '/static/image/home/g6.png', - title : '申遗新闻', - path : '/pages_order/service/newsList', - }, + // { + // icon : '/static/image/home/g6.png', + // title : '申遗新闻', + // path : '/pages_order/service/newsList', + // }, ], bannerList: [ // { diff --git a/store/store.js b/store/store.js index 085fdac..8ef9f56 100644 --- a/store/store.js +++ b/store/store.js @@ -5,6 +5,7 @@ Vue.use(Vuex); //vue的插件机制 import api from '@/api/api.js' import Position from '@/utils/position.js' +import utils from '../utils/utils'; //Vuex.Store 构造器选项 const store = new Vuex.Store({ @@ -229,7 +230,8 @@ const store = new Vuex.Store({ url: '/pages_order/auth/wxUserInfo' }) }else{ - uni.navigateBack(-1) + // uni.navigateBack(-1) + utils.navigateBack() } }) } diff --git a/utils/utils.js b/utils/utils.js index dabe1e0..65a8784 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -165,7 +165,17 @@ export function navigateTo(...args){ uni.navigateTo(params(...args)) } +/** + * 返回上一页 + * @param {number} num - 返回的页面数,默认为-1 + */ export function navigateBack(num = -1){ + if(getCurrentPages().length == 1){ + uni.reLaunch({ + url: '/pages/index/index' + }) + return + } uni.navigateBack(num) }