quanyawei
2023-10-31 6d9652287b1aaf1fbb2423921b4ea036839c5a74
fix:小程序分享功能
1 files added
5 files modified
50 ■■■■■ changed files
App.vue 1 ●●●● patch | view | raw | blame | history
main.js 4 ●●● patch | view | raw | blame | history
pages/actionChange/workOrderDetails/index.vue 1 ●●●● patch | view | raw | blame | history
pages/index/index.vue 4 ●●●● patch | view | raw | blame | history
pages/login/login.vue 1 ●●●● patch | view | raw | blame | history
utils/share.js 39 ●●●●● patch | view | raw | blame | history
App.vue
@@ -25,6 +25,7 @@
                                    uni.clearStorageSync()
                                    uni.setStorageSync('userInfor', JSON.stringify(result.data))
                                    uni.setStorageSync('tonken', result.data.token)
                                    uni.setStorageSync('openId', result.data.openId)
                                    getDic()
                                    this.$isResolve()
                                } else {
main.js
@@ -6,6 +6,7 @@
// import * as common from './utils/common' // 公共文件
import store from './store/index.js'
import storage from './utils/storage' // 缓存文件
import share from './utils/share.js' // 导入并挂载全局的分享方法
import '.env.js'
// 定义全局
Vue.prototype.$store = store
@@ -24,4 +25,5 @@
})
app.$mount()
import uView from '@/uni_modules/uview-ui'
Vue.use(uView)
Vue.use(uView)
Vue.mixin(share)
pages/actionChange/workOrderDetails/index.vue
@@ -40,6 +40,7 @@
            console.log('option', option)
            //option为object类型,会序列化上个页面传递的参数
            this.basicInfor = JSON.parse(option.infor)
            this.share.title = '交办单信息'
        },
        onBackPress(e) {
            uni.navigateBack({
pages/index/index.vue
@@ -46,6 +46,7 @@
                this.showTabBar = data.data.showTabBar
                this.$refs.agencyPage.getContaminateList()
            })
            this.share.title = this.title
        },
        methods: {
            getData() {
@@ -56,9 +57,12 @@
                if (index === 2) {
                    this.isShow = false
                    this.title = '我的'
                    this.share.title = this.title
                }
                if (index === 0) {
                    this.isShow = true
                    this.title = '首页'
                    this.share.title = this.title
                    this.$nextTick(() => {
                        this.getData()
                    })
pages/login/login.vue
@@ -108,7 +108,6 @@
                console.log('openId', value)
                if (value) {
                    this.logining(value)
                    console.log('openId', openId)
                }
            },
            logining(openId) {
utils/share.js
New file
@@ -0,0 +1,39 @@
export default {
    data() {
        return {
            // 默认的全局分享内容(待测试)
            share: {
                title: '分享',
                path: '/pages/index/index', // 全局分享的路径
                imageUrl: '', // 全局分享的图片(可本地可网络)
            }
        }
    },
    // 定义全局分享
    // 1.发送给朋友
    onShareAppMessage(res) {
        // 获取加载的页面
        let pages = getCurrentPages(),
            // 获取当前页面的对象
            page = pages[pages.length - 1]
        // console.log("获取加载的页面", pages);
        this.share.path = `/${page.route}`
        if (page.options.infor) {
            this.share.path = `/${page.route}?infor=${page.options.infor}`
        }
        console.log('page.options', page.options)
        return {
            title: this.share.title,
            path: this.share.path,
            imageUrl: this.share.imageUrl,
        }
    },
    // //2.分享到朋友圈
    // onShareTimeline(res) {
    //     return {
    //         title: this.share.title,
    //         path: this.share.path,
    //         imageUrl: this.share.imageUrl,
    //     }
    // },
}