This commit is contained in:
zpc 2025-05-03 15:37:20 +08:00
parent 8c59a5d19e
commit 5cb1218193
5 changed files with 132 additions and 149 deletions

View File

@ -3,44 +3,58 @@
* 定义所有端必须实现的方法 * 定义所有端必须实现的方法
*/ */
class BasePlatform { class BasePlatform {
constructor() { constructor() {
if (new.target === BasePlatform) { if (new.target === BasePlatform) {
throw new Error('BasePlatform 是抽象类,不能直接实例化'); throw new Error('BasePlatform 是抽象类,不能直接实例化');
} }
this.code = ''; // 平台代码WEB/MP/APP this.code = ''; // 平台代码WEB/MP/APP
this.env = ''; // 运行环境标识 this.env = ''; // 运行环境标识
}
getPayData(url,data) {
throw new Error('子类必须实现 getPayData 方法');
} }
/** getPayData(url, data) {
* 支付方法子类必须实现 throw new Error('子类必须实现 getPayData 方法');
* @param {number} amount - 支付金额 }
* @param {string} orderId - 订单号 /**
*/ *
pay({ data }) { */
throw new Error('子类必须实现 pay 方法'); chooseAddress() {
} return new Promise((resolve, reject) => {
throw new Error('子类必须实现 chooseAddress 方法');
});
}
/**
* 支付方法子类必须实现
* @param {number} amount - 支付金额
* @param {string} orderId - 订单号
*/
pay({
data
}) {
throw new Error('子类必须实现 pay 方法');
}
/** /**
* 分享方法子类必须实现 * 分享方法子类必须实现
* @param {object} params - 分享参数 { title, desc, image, url } * @param {object} params - 分享参数 { title, desc, image, url }
*/ */
share({ title, desc, link, image }) { share({
throw new Error('子类必须实现 share 方法'); title,
} desc,
link,
image
}) {
throw new Error('子类必须实现 share 方法');
}
/** /**
* 通用方法所有端共用 * 通用方法所有端共用
*/ */
getPlatformInfo() { getPlatformInfo() {
return { return {
code: this.code, code: this.code,
env: this.env, env: this.env,
ua: navigator?.userAgent || '' ua: navigator?.userAgent || ''
}; };
} }
} }
export default BasePlatform; export default BasePlatform;

View File

@ -7,15 +7,15 @@ class H5Platform extends BasePlatform {
this.env = 'h5'; this.env = 'h5';
} }
getPayData(url, data) { getPayData(url, data) {
data['quitUrl']=escape(window.location.href); data['quitUrl'] = escape(window.location.href);
data['returnUrl']=escape(window.location.href); data['returnUrl'] = escape(window.location.href);
console.log('处理数据',data); console.log('处理数据', data);
return data; return data;
} }
pay({ data }) { pay({ data }) {
console.log('支付1111'); console.log('支付1111');
return new Promise((resolve) => { return new Promise((resolve) => {
console.log(data); console.log(data);
// 创建一个临时div元素 // 创建一个临时div元素
@ -44,5 +44,31 @@ class H5Platform extends BasePlatform {
// 降级方案 // 降级方案
alert(`请手动分享:${url}`); alert(`请手动分享:${url}`);
} }
/**
* 选择地址
* @returns
*/
chooseAddress() {
return new Promise((resolve, reject) => {
uni.navigateTo({
url: '/pages/other/choose_address',
events: {
// 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
acceptDataFromOpenedPage: function (data) {
console.log(data)
},
someEvent: function (data) {
console.log(data)
}
},
success: function (res) {
// 通过eventChannel向被打开页面传送数据
res.eventChannel.emit('acceptDataFromOpenerPage', { data: 'data from starter page' })
}
})
});
}
} }
export default H5Platform; export default H5Platform;

View File

@ -11,7 +11,9 @@ class MiniProgramPlatform extends BasePlatform {
getPayData(url, data) { getPayData(url, data) {
return data; return data;
} }
pay({ data }) { pay({
data
}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let provider = "weixin"; let provider = "weixin";
uni.requestPayment({ uni.requestPayment({
@ -26,19 +28,20 @@ class MiniProgramPlatform extends BasePlatform {
complete: res => { complete: res => {
console.log('complete (res)', res) console.log('complete (res)', res)
if (res.errMsg == 'requestPayment:fail cancel') { if (res.errMsg == 'requestPayment:fail cancel') {
this.toast({ uni.showToast({
title: '取消支付', title: '取消支付',
icon: 'none', icon: 'none',
duration: 500, duration: 500,
success: () => { success: () => {
/* 取消订单 */ /* 取消订单 */
resolve('cancel')
} }
}) })
resolve('cancel')
} }
if (res.errMsg == 'requestPayment:ok') { if (res.errMsg == 'requestPayment:ok') {
this.toast({ uni.showToast({
title: '支付成功', title: '支付成功',
icon: 'success', icon: 'success',
duration: 500, duration: 500,
@ -52,13 +55,38 @@ class MiniProgramPlatform extends BasePlatform {
}) })
} }
share({ title, desc, image, url }) { share({
title,
desc,
image,
url
}) {
wx.showShareMenu({ wx.showShareMenu({
withShareTicket: true, withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline'] menus: ['shareAppMessage', 'shareTimeline']
}); });
// 监听用户点击分享按钮 // 监听用户点击分享按钮
wx.onShareAppMessage(() => ({ title, imageUrl: image })); wx.onShareAppMessage(() => ({
title,
imageUrl: image
}));
}
/**
* 选择地址
* @returns
*/
chooseAddress() {
return new Promise((resolve, reject) => {
uni.chooseAddress({
success: res => {
res.detailed_address = res.provinceName + res.cityName + res.countyName + res.detailInfo;
resolve(res)
},
fail: err => {
reject(err)
}
});
});
} }
} }
export default MiniProgramPlatform; export default MiniProgramPlatform;

View File

@ -17,17 +17,17 @@
onLoad() { onLoad() {
this.load(); this.load();
// test.vue // test.vue
// const eventChannel = this.getOpenerEventChannel(); const eventChannel = this.getOpenerEventChannel();
// eventChannel.emit('acceptDataFromOpenedPage', { eventChannel.emit('acceptDataFromOpenedPage', {
// data: 'data from test page' data: 'data from test page'
// }); });
// eventChannel.emit('someEvent', { eventChannel.emit('someEvent', {
// data: 'data from test page for someEvent' data: 'data from test page for someEvent'
// }); });
// // acceptDataFromOpenerPageeventChannel // // acceptDataFromOpenerPageeventChannel
// eventChannel.on('acceptDataFromOpenerPage', function(data) { eventChannel.on('acceptDataFromOpenerPage', function(data) {
// console.log(data) console.log(data)
// }) })
}, },
methods: { methods: {
async load() { async load() {

View File

@ -244,14 +244,11 @@
<view v-else class="add-info"> <view v-else class="add-info">
<view class="name-phone"> <view class="name-phone">
<view>{{ addData.userName }}</view> <view>{{ addData.userName }}</view>
<view class="phone">{{ addData.telNumber }}</view> <view class="phone">{{ addData.telNumber }}</view>
</view> </view>
<view class="add-text"> <view class="add-text">
{{ addData.provinceName }}-{{ addData.cityName }}-{{ {{ addData.detailed_address }}
addData.countyName
}}-{{ addData.detailInfo }}
</view> </view>
</view> </view>
<view class="icon"> <view class="icon">
@ -400,7 +397,6 @@ export default {
// } // }
], ],
subTabCur: 0, subTabCur: 0,
addData: '',
listData: [], listData: [],
total: 0, total: 0,
handelList: [], handelList: [],
@ -546,87 +542,12 @@ export default {
chooseAdd() { chooseAdd() {
this.canReload = false this.canReload = false
this.$platform.chooseAddress().then(res => {
var that = this; console.log(res);
// #ifdef H5
this.req({ this.addData = res
url: 'getAccessTokenOffiaccountSign', this.canReload = true;
data: { });
// recovery_info: JSON.stringify(data)
url: location.href.split('#')[0]
},
success: res => {
console.log(res);
if (res.status == 1) {
var _data = res.data;
wx.config({
debug: false, // ,apialertpclogpc
appId: _data.appId,
timestamp: _data.timestamp,
nonceStr: _data.noncestr,
signature: _data.signature,
jsApiList: [
'checkJsApi',
'openAddress',
]
});
wx.ready(function () {
wx.checkJsApi({
jsApiList: [
'openAddress',
],
success: function (res) {
// alert(res);
// console.log(res);
wx.openAddress({
success: function (res) {
console.log(res);
that.addData = res;
// var userName = res.userName; //
// var postalCode = res.postalCode; //
// var provinceName = res
// .provinceName; //
// var cityName = res.cityName; //
// var countryName = res
// .countryName; //
// var detailInfo = res.detailInfo; //
// var nationalCode = res.nationalCode; //
// var telNumber = res.telNumber; //
}
});
}
});
});
wx.error(function (res) {
// configerrorconfigdebugresSPA
console.log("出现错误", res);
});
}
}
})
// #endif
// #ifdef MP-WEIXIN
uni.chooseAddress({
success: res => {
console.log(res)
this.addData = res
},
fail: error => {
console.log(error)
},
complete: res => {
// console.log(123);
setTimeout(() => {
this.canReload = true
}, 500)
}
})
// #endif
}, },
submitLock() { submitLock() {
@ -693,13 +614,7 @@ export default {
type: this.subTab[this.subTabCur].id, type: this.subTab[this.subTabCur].id,
name: this.addData.userName, name: this.addData.userName,
mobile: this.addData.telNumber, mobile: this.addData.telNumber,
address: this.addData.provinceName + address: this.addData.detailed_address,
this.addData.cityName +
this.addData.countyName +
this.addData.detailInfo,
// name: '',
// mobile: '13355852333',
// address: '',
message: this.remark message: this.remark
// ad_id: uni.getStorageSync('_ad_id') // ad_id: uni.getStorageSync('_ad_id')
}, },