Browse Source

feat: 添加H5端适配和微信分享功能

- 新增H5端页面适配,包括登录、用户信息修改等页面
- 实现微信JSSDK分享功能,支持朋友圈和好友分享
- 重构微信支付为Promise版本,优化错误处理
- 添加H5端微信授权登录流程
- 更新项目配置和文档说明H5适配要求
master
主管理员 4 days ago
parent
commit
31be7a0312
18 changed files with 511 additions and 89 deletions
  1. +3
    -0
      .trae/rules/project_rules.md
  2. +2
    -0
      App.vue
  3. +5
    -0
      api/model/login.js
  4. +3
    -0
      components/base/navbar.vue
  5. +1
    -1
      components/novel/bookshelfItem.vue
  6. +1
    -1
      components/novel/novelItem.vue
  7. +1
    -1
      config.js
  8. +2
    -0
      manifest.json
  9. +113
    -31
      pages.json
  10. +10
    -3
      pages/index/center.vue
  11. +50
    -0
      pages_order/auth/Modifyinformation.vue
  12. +178
    -2
      pages_order/auth/wxLogin.vue
  13. +53
    -0
      pages_order/auth/wxUserInfo.vue
  14. +6
    -0
      pages_order/novel/readnovels.vue
  15. +8
    -0
      store/store.js
  16. +13
    -0
      utils/index.js
  17. +28
    -35
      utils/pay.js
  18. +34
    -15
      utils/share.js

+ 3
- 0
.trae/rules/project_rules.md View File

@ -1,3 +1,6 @@
当前项目是uniap开发微信小程序,目前需要在转h5端请你适配
每次编写代码时,请你先查看我的整个目录,提供的哪些文件、组件、功能、API接口,了解我的代码风格,写出和我风格一致的代码
## 项目规则


+ 2
- 0
App.vue View File

@ -1,6 +1,8 @@
<script>
import SignPackage from '@/utils/share.js'
export default {
onLaunch: function() {
SignPackage()
},
onShow: function() {
this.$store.commit('initConfig')


+ 5
- 0
api/model/login.js View File

@ -8,6 +8,11 @@ const api = {
limit: 500,
showLoading: true,
},
// 获取公众号签名
getSignPackage: {
url: '/all_login/getSignPackage',
method: 'POST',
},
// 绑定手机号码
bindPhone: {
url: '/all_login/bindPhone',


+ 3
- 0
components/base/navbar.vue View File

@ -1,4 +1,6 @@
<template>
<!-- #ifndef H5 -->
<!-- <view class="navbar"
:style="{backgroundColor : bgColor}"> -->
<view class="title"
@ -43,6 +45,7 @@
</view>
<!-- </view> -->
<!-- #endif -->
</template>
<script>


+ 1
- 1
components/novel/bookshelfItem.vue View File

@ -22,7 +22,7 @@
<text>{{ statusText }}</text>
</view>
<view class="book-text">
{{ item.service || '大家都在读' }}
{{ book.service || '大家都在读' }}
</view>
</view>
</view>


+ 1
- 1
components/novel/novelItem.vue View File

@ -19,7 +19,7 @@
<view class="content-row" v-if="!horizontal">
<bookStatus :status="book.status"/>
<view class="book-text">
{{ item.service || '大家都在读' }}
{{ book.service || '大家都在读' }}
</view>
</view>
</view>


+ 1
- 1
config.js View File

@ -14,7 +14,7 @@ const type = 'prod'
// 环境配置
const config = {
local : {
baseUrl : 'http://127.0.0.1:8002/novel-admin',
baseUrl : 'http://127.0.0.1:8003/novel-admin',
},
dev : {
baseUrl : 'http://h5.xzaiyp.top/novel-admin',


+ 2
- 0
manifest.json View File

@ -89,6 +89,8 @@
}
},
"devServer" : {
"port" : 8002,
"disableHostCheck" : true,
"https" : false,
"proxy" : {
"/ws/geocoder/v1/" : {


+ 113
- 31
pages.json View File

@ -2,7 +2,7 @@
"pages": [{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "",
"navigationBarTitleText": "首页",
"navigationBarTextStyle": "white",
"enablePullDownRefresh": true
}
@ -10,19 +10,19 @@
{
"path": "pages/index/bookshelf",
"style": {
"navigationBarTitleText": ""
"navigationBarTitleText": "书架"
}
},
{
"path": "pages/index/category",
"style": {
"navigationBarTitleText": ""
"navigationBarTitleText": "书城"
}
},
{
"path": "pages/index/center",
"style": {
"navigationBarTitleText": ""
"navigationBarTitleText": "个人中心"
}
}
],
@ -36,91 +36,173 @@
"root": "pages_order",
"pages": [
{
"path": "mine/purse"
"path": "mine/purse",
"style": {
"navigationBarTitleText": "立即提现"
}
},
{
"path": "mine/runningWater"
"path": "mine/runningWater",
"style": {
"navigationBarTitleText": "钱包流水"
}
},
{
"path": "author/editor"
"path": "author/editor",
"style": {
"navigationBarTitleText": "编辑器"
}
},
{
"path": "auth/wxLogin"
"path": "auth/wxLogin",
"style": {
"navigationBarTitleText": "登录"
}
},
{
"path": "auth/wxUserInfo"
"path": "auth/wxUserInfo",
"style": {
"navigationBarTitleText": "用户信息"
}
},
{
"path": "mine/help"
"path": "mine/help",
"style": {
"navigationBarTitleText": "帮助"
}
},
{
"path": "novel/novelDetail"
"path": "novel/novelDetail",
"style": {
"navigationBarTitleText": "小说详情"
}
},
{
"path": "announcement/announcementDetail"
"path": "announcement/announcementDetail",
"style": {
"navigationBarTitleText": "公告详情"
}
},
{
"path": "announcement/announcements"
"path": "announcement/announcements",
"style": {
"navigationBarTitleText": "全部公告"
}
},
{
"path": "author/createNovel"
"path": "author/createNovel",
"style": {
"navigationBarTitleText": "创建小说"
}
},
{
"path": "author/chapterList"
"path": "author/chapterList",
"style": {
"navigationBarTitleText": "章节列表"
}
},
{
"path": "novel/ReaderAchievement"
"path": "novel/ReaderAchievement",
"style": {
"navigationBarTitleText": "读者成就"
}
},
{
"path": "novel/readnovels"
"path": "novel/readnovels",
"style": {
"navigationBarTitleText": "阅读小说"
}
},
{
"path": "novel/SubscriptionInformation"
"path": "novel/SubscriptionInformation",
"style": {
"navigationBarTitleText": "订阅信息"
}
},
{
"path": "novel/Tipping",
"style": {
"navigationBarTitleText": "读者亲密值榜单",
"navigationBarTextStyle": "white"
}
},
{
"path": "comment/review"
"path": "comment/review",
"style": {
"navigationBarTitleText": "写书评"
}
},
{
"path": "comment/comments"
"path": "comment/comments",
"style": {
"navigationBarTitleText": "评论"
}
},
{
"path": "comment/respondComments"
"path": "comment/respondComments",
"style": {
"navigationBarTitleText": "回复评论"
}
},
{
"path": "mine/Walletflow"
"path": "mine/Walletflow",
"style": {
"navigationBarTitleText": "钱包流水"
}
},
{
"path": "author/creator"
"path": "author/creator",
"style": {
"navigationBarTitleText": "作者中心"
}
},
{
"path": "novel/Giftbox"
"path": "novel/Giftbox",
"style": {
"navigationBarTitleText": "礼物盒"
}
},
{
"path": "novel/Giftpurchases"
"path": "novel/Giftpurchases",
"style": {
"navigationBarTitleText": "礼物购买"
}
},
{
"path": "comment/myComment"
"path": "comment/myComment",
"style": {
"navigationBarTitleText": "我的评论"
}
},
{
"path": "novel/Translation"
"path": "novel/Translation",
"style": {
"navigationBarTitleText": "任务中心"
}
},
{
"path": "novel/bookList"
"path": "novel/bookList",
"style": {
"navigationBarTitleText": "搜索"
}
},
{
"path": "auth/Modifyinformation"
"path": "auth/Modifyinformation",
"style": {
"navigationBarTitleText": "修改信息"
}
},
{
"path": "mine/recharge"
"path": "mine/recharge",
"style": {
"navigationBarTitleText": "充值"
}
},
{
"path": "mine/webview"
"path": "mine/webview",
"style": {
"navigationBarTitleText": "网页"
}
}
]
}],


+ 10
- 3
pages/index/center.vue View File

@ -10,19 +10,21 @@
<view class="user">
<!-- #ifndef H5 -->
<view class=""
style="height: 120rpx;padding-top: calc(var(--status-bar-height) + 20rpx);">
</view>
<!-- #endif -->
<!-- 用户信息区域 -->
<view class="user-info">
<image class="avatar" :src="userInfo.headImage" mode="aspectFill"></image>
<image class="avatar" :src="userInfo.headImage || '/static/image/center/headImage.png'" mode="aspectFill"></image>
<view class="info">
<view class="name">{{ userInfo.nickName }}
<view class="name">{{ userInfo.nickName || 'Hi 尊敬的用户' }}
<!-- <text class="id"> (ID: {{ userInfo.id }})</text> -->
</view>
<view class="desc">{{ userInfo.details || '' }}</view>
<view class="phone">手机号{{ userInfo.phone }}</view>
<view class="phone">手机号{{ userInfo.phone || '未绑定' }}</view>
</view>
<!-- <view class="more">
<uv-icon name="more-dot-fill" size="46rpx" color="#999"></uv-icon>
@ -299,8 +301,13 @@
flex-direction: row;
align-items: center;
margin-left: 36rpx;
/* #ifndef H5 */
margin-top: 218rpx;
/* #endif */
/* #ifdef H5 */
margin-top: 58rpx;
/* #endif */
}
.nologin-avatar {
width: 80rpx;


+ 50
- 0
pages_order/auth/Modifyinformation.vue View File

@ -3,6 +3,7 @@
<navbar title="修改信息" leftClick @leftClick="$utils.navigateBack" />
<view class="header">
<!-- #ifdef MP-WEIXIN -->
<button open-type="chooseAvatar"
class="share"
@chooseavatar="onChooseAvatar">
@ -13,6 +14,19 @@
</view>
</view>
</button>
<!-- #endif -->
<!-- #ifdef H5 -->
<view class="avatar-upload">
<uv-avatar :src="userInfoForm.headImage" size="88" shape="circle" class="avatar-main" />
<uv-upload :fileList="fileList" :maxCount="1" width="48rpx" height="48rpx"
@afterRead="afterRead" @delete="deleteImage">
<view class="avatar-upload-btn">
<uv-icon name="camera-fill" size="28" color="#fff" />
</view>
</uv-upload>
</view>
<!-- #endif -->
</view>
<view class="card">
<view class="card-title">个人信息</view>
@ -33,6 +47,7 @@
<view class="divider"></view>
</view>
<!-- #ifdef MP-WEIXIN -->
<button
class="share"
open-type="getPhoneNumber" @getphonenumber="getPhone">
@ -45,6 +60,20 @@
<view class="divider"></view>
</view>
</button>
<!-- #endif -->
<!-- #ifdef H5 -->
<view class="card">
<view class="card-title">手机号</view>
<view class="form-item">
<view class="form-label"><text class="star">*</text> 手机号</view>
<view class="form-value">
<input placeholder="请输入手机号" v-model="userInfoForm.phone" />
</view>
</view>
<view class="divider"></view>
</view>
<!-- #endif -->
<view class="footer">
<uv-button type="primary" text="确认" shape="circle" size="large" @click="submit"
@ -65,6 +94,7 @@
headImage: '',
nickName: '',
phone: '',
details: '',
},
}
},
@ -75,6 +105,7 @@
this.userInfoForm.details = this.userInfo.details || ''
},
methods: {
// #ifdef MP-WEIXIN
onChooseAvatar(res) {
this.$Oss.ossUpload(res.target.avatarUrl)
.then(url => {
@ -97,6 +128,25 @@
}
})
},
// #endif
// #ifdef H5
deleteImage(e){
this.fileList.splice(e.index, 1)
this.userInfoForm.headImage = ''
},
afterRead(e){
let self = this
// e.file.forEach(file => {
self.$Oss.ossUpload(e.file.url).then(url => {
self.userInfoForm.headImage = url
// self.fileList = [{
// url
// }]
})
// })
},
// #endif
submit() {
let self = this


+ 178
- 2
pages_order/auth/wxLogin.vue View File

@ -9,7 +9,7 @@
</view>
<view class="btn mt"
@click="wxLogin">
@click="handleLogin">
<!-- <view class="icon">
<image src="../static/auth/wx.png" mode=""></image>
</view> -->
@ -36,7 +36,7 @@
activeColor="#0A2463"
:name="1"
></uv-checkbox>
阅读并同意我们的<text @click="$refs.popup.open('user_xy')">用户协议</text>
阅读并同意我们的<text @click="$refs.popup.open('user_xy')">"用户协议"</text>
</view>
<view class="">
以及<text @click="$refs.popup.open('user_ys')">隐私政策</text>
@ -51,6 +51,7 @@
</template>
<script>
import SignPackage from '@/utils/share.js'
export default {
name : 'Login',
data() {
@ -67,11 +68,186 @@
this.config = query
}
},
// #ifdef H5
mounted() {
// H5URL
this.checkWechatAuthCallback();
},
// #endif
methods: {
//
handleLogin() {
if(!this.checkboxValue.length){
return uni.showToast({
title: '请先同意隐私协议',
icon:'none'
})
}
// #ifdef MP-WEIXIN
//
this.miniProgramLogin();
// #endif
// #ifdef H5
// H5 -
this.wechatOfficialLogin();
// #endif
},
//
miniProgramLogin() {
uni.login({
provider: 'weixin',
success: async (res) => {
console.log('小程序登录成功', res);
await this.processLogin(res.code);
},
fail: (err) => {
console.log('小程序登录失败', err);
uni.showToast({
title: '登录失败',
icon: 'none'
});
}
})
},
//
wechatOfficialLogin() {
console.log('开始微信公众号授权登录');
// URL
const appId = this.configList.official_appid || 'wx3c85955875a7b099'; // AppID
const redirectUri = encodeURIComponent(window.location.origin + window.location.pathname + '#/pages_order/auth/wxLogin');
console.log('redirectUri:', window.location.origin + window.location.pathname + '#/pages_order/auth/wxLogin');
const state = Date.now().toString();
//
if (uni.getStorageSync('shareId')) {
sessionStorage.setItem('temp_shareId', uni.getStorageSync('shareId'));
}
const authUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`;
console.log('跳转到微信授权页面:', authUrl);
window.location.href = authUrl;
},
//
checkWechatAuthCallback() {
const code = this.getUrlParameter('code');
const state = this.getUrlParameter('state');
if (code && state) {
console.log('检测到微信授权回调, code:', code, 'state:', state);
//
const tempShareId = sessionStorage.getItem('temp_shareId');
if (tempShareId) {
uni.setStorageSync('shareId', tempShareId);
sessionStorage.removeItem('temp_shareId');
}
//
this.processLogin(code, 'official');
}
},
//
async processLogin(code, type = 'applet') {
try {
const loginParams = {
code: code,
type
};
//
if (uni.getStorageSync('shareId')) {
loginParams.shareId = uni.getStorageSync('shareId');
}
console.log('登录参数:', loginParams);
// API
const apiName = type === 'official' ? 'officialLogin' : 'wxLogin';
// API
this.$api('wxLogin', loginParams, (res) => {
if (res.code == 200) {
uni.setStorageSync('token', res.result.token);
const userInfo = res.result.userInfo;
// store
this.$store.state.userInfo = userInfo;
this.$store.state.isLogin = true;
uni.setStorageSync('userInfo', userInfo)
SignPackage()
if (!userInfo.nickName || !userInfo.headImage) {
uni.navigateTo({
url: '/pages_order/auth/wxUserInfo'
});
return;
} else {
uni.showToast({
title: '登录成功',
icon: 'success'
});
uni.navigateBack(-1);
}
} else {
throw new Error(res.msg || '登录失败');
}
});
} catch (error) {
console.error('登录失败:', error);
uni.showToast({
title: '登录失败,请重试',
icon: 'none'
});
// #ifdef H5
// H5URL
if (this.getUrlParameter('code')) {
const cleanUrl = window.location.origin + window.location.pathname + window.location.hash.split('?')[0];
window.history.replaceState({}, document.title, cleanUrl);
}
// #endif
}
},
// URL
getUrlParameter(name) {
// #ifdef H5
const url = window.location.href;
try {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(name) || '';
} catch (e) {
//
const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)');
const results = regex.exec(url);
if (!results) return '';
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
// #endif
// #ifndef H5
return '';
// #endif
},
getPhoneNumber(e){
console.log(e, e.detail.code);
this.wxLogin(phoneCode)
},
wxLogin(phoneCode){
if(!this.checkboxValue.length){
return uni.showToast({


+ 53
- 0
pages_order/auth/wxUserInfo.vue View File

@ -10,6 +10,7 @@
申请获取你的头像昵称
</view>
<!-- #ifdef MP-WEIXIN -->
<button class="chooseAvatar" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
<view class="line">
<view class="">
@ -23,6 +24,21 @@
</view>
</view>
</button>
<!-- #endif -->
<!-- #ifdef H5 -->
<view class="line">
<view class="">
头像
</view>
<view class="h5-avatar-upload">
<uv-upload :fileList="fileList" :maxCount="1" width="60rpx" height="60rpx"
@afterRead="afterRead" @delete="deleteImage">
<image src="../static/auth/headImage.png" style="width: 50rpx;height: 50rpx;" mode=""></image>
</uv-upload>
</view>
</view>
<!-- #endif -->
<view class="line">
<view class="">
昵称
@ -37,6 +53,7 @@
手机号
</view>
<!-- #ifdef MP-WEIXIN -->
<view class=""
v-if="userInfoForm.phone">
<input placeholder="请输入手机号" style="text-align: right;"
@ -53,6 +70,14 @@
获取电话号码
</button>
</view>
<!-- #endif -->
<!-- #ifdef H5 -->
<view class="">
<input placeholder="请输入手机号" style="text-align: right;"
v-model="userInfoForm.phone" />
</view>
<!-- #endif -->
</view>
@ -72,6 +97,9 @@
nickName: '',
phone : '',
},
// #ifdef H5
fileList: []
// #endif
};
},
onShow() {},
@ -79,9 +107,15 @@
this.userInfoForm.phone = this.userInfo.phone || ''
this.userInfoForm.nickName = this.userInfo.nickName || ''
this.userInfoForm.headImage = this.userInfo.headImage || ''
if(this.userInfoForm.headImage){
this.fileList = [{
url: this.userInfoForm.headImage
}]
}
},
computed: {},
methods: {
// #ifdef MP-WEIXIN
onChooseAvatar(res) {
this.$Oss.ossUpload(res.target.avatarUrl)
.then(url => {
@ -104,6 +138,25 @@
}
})
},
// #endif
// #ifdef H5
deleteImage(e){
this.fileList.splice(e.index, 1)
this.userInfoForm.headImage = ''
},
afterRead(e){
let self = this
// e.file.forEach(file => {
self.$Oss.ossUpload(e.file.url).then(url => {
self.userInfoForm.headImage = url
self.fileList = [{
url
}]
})
// })
},
// #endif
submit() {
let self = this


+ 6
- 0
pages_order/novel/readnovels.vue View File

@ -965,9 +965,13 @@
font-size: 28rpx;
color: #222;
line-height: 2.2;
/* #ifndef H5 */
padding-top: 160rpx;
/* 为导航栏预留空间,不随状态变化 */
padding-bottom: 180rpx;
/* #endif */
width: 100%;
box-sizing: border-box;
overflow-x: hidden;
@ -996,6 +1000,8 @@
font-size: 30rpx;
color: #333;
word-wrap: break-word;
// white-space: pre-wrap;
// word-break: break-word;
word-break: normal;
white-space: normal;
transition: color 0.3s ease;


+ 8
- 0
store/store.js View File

@ -5,6 +5,8 @@ Vue.use(Vuex); //vue的插件机制
import api from '@/api/api.js'
import SignPackage from '@/utils/share.js'
//Vuex.Store 构造器选项
const store = new Vuex.Store({
state: {
@ -33,6 +35,11 @@ const store = new Vuex.Store({
res.result.forEach(n => {
state.configList[n.keyName] = n.keyContent
})
// 登录logo
uni.setStorageSync('login_logo', state.configList.logo_image)
SignPackage()
}
})
},
@ -97,6 +104,7 @@ const store = new Vuex.Store({
api('getUserInfo', res => {
if (res.code == 200) {
state.userInfo = res.result
uni.setStorageSync('userInfo', state.userInfo)
}
})
},


+ 13
- 0
utils/index.js View File

@ -52,6 +52,19 @@ Vue.prototype.openLocation = (latitude, longitude) => {
// 封装微信支付
uni.requestPaymentWxPay = function(res){
// #ifdef H5
if(!jWeixin){
uni.showToast({
icon:'none',
title:"请在微信浏览器中打开"
})
return
}
return wxPay(res)
// #endif
return new Promise((success, error) => {
uni.requestPayment({
provider: 'wxpay', // 服务提提供商


+ 28
- 35
utils/pay.js View File

@ -4,44 +4,37 @@ import jWeixin from './lib/jweixin-module.js'
// #endif
/**
* 调用微信支付
* 调用微信支付 - Promise版本
* @param {Object} res - 支付参数对象包含appIdtimeStampnonceStr等必要信息
* @param {Function} successCallback - 支付成功的回调函数
* @param {Function} failCallback - 支付失败的回调函数
* @param {Function} optionCallback - 配置失败的回调函数
* @returns {Promise} 返回Promise对象成功时resolve失败时reject
*/
export function wxPay(res, successCallback, failCallback, optionCallback) {
// 配置微信JSSDK
jWeixin.config({
debug: false,
appId: res.result.appId, //必填,公众号的唯一标识
jsApiList: ['chooseWXPay'] //必填,需要使用的JS接口列表
});
// JSSDK配置成功后的回调
jWeixin.ready(function() {
// 调用微信支付接口
jWeixin.chooseWXPay({
appId: res.result.appId,
timestamp: res.result.timeStamp, // 支付签名时间戳
nonceStr: res.result.nonceStr, // 支付签名随机串
package: res.result.packageValue, // 统一支付接口返回的prepay_id参数值
signType: res.result.signType, // 签名类型,默认为MD5
paySign: res.result.paySign, // 支付签名
success: function() {
successCallback && successCallback();
},
fail: function(error) {
failCallback && failCallback();
},
cancel : function(){
failCallback && failCallback();
}
export function wxPay(res) {
return new Promise((resolve, reject) => {
// JSSDK配置成功后的回调
jWeixin.ready(function() {
// 调用微信支付接口
jWeixin.chooseWXPay({
appId: res.result.appId,
timestamp: res.result.timeStamp, // 支付签名时间戳
nonceStr: res.result.nonceStr, // 支付签名随机串
package: res.result.packageValue, // 统一支付接口返回的prepay_id参数值
signType: res.result.signType, // 签名类型,默认为MD5
paySign: res.result.paySign, // 支付签名
success: function(result) {
resolve(result);
},
fail: function(error) {
reject(error);
},
cancel: function(cancelResult) {
reject({ type: 'cancel', data: cancelResult });
}
});
});
});
// JSSDK配置失败处理
jWeixin.error(function(res) {
optionCallback && optionCallback()
// JSSDK配置失败处理
jWeixin.error(function(error) {
reject({ type: 'config_error', data: error });
});
});
}

+ 34
- 15
utils/share.js View File

@ -1,3 +1,4 @@
// #ifdef H5
import api from '@/api/api.js'
import config from "../config.js"
import jWeixin from './lib/jweixin-module.js'
@ -5,9 +6,11 @@ import jWeixin from './lib/jweixin-module.js'
function share() { //微信分享
//获取签名
let data = {
url: import.meta.env.VITE_REDIRECT_URI + '/#/'
// location.href.split('#')[0])
// url: Vue.prototype.$config.redirect + '/#/'
url: location.href.split('#')[0]
}
api('getVipShareSign', data, res => {
api('getSignPackage', data).then(res => {
if (res.code == 200) {
let {
appId,
@ -25,24 +28,35 @@ function share() { //微信分享
'updateTimelineShareData',
'updateAppMessageShareData',
'onMenuShareWeibo',
'getLocation'
]
'getLocation',
'chooseWXPay',
'requestMerchantTransfer',
'checkJsApi',
'scanQRCode',
],
success: function () {
console.log('配置成功');
}
});
jWeixin.ready(function() {
jWeixin.ready(function () {
// 微信分享的数据
var shareData = {
"link": addQueryParams(data.url),
"desc": "泰柔到家",
"title": "泰柔到家,温柔呵护每一刻!",
imgUrl : import.meta.env.VITE_REDIRECT_URI + '/static/share/logo.png',
success: function() {
"desc": "布丁小说",
"title": "布丁小说",
imgUrl: uni.getStorageSync('login_logo'),
success: function () {
//分享成功可以做相应的数据处理
console.log('注册分享成功');
// uni.showToast({
// mask: true,
// duration: 1000,
// title: '注册分享成功',
// });
},
fail : function (e){
console.log(e);
}
};
//分享微信朋友圈内容设置
@ -52,10 +66,10 @@ function share() { //微信分享
//分享到微博内容设置
jWeixin.onMenuShareWeibo(shareData);
});
jWeixin.error(function(err){
jWeixin.error(function (err) {
console.error(err);
// config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
// config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
})
}
})
@ -65,11 +79,16 @@ function addQueryParams(url) {
if (url) {
//获取用户id
let userInfo = localStorage.getItem('userInfo') ? JSON.parse(localStorage.getItem('userInfo')) : null
if(userInfo){
url += `?vid=${userInfo.id}`
if (userInfo) {
url += `?inviter=${userInfo.id}`
}
}
return url
}
export default share
export default share
// #endif
// #ifndef H5
export default function(){}
// #endif

Loading…
Cancel
Save