初始化项目模板

This commit is contained in:
yangyao committed 2026-01-04 17:53:40 +08:00
1 parent 80fd6a1d4b
commit b3a69a1f27
69 files changed
+11088

No files matched your search

+1062
View File
File diff suppressed because it is too large. Load diff
+159
View File
@@ -0,0 +1,159 @@
import {
isEmpty
} from '@/common/common.js'
import {
useUserStore
} from '@/store/user.js'
import { request } from '@/utils/request.js'
/*
@desc 多端一键登录授权
@desc wx:自2023年8月26日起,手机号快速验证组件将需要付费使用。标准单价为:每次组件调用成功,收费0.03元。
zfb:用户同意授权后,scope为长期有效,需用户自行手动解除授权。
@params e 为getPhoneNumber原生按钮的回调值
*/
export function uniLogin(e) {
return new Promise((resolve, reject) => {
if (e.detail.errMsg !== 'getPhoneNumber:ok') {
return
}
// 获取当前操作端
uni.getProvider({
service: 'oauth',
success: (res) => {
if (res.provider.includes('weixin') || res.provider.includes('alipay')) {
// 登录
uni.login({
provider: res.provider[0],
success: (loginRes) => {
if (loginRes.code) {
// 请求后端接口解密code,拿到真实电话号码,并缓存,然后关闭弹窗,渲染页面数据
var params = {
codeType: 'mpMobile',
codeValue: JSON.stringify({
...e.detail,
...{
loginData: loginRes,
},
}),
}
request({
method: 'POST',
url: '/sale/login/login',
data: params,
}).then((resp) => {
uni.showToast({
icon: 'none',
mask: true,
title: '登录成功',
})
if (resp.success) {
const userStore = useUserStore()
userStore.userToken = resp.data.token;
userStore.isLogin = resp.data.isLogin;
userStore.setProfile({
...resp.data.userData,
});
resolve(true)
} else {
// 失败的操作
console.log('request-fail', resp)
uni.showToast({
title: '授权登录失败',
icon: 'none',
})
resolve(false)
}
})
}
},
})
}
},
fail: (err) => {
console.log({ err })
uni.showToast({
title: '授权失败',
icon: 'none',
})
},
})
})
}
/**
* @desc 获取当前小程序端的登录授权码code
*/
export function getLoginCode() {
return new Promise((resolve, reject) => {
// #ifdef MP-WEIXIN || MP-ALIPAY
uni.getProvider({
service: 'oauth',
success: function(res) {
if (~res.provider.indexOf('weixin') || ~res.provider.indexOf('alipay')) {
// 登录
uni.login({
provider: res.provider[0],
success: function(loginRes) {
resolve(loginRes);
},
fail(err) {
reject(err);
},
});
}
},
});
// #endif
// #ifdef MP-BAIDU
swan.getLoginCode({
success(loginRes) {
resolve(loginRes);
},
fail(err) {
reject(err);
},
});
// #endif
// #ifdef APP-PLUS || H5
resolve();
// #endif
});
}
/**
* @desc 退出登录,清除token,手机号缓存
*/
export function loginOut(status) {
const userStore = useUserStore();
userStore.clearProfile();
userStore.userToken = '';
uni.showLoading({
mask: true,
title: 'loading...'
})
setTimeout(() => {
if (status) {
uni.switchTab({
url: '/pages/index/index'
})
}
uni.hideLoading()
}, 800)
}
/**
* @desc 检查是否存在token等用户信息
* @returns false 不存在token 、true存在token
*/
export function checkLoginStatus() {
const userStore = useUserStore();
const token = userStore.userToken;
if (isEmpty(token)) {
loginOut(false)
return false
} else {
return true
}
}
+262
View File
@@ -0,0 +1,262 @@
import { apiInitPay } from '../api/common';
import { useUserStore } from '../store/user';
import { baseUrl } from '../utils/request';
import { getConfig } from '@/pages/index/api';
import i18n from '../lang';
/**
* @desc 获取全局配置参数
*/
export const getConfigInfo = () => {
getConfig().then((res) => {
if (res.success) {
const bottomNavList = res.data?.bottomNavList;
// if (bottomNavList.length > 0) {
// bottomNavList.map((item) => {
// uni.setTabBarItem({
// ...item,
// });
// });
// }
}
});
};
/**
* @desc 退款协议
* @params companyCode 退款协议需要conpanyCode
* @params isRefund false非退款协议 true退款协议
* @return html富文本
*/
export function serviceApi(companyCode, isRefund) {
return new Promise((resolve, reject) => {
let id;
if (isRefund) {
id = companyCode === 'turbojet' ? 34 : 35;
} else {
id = 1;
}
request
.post(api.infoMessage, {
id: id,
})
.then((res) => {
if (res.success) {
resolve(res.data.content);
} else {
uni.showToast({
icon: 'none',
title: res.message,
});
reject();
}
});
});
}
//
/**
* @desc APP调用第三方程序 集成微信,支付寶跳轉
*/
export function launchApp() {
if (
plus.runtime.isApplicationExist({
pname: 'com.tencent.mm',
action: 'weixin://',
}) &&
paymentKey.value.includes('wx')
) {
// 跳转应用
plus.runtime.launchApplication(
{
pname: 'com.tencent.mm',
action: 'weixin://',
},
function (e) {
console.log('e', e);
}
);
// 检查支付通道
plus.payment.getChannels((res) => {
console.log('getChannels', res);
});
// 后台获取支付参数
request
.post(api.pay, {
groupId: groupId.value,
payAgentId: payAgentId.value,
})
.then((res) => {
// 拉起微信支付
plus.payment.request(
'wxpay',
res.data,
function (resp) {
console.log('resp', resp);
},
function (err) {
console.log('err', err);
}
);
});
}
// 判断支付宝
if (
plus.runtime.isApplicationExist({
pname: 'com.eg.android.AlipayGphone',
action: 'alipay://',
}) &&
paymentKey.value.includes('zfb')
) {
plus.runtime.launchApplication(
{
pname: 'com.eg.android.AlipayGphone',
action: 'alipay://',
},
function (e) {
console.log('launchApplication', e.message);
}
);
}
}
/**
* @desc 处理支付
* @params groupId 订单组id
* @return 支付参数
*/
export const handlePay = (groupId) => {
return new Promise(async (resolve, reject) => {
const res = await apiInitPay(groupId);
if (res.success) {
console.log(res.data);
const payInfo = res.data;
// 半屏支付
if (payInfo.payType === 'mpSkip') {
uni.openEmbeddedMiniProgram({
...payInfo.mpSkipParam,
success: (res) => {
console.log('success', res);
resolve(res.data);
},
fail: (err) => {
console.log('fail', err);
resolve(err.message);
},
});
} else if (payInfo.payType === 'direct') {
handleDirectPay(groupId, () => {
resolve();
});
}
} else {
resolve(res.message);
}
});
};
export function handleDirectPay(orderNo, callback) {
const userStore = useUserStore();
let __userToken = userStore.userToken;
let __lang = userStore.lang;
let __platform = userStore.platform;
let orderNum = typeof orderNo === 'object' ? orderNo.join(',') : orderNo;
uni.showLoading({
mask: true,
title: 'loading...',
});
uni.request({
url: baseUrl + '/sale/pay/pay',
method: 'POST',
data: {
groupId: orderNum,
__token: __userToken,
__platform: __platform,
__language: __lang,
channelId: 33,
},
success: (res) => {
if (res.data.code === 0) {
let requestParams = {};
// #ifdef MP-BAIDU
requestParams = {
orderInfo: {
...res.data.data,
...res.data.data.thirdParams,
},
};
// #endif
console.log(res.data.data);
// #ifndef MP-BAIDU
requestParams = {
orderInfo: res.data.data.thirdParams ? res.data.data.thirdParams.frontData.tradeNo : '',
timeStamp: res.data.data.timeStamp,
nonceStr: res.data.data.nonceStr,
package: res.data.data.package,
signType: res.data.data.signType,
paySign: res.data.data.paySign,
};
// #endif
uni.requestPayment({
...requestParams,
success(res) {
// #ifdef MP-ALIPAY
if (res.resultCode === '6001') {
uni.showToast({
icon: 'none',
title: i18n.global.t('cancelPay'),
duration: 2000,
});
}
if (res.resultCode === '9000') {
uni.showToast({
icon: 'none',
title: i18n.global.t('paySuccess'),
duration: 2000,
});
}
// #endif
// #ifndef MP-ALIPAY
uni.showToast({
icon: 'none',
title: i18n.global.t('paySuccess'),
});
// #endif
},
fail(res) {
console.log('fail-res', res);
uni.showToast({
icon: 'none',
title: i18n.global.t('payFailed'),
mask: true,
});
},
complete() {
callback();
},
});
} else {
// 创建失败
uni.showToast({
icon: 'none',
title: res.data.message,
mask: true,
});
callback();
}
},
fail: (err) => {
console.log('fail-err', err);
uni.showToast({
icon: 'none',
title: err.message,
});
setTimeout(() => {
callback();
}, 1500);
},
complete() {
uni.hideLoading();
},
});
}