diff --git a/admin/src/api/app/recharge.ts b/admin/src/api/app/recharge.ts new file mode 100644 index 00000000..8342c044 --- /dev/null +++ b/admin/src/api/app/recharge.ts @@ -0,0 +1,10 @@ +import request from '@/utils/request' + +export function getRechargeConfig() { + return request.get({ url: '/marketing/recharge/detail' }) +} + +// 设置 +export function setRechargeConfig(params: any) { + return request.post({ url: '/marketing/recharge/save', params }) +} diff --git a/admin/src/api/finance.ts b/admin/src/api/finance.ts new file mode 100644 index 00000000..790c6683 --- /dev/null +++ b/admin/src/api/finance.ts @@ -0,0 +1,31 @@ +import request from '@/utils/request' + +// 余额明细 +export function accountLog(params?: any) { + return request.get({ url: '/finance/wallet/list', params }) +} + +// 充值记录 +export function rechargeLists(params?: any) { + return request.get({ url: '/finance/recharger/list', params }, { ignoreCancelToken: true }) +} + +//退款 +export function refund(params?: any) { + return request.post({ url: '/finance/recharger/refund', params }) +} + +//重新退款 +export function refundAgain(params?: any) { + return request.post({ url: '/finance/recharger/refundAgain', params }) +} + +//退款记录 +export function refundRecord(params?: any) { + return request.get({ url: '/finance/refund/list', params }) +} + +//退款日志 +export function refundLog(params?: any) { + return request.get({ url: '/finance/refund/log', params }) +} diff --git a/admin/src/api/setting/pay.ts b/admin/src/api/setting/pay.ts new file mode 100644 index 00000000..8adad91f --- /dev/null +++ b/admin/src/api/setting/pay.ts @@ -0,0 +1,26 @@ +import request from '@/utils/request' + +// 获取支付方式 +export function getPayWay() { + return request.get({ url: '/setting/payment/method' }) +} + +// 设置支付方式 +export function setPayWay(params: any) { + return request.post({ url: '/setting/payment/editMethod', params }) +} + +// 获取支付方式 +export function getPayConfigLists() { + return request.get({ url: '/setting/payment/list' }) +} + +// 设置支付方式 +export function setPayConfig(params: any) { + return request.post({ url: '/setting/payment/editConfig', params }) +} + +// 设置支付方式 +export function getPayConfig(params: any) { + return request.get({ url: '/setting/payment/detail', params }) +} diff --git a/admin/src/components/link/shop-pages.vue b/admin/src/components/link/shop-pages.vue index e5c747b4..acb49b26 100644 --- a/admin/src/components/link/shop-pages.vue +++ b/admin/src/components/link/shop-pages.vue @@ -92,6 +92,11 @@ const linkList = ref([ path: '/pages/search/search', name: '搜索', type: LinkTypeEnum.SHOP_PAGES + }, + { + path: '/packages/pages/user_wallet/user_wallet', + name: '我的钱包', + type: LinkTypeEnum.SHOP_PAGES } ]) diff --git a/admin/src/hooks/usePaging.ts b/admin/src/hooks/usePaging.ts index 8a1aa599..d0de38d9 100644 --- a/admin/src/hooks/usePaging.ts +++ b/admin/src/hooks/usePaging.ts @@ -1,3 +1,4 @@ +import { isFunction } from 'lodash' import { reactive, toRaw } from 'vue' // 分页钩子函数 @@ -7,10 +8,20 @@ interface Options { fetchFun: (_arg: any) => Promise params?: Record firstLoading?: boolean + beforeRequest?(params: Record): Record + afterRequest?(res: Record): void } export function usePaging(options: Options) { - const { page = 1, size = 15, fetchFun, params = {}, firstLoading = false } = options + const { + page = 1, + size = 15, + fetchFun, + params = {}, + firstLoading = false, + beforeRequest, + afterRequest + } = options // 记录分页初始参数 const paramsInit: Record = Object.assign({}, toRaw(params)) // 分页数据 @@ -19,19 +30,28 @@ export function usePaging(options: Options) { size, loading: firstLoading, count: 0, - lists: [] as any[] + lists: [] as any[], + extend: {} as Record }) // 请求分页接口 const getLists = () => { pager.loading = true + let requestParams = params + if (isFunction(beforeRequest)) { + requestParams = beforeRequest(params) + } return fetchFun({ pageNo: pager.page, pageSize: pager.size, - ...params + ...requestParams }) .then((res: any) => { pager.count = res?.count pager.lists = res?.lists + pager.extend = res?.extend + if (isFunction(afterRequest)) { + afterRequest(res) + } return Promise.resolve(res) }) .catch((err: any) => { diff --git a/admin/src/views/app/recharge/index.vue b/admin/src/views/app/recharge/index.vue new file mode 100644 index 00000000..4944a140 --- /dev/null +++ b/admin/src/views/app/recharge/index.vue @@ -0,0 +1,54 @@ + + diff --git a/admin/src/views/consumer/components/account-adjust.vue b/admin/src/views/consumer/components/account-adjust.vue new file mode 100644 index 00000000..889cb3b2 --- /dev/null +++ b/admin/src/views/consumer/components/account-adjust.vue @@ -0,0 +1,104 @@ + + diff --git a/admin/src/views/consumer/lists/detail.vue b/admin/src/views/consumer/lists/detail.vue index 969df850..b69c8c67 100644 --- a/admin/src/views/consumer/lists/detail.vue +++ b/admin/src/views/consumer/lists/detail.vue @@ -5,9 +5,25 @@ -
-
用户头像
- +
+
+
用户头像
+ +
+
+
账户余额
+
+ ¥{{ formData.user_money }} + + 调整 + +
+
{{ formData.sn }} @@ -80,6 +96,11 @@ {{ formData.lastLoginTime }} +
@@ -88,7 +109,7 @@ import type { FormInstance } from 'element-plus' import { getUserDetail, userEdit } from '@/api/consumer' import feedback from '@/utils/feedback' import { isEmpty } from '@/utils/util' - +import AccountAdjust from '../components/account-adjust.vue' const route = useRoute() const formData = reactive({ avatar: '', @@ -105,7 +126,10 @@ const formData = reactive({ }) const formRef = shallowRef() - +const adjustState = reactive({ + show: false, + value: '' +}) const getDetails = async () => { const data = await getUserDetail({ id: route.query.id @@ -126,6 +150,15 @@ const handleEdit = async (value: string, field: string) => { feedback.msgSuccess('编辑成功') getDetails() } +const handleAdjust = (value: string) => { + adjustState.show = true + adjustState.value = value +} +const handleConfirmAdjust = async (value: any) => { + await adjustMoney({ user_id: route.query.id, ...value }) + adjustState.show = false + getDetails() +} getDetails() diff --git a/admin/src/views/consumer/lists/index.vue b/admin/src/views/consumer/lists/index.vue index 0d5b07fa..f9c24128 100644 --- a/admin/src/views/consumer/lists/index.vue +++ b/admin/src/views/consumer/lists/index.vue @@ -44,7 +44,7 @@ - + diff --git a/admin/src/views/finance/balance_details.vue b/admin/src/views/finance/balance_details.vue new file mode 100644 index 00000000..f2c27df7 --- /dev/null +++ b/admin/src/views/finance/balance_details.vue @@ -0,0 +1,101 @@ + + diff --git a/admin/src/views/finance/component/refund-log.vue b/admin/src/views/finance/component/refund-log.vue new file mode 100644 index 00000000..da59a6ab --- /dev/null +++ b/admin/src/views/finance/component/refund-log.vue @@ -0,0 +1,68 @@ + + + diff --git a/admin/src/views/finance/recharge_record.vue b/admin/src/views/finance/recharge_record.vue new file mode 100644 index 00000000..dbd5faa6 --- /dev/null +++ b/admin/src/views/finance/recharge_record.vue @@ -0,0 +1,141 @@ + + diff --git a/admin/src/views/finance/refund_record.vue b/admin/src/views/finance/refund_record.vue new file mode 100644 index 00000000..9a38df94 --- /dev/null +++ b/admin/src/views/finance/refund_record.vue @@ -0,0 +1,226 @@ + + diff --git a/admin/src/views/setting/pay/config/edit.vue b/admin/src/views/setting/pay/config/edit.vue new file mode 100644 index 00000000..edfe065e --- /dev/null +++ b/admin/src/views/setting/pay/config/edit.vue @@ -0,0 +1,279 @@ + + diff --git a/admin/src/views/setting/pay/config/index.vue b/admin/src/views/setting/pay/config/index.vue new file mode 100644 index 00000000..c2975a14 --- /dev/null +++ b/admin/src/views/setting/pay/config/index.vue @@ -0,0 +1,63 @@ + + + diff --git a/admin/src/views/setting/pay/method/index.vue b/admin/src/views/setting/pay/method/index.vue new file mode 100644 index 00000000..db23be06 --- /dev/null +++ b/admin/src/views/setting/pay/method/index.vue @@ -0,0 +1,138 @@ + + + diff --git a/uniapp/src/api/app.ts b/uniapp/src/api/app.ts index 9d5dcd37..32cec0d5 100644 --- a/uniapp/src/api/app.ts +++ b/uniapp/src/api/app.ts @@ -1,3 +1,4 @@ +import wechatOa from '@/utils/wechat' import request from '@/utils/request' //发送短信 @@ -24,3 +25,7 @@ export function uploadImage(file: any, token?: string) { fileType: 'image' }) } + +export function wxJsConfig(data: any) { + return request.get({ url: '/wechat/jsConfig', data }) +} diff --git a/uniapp/src/api/pay.ts b/uniapp/src/api/pay.ts new file mode 100644 index 00000000..cf56c8be --- /dev/null +++ b/uniapp/src/api/pay.ts @@ -0,0 +1,16 @@ +import request from '@/utils/request' + +//支付方式 +export function getPayWay(data: any) { + return request.get({ url: '/pay/payWay', data }, { isAuth: true }) +} + +// 预支付 +export function prepay(data: any) { + return request.post({ url: '/pay/prepay', data }, { isAuth: true }) +} + +// 预支付 +export function getPayResult(data: any) { + return request.get({ url: '/pay/payStatus', data }, { isAuth: true }) +} diff --git a/uniapp/src/api/recharge.ts b/uniapp/src/api/recharge.ts new file mode 100644 index 00000000..1432dd8f --- /dev/null +++ b/uniapp/src/api/recharge.ts @@ -0,0 +1,16 @@ +import request from '@/utils/request' + +//充值 +export function recharge(data: any) { + return request.post({ url: '/recharge/placeOrder', data }, { isAuth: true }) +} + +//充值记录 +export function rechargeRecord(data: any) { + return request.get({ url: '/recharge/record', data }, { isAuth: true }) +} + +// 充值配置 +export function rechargeConfig() { + return request.get({ url: '/recharge/config' }, { isAuth: true }) +} diff --git a/uniapp/src/api/user.ts b/uniapp/src/api/user.ts index c81c137b..8e1014ba 100644 --- a/uniapp/src/api/user.ts +++ b/uniapp/src/api/user.ts @@ -41,3 +41,8 @@ export function oaAuthBind(data: any) { export function updateUser(data: Record, header: any) { return request.post({ url: '/user/updateUser', data, header }) } + +//余额明细 +export function accountLog(data: any) { + return request.get({ url: '/logs/userMoney', data }) +} diff --git a/uniapp/src/components/page-status/page-status.vue b/uniapp/src/components/page-status/page-status.vue new file mode 100644 index 00000000..946fcc3b --- /dev/null +++ b/uniapp/src/components/page-status/page-status.vue @@ -0,0 +1,62 @@ + + + + + diff --git a/uniapp/src/components/payment/payment.vue b/uniapp/src/components/payment/payment.vue new file mode 100644 index 00000000..7e444500 --- /dev/null +++ b/uniapp/src/components/payment/payment.vue @@ -0,0 +1,330 @@ + + + + + diff --git a/uniapp/src/components/price/price.vue b/uniapp/src/components/price/price.vue new file mode 100644 index 00000000..58984989 --- /dev/null +++ b/uniapp/src/components/price/price.vue @@ -0,0 +1,126 @@ + + + + + diff --git a/uniapp/src/enums/appEnums.ts b/uniapp/src/enums/appEnums.ts index c399d6ab..957d40da 100644 --- a/uniapp/src/enums/appEnums.ts +++ b/uniapp/src/enums/appEnums.ts @@ -32,3 +32,18 @@ export enum FieldType { NICKNAME = 'nickname', SEX = 'sex' } + +// 支付结果 +export enum PayStatusEnum { + SUCCESS = 'success', + FAIL = 'fail', + PENDING = 'pending' +} + +// 页面状态 +export enum PageStatusEnum { + LOADING = 'loading', // 加载中 + NORMAL = 'normal', // 正常 + ERROR = 'error', // 异常 + EMPTY = 'empty' // 为空 +} \ No newline at end of file diff --git a/uniapp/src/packages/pages/recharge/recharge.vue b/uniapp/src/packages/pages/recharge/recharge.vue new file mode 100644 index 00000000..20f65c81 --- /dev/null +++ b/uniapp/src/packages/pages/recharge/recharge.vue @@ -0,0 +1,102 @@ + + diff --git a/uniapp/src/packages/pages/recharge_record/recharge_record.vue b/uniapp/src/packages/pages/recharge_record/recharge_record.vue new file mode 100644 index 00000000..f152cfdc --- /dev/null +++ b/uniapp/src/packages/pages/recharge_record/recharge_record.vue @@ -0,0 +1,44 @@ + + + + + diff --git a/uniapp/src/packages/pages/user_wallet/user_wallet.vue b/uniapp/src/packages/pages/user_wallet/user_wallet.vue new file mode 100644 index 00000000..14d85cb1 --- /dev/null +++ b/uniapp/src/packages/pages/user_wallet/user_wallet.vue @@ -0,0 +1,118 @@ + + + + + diff --git a/uniapp/src/packages/static/images/recharge_success.png b/uniapp/src/packages/static/images/recharge_success.png new file mode 100644 index 00000000..c6df9db6 Binary files /dev/null and b/uniapp/src/packages/static/images/recharge_success.png differ diff --git a/uniapp/src/pages.json b/uniapp/src/pages.json index 763f76ba..cbb0582e 100644 --- a/uniapp/src/pages.json +++ b/uniapp/src/pages.json @@ -109,7 +109,14 @@ "style": { "navigationStyle": "custom" } - }, + }, + { + "path": "pages/payment_result/payment_result", + "style": { + "navigationBarTitleText": "支付结果" + }, + "auth": true + }, { "path": "uni_modules/vk-uview-ui/components/u-avatar-cropper/u-avatar-cropper", "style": { @@ -117,7 +124,33 @@ "navigationBarBackgroundColor": "#000000" } } - ], + ], + "subPackages": [{ + "root": "packages", + "pages": [ + { + "path": "pages/user_wallet/user_wallet", + "style": { + "navigationBarTitleText": "我的钱包" + }, + "auth": true + }, + { + "path": "pages/recharge/recharge", + "style": { + "navigationBarTitleText": "充值" + }, + "auth": true + }, + { + "path": "pages/recharge_record/recharge_record", + "style": { + "navigationBarTitleText": "充值记录" + }, + "auth": true + } + ] + }], "globalStyle": { "navigationBarTextStyle": "black", "navigationBarTitleText": "商城", diff --git a/uniapp/src/pages/payment_result/payment_result.vue b/uniapp/src/pages/payment_result/payment_result.vue new file mode 100644 index 00000000..6bf7c63c --- /dev/null +++ b/uniapp/src/pages/payment_result/payment_result.vue @@ -0,0 +1,157 @@ + + + + + diff --git a/uniapp/src/pages/user_set/user_set.vue b/uniapp/src/pages/user_set/user_set.vue index 0c4c9c45..4cd5f5e6 100644 --- a/uniapp/src/pages/user_set/user_set.vue +++ b/uniapp/src/pages/user_set/user_set.vue @@ -145,13 +145,14 @@ const bindWechat = async () => { await mnpAuthBind({ code: code }) + + uni.$u.toast('绑定成功') //#endif // #ifdef H5 if (isWeixin.value) { wechatOa.getUrl() } // #endif - uni.$u.toast('绑定成功') await userStore.getUser() uni.hideLoading() } catch (e) { diff --git a/uniapp/src/router/index.ts b/uniapp/src/router/index.ts index 2de8363d..541f3055 100644 --- a/uniapp/src/router/index.ts +++ b/uniapp/src/router/index.ts @@ -1,7 +1,12 @@ +import { ClientEnum } from '@/enums/appEnums' import { BACK_URL } from '@/enums/cacheEnums' import { useUserStore } from '@/stores/user' import { getToken } from '@/utils/auth' import cache from '@/utils/cache' +import { client } from '@/utils/client' +// #ifdef H5 +import wechatOa from '@/utils/wechat' +// #endif import { routes } from './routes' const whiteList = ['register', 'login', 'forget_pwd'] @@ -41,6 +46,11 @@ export function setupRouter() { cache.set(BACK_URL, from.fullPath) } }) - + setTimeout(async () => { + if (client == ClientEnum.OA_WEIXIN) { + // jssdk配置 + await wechatOa.config() + } + }) // #endif } diff --git a/uniapp/src/static/images/payment/icon_succeed.png b/uniapp/src/static/images/payment/icon_succeed.png new file mode 100644 index 00000000..c27b413e Binary files /dev/null and b/uniapp/src/static/images/payment/icon_succeed.png differ diff --git a/uniapp/src/static/images/payment/icon_waiting.png b/uniapp/src/static/images/payment/icon_waiting.png new file mode 100644 index 00000000..956702a4 Binary files /dev/null and b/uniapp/src/static/images/payment/icon_waiting.png differ diff --git a/uniapp/src/uni_modules/vk-uview-ui/components/u-tabs/u-tabs.vue b/uniapp/src/uni_modules/vk-uview-ui/components/u-tabs/u-tabs.vue index 1cd83f35..718b6ef4 100644 --- a/uniapp/src/uni_modules/vk-uview-ui/components/u-tabs/u-tabs.vue +++ b/uniapp/src/uni_modules/vk-uview-ui/components/u-tabs/u-tabs.vue @@ -183,13 +183,18 @@ watch: { // 监听tab的变化,重新计算tab菜单的布局信息,因为实际使用中菜单可能是通过 // 后台获取的(如新闻app顶部的菜单),获取返回需要一定时间,所以list变化时,重新获取布局信息 - list(n, o) { - // list变动时,重制内部索引,否则可能导致超出数组边界的情况 - if(n.length !== o.length) this.currentIndex = 0; - // 用$nextTick等待视图更新完毕后再计算tab的局部信息,否则可能因为tab还没生成就获取,就会有问题 - this.$nextTick(() => { - this.init(); - }); + list: { + immediate: true, + handler(n, o) { + if(o) { + // list变动时,重制内部索引,否则可能导致超出数组边界的情况 + if(n.length !== o.length) this.currentIndex = 0; + // 用$nextTick等待视图更新完毕后再计算tab的局部信息,否则可能因为tab还没生成就获取,就会有问题 + } + setTimeout(() => { + this.init(); + },200) + } }, current: { immediate: true, @@ -290,6 +295,7 @@ for (let i = 0; i < this.list.length; i++) { // 只要size和rect两个参数 query.select(`#u-tab-item-${i}`).fields({ + id: true, size: true, rect: true }); @@ -319,6 +325,7 @@ let left = tabInfo.left + tabInfo.width / 2 - this.parentLeft; // 计算当前活跃item到组件左边的距离 this.scrollBarLeft = left - uni.upx2px(this.barWidth) / 2; + // 第一次移动滑块的时候,barFirstTimeMove为true,放到延时中将其设置false // 延时是因为scrollBarLeft作用于computed计算时,需要一个过程需,否则导致出错 if(this.barFirstTimeMove == true) { diff --git a/uniapp/src/utils/client.ts b/uniapp/src/utils/client.ts index 06e8d8a0..98b1aafc 100644 --- a/uniapp/src/utils/client.ts +++ b/uniapp/src/utils/client.ts @@ -43,7 +43,7 @@ export const getClient = () => { // 根据端处理事件 //@ts-ignore -export const handleClientEvent = ({ MP_WEIXIN, OA_WEIXIN, H5, IOS, ANDROID, OTHER }) => { +export const handleClientEvent = ({ MP_WEIXIN, OA_WEIXIN, H5, IOS, ANDROID, OTHER }: any) => { // #ifdef MP-WEIXIN return MP_WEIXIN() // #endif diff --git a/uniapp/src/utils/pay/index.ts b/uniapp/src/utils/pay/index.ts new file mode 100644 index 00000000..12b463eb --- /dev/null +++ b/uniapp/src/utils/pay/index.ts @@ -0,0 +1,14 @@ +import { Pay } from './pay' +import { Wechat } from './wechat' + +// 支付方式 +enum PayWayEnum { + BALANCE = 1, + WECHAT = 2, + ALIPAY = 3 +} +const wechat = new Wechat() +// 注入微信支付 +Pay.inject(PayWayEnum[2], wechat) +const pay = new Pay() +export { pay, PayWayEnum } diff --git a/uniapp/src/utils/pay/pay.ts b/uniapp/src/utils/pay/pay.ts new file mode 100644 index 00000000..09486009 --- /dev/null +++ b/uniapp/src/utils/pay/pay.ts @@ -0,0 +1,28 @@ +import { PayWayEnum } from '.' + +export class Pay { + private static modules = new Map() + static inject(name: string, module: any) { + this.modules.set(name, module) + } + constructor() { + //动态注入支付方式 + for (const [name, module] of Pay.modules.entries()) { + module.init(name, this) + } + } + + //调用支付 + async payment(payWay: PayWayEnum, options: any) { + try { + //@ts-ignore + const module = this[PayWayEnum[payWay]] + if (!module) { + throw new Error(`can not find pay way ${payWay}`) + } + return await module.run(options) + } catch (error) { + return Promise.reject(error) + } + } +} diff --git a/uniapp/src/utils/pay/wechat.ts b/uniapp/src/utils/pay/wechat.ts new file mode 100644 index 00000000..513eb4ba --- /dev/null +++ b/uniapp/src/utils/pay/wechat.ts @@ -0,0 +1,58 @@ +import { PayStatusEnum } from '@/enums/appEnums' +import { handleClientEvent } from '../client' +//#ifdef H5 +import wechatOa from '../wechat' +//#endif +export class Wechat { + init(name: string, pay: any) { + pay[name] = this + } + + async run(options: any) { + try { + const res = await handleClientEvent({ + MP_WEIXIN: () => { + return new Promise((resolve) => { + console.log(options) + uni.requestPayment({ + orderInfo: '', + provider: 'wxpay', + timeStamp: options.timeStamp, + nonceStr: options.nonceStr, + package: options.packageValue, + paySign: options.paySign, + signType: options.signType, + success() { + resolve(PayStatusEnum.SUCCESS) + }, + fail() { + resolve(PayStatusEnum.FAIL) + } + }) + }) + }, + OA_WEIXIN: () => { + return new Promise((resolve) => { + wechatOa + .pay(options) + .then(() => { + resolve(PayStatusEnum.SUCCESS) + }) + .catch(() => { + resolve(PayStatusEnum.FAIL) + }) + }) + }, + H5: () => { + return new Promise((resolve) => { + window.open(options.url, '_self') + resolve(PayStatusEnum.PENDING) + }) + } + }) + return res + } catch (error) { + return Promise.reject(error) + } + } +} diff --git a/uniapp/src/utils/util.ts b/uniapp/src/utils/util.ts index 2577ed7f..c8608e17 100644 --- a/uniapp/src/utils/util.ts +++ b/uniapp/src/utils/util.ts @@ -94,6 +94,33 @@ export function objectToQuery(params: Record): string { return query.slice(0, -1) } +/** + * @description 格式化输出价格 + * @param { string } price 价格 + * @param { string } take 小数点操作 + * @param { string } prec 小数位补 + */ +export function formatPrice({ price, take = 'all', prec = undefined }: any) { + let [integer, decimals = ''] = (price + '').split('.') + + // 小数位补 + if (prec !== undefined) { + const LEN = decimals.length + for (let i = prec - LEN; i > 0; --i) decimals += '0' + decimals = decimals.substr(0, prec) + } + + switch (take) { + case 'int': + return integer + case 'dec': + return decimals + case 'all': + return integer + '.' + decimals + } +} + + /** * @description 组合异步任务 * @param { string } task 异步任务 diff --git a/uniapp/src/utils/wechat.ts b/uniapp/src/utils/wechat.ts index cd29de0c..1e1c6210 100644 --- a/uniapp/src/utils/wechat.ts +++ b/uniapp/src/utils/wechat.ts @@ -1,7 +1,7 @@ import weixin from 'weixin-js-sdk' import { getWxCodeUrl, OALogin } from '@/api/account' -import { useUserStore } from '@/stores/user' import { isAndroid } from './client' +import { wxJsConfig } from '@/api/app' const wechatOa = { getSignLink() { @@ -15,6 +15,27 @@ const wechatOa = { location.href = res.url }) }, + config() { + return new Promise((resolve, reject) => { + wxJsConfig({ + url: this.getSignLink() + }).then((res) => { + weixin.config({ + appId: res.appid, // 必填,公众号的唯一标识 + timestamp: res.timestamp, // 必填,生成签名的时间戳 + nonceStr: res.nonceStr, // 必填,生成签名的随机串 + signature: res.signature, // 必填,签名 + jsApiList: res.jsApiList, + success: () => { + resolve('success') + }, + fail: (res: any) => { + reject('weixin config is fail') + } + }) + }) + }) + }, authLogin(code: string) { return new Promise((resolve, reject) => { OALogin({ @@ -35,6 +56,36 @@ const wechatOa = { }) }) }, + pay(options: Record) { + return new Promise((resolve, reject) => { + this.ready() + .then(() => { + weixin.chooseWXPay({ + timestamp: options.timeStamp, + nonceStr: options.nonceStr, + package: options.packageValue, + signType: options.signType, + paySign: options.paySign, + success: (res: any) => { + if (res.errMsg === 'chooseWXPay:ok') { + resolve(res) + } else { + reject(res.errMsg) + } + }, + cancel: (res: any) => { + reject(res) + }, + fail: (res: any) => { + reject(res) + } + }) + }) + .catch((err) => { + reject(err) + }) + }) + }, share(options: Record) { this.ready().then(() => { const { shareTitle, shareLink, shareImage, shareDesc } = options @@ -91,24 +142,3 @@ const wechatOa = { } export default wechatOa -// export function wxOaConfig() { -// return new Promise((resolve, reject) => { -// apiJsConfig().then((res) => { -// console.log(res) //微信配置 -// weixin.config({ -// debug: false, // 开启调试模式 -// appId: res.appId, // 必填,公众号的唯一标识 -// timestamp: res.timestamp, // 必填,生成签名的时间戳 -// nonceStr: res.nonceStr, // 必填,生成签名的随机串 -// signature: res.signature, // 必填,签名 -// jsApiList: res.jsApiList, // 必填,需要使用的JS接口列表 -// success: () => { -// resolve('success') -// }, -// fail: (res: any) => { -// reject('weixin config is fail') -// } -// }) -// }) -// }) -// } diff --git a/uniapp/tsconfig.json b/uniapp/tsconfig.json index 82086881..51f693c9 100644 --- a/uniapp/tsconfig.json +++ b/uniapp/tsconfig.json @@ -17,5 +17,12 @@ "@/*": ["./src/*"] } }, - "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "typings/**/*.d.ts"] + "include": [ + "src/**/*.ts", + "src/**/*.d.ts", + "src/**/*.tsx", + "src/**/*.vue", + "typings/**/*.d.ts", + "../admin/src/api/finance.ts" + ] }