mirror of
https://gitee.com/bootx/dax-pay-h5.git
synced 2025-10-14 06:04:51 +00:00
feat 收银台调试
This commit is contained in:
60
src/hooks/daxpay/useKeyboard.ts
Normal file
60
src/hooks/daxpay/useKeyboard.ts
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import type { Ref } from 'vue'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 键盘hooks
|
||||||
|
* @param amount
|
||||||
|
*/
|
||||||
|
export function useKeyboard(amount: Ref<string>) {
|
||||||
|
/**
|
||||||
|
* 输入
|
||||||
|
*/
|
||||||
|
function input(value: string) {
|
||||||
|
const amountStr = amount.value
|
||||||
|
if (amountStr === '0') {
|
||||||
|
if (value === '.') {
|
||||||
|
amount.value = '0.'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
amount.value = String(value)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// 只允许有一个小数点
|
||||||
|
if (value === '.' && amountStr.includes('.')) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 小数最多两位
|
||||||
|
if (amountStr.includes('.') && amountStr.length - amountStr.indexOf('.') > 2) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 金额最高100万
|
||||||
|
if (amountStr.split('.')[0].length > 6) {
|
||||||
|
// 是否有小数,
|
||||||
|
if (amountStr.includes('.') && amountStr.split('.')[1].length > 1) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!amountStr.includes('.') && value !== '.') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
amount.value = amountStr.concat(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
function del() {
|
||||||
|
if (amount.value.length > 1) {
|
||||||
|
amount.value = amount.value.substring(0, amount.value.length - 1)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
amount.value = '0'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
input,
|
||||||
|
del,
|
||||||
|
}
|
||||||
|
}
|
@@ -69,6 +69,7 @@ import {
|
|||||||
|
|
||||||
import { CashierTypeEnum } from '@/enums/daxpay/DaxPayEnum'
|
import { CashierTypeEnum } from '@/enums/daxpay/DaxPayEnum'
|
||||||
import router from '@/router'
|
import router from '@/router'
|
||||||
|
import { useKeyboard } from '@/hooks/daxpay/useKeyboard'
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const { mchNo, appId } = route.params
|
const { mchNo, appId } = route.params
|
||||||
@@ -80,6 +81,8 @@ const amount = ref<string>('0')
|
|||||||
const description = ref<string>('')
|
const description = ref<string>('')
|
||||||
const mchName = ref<string>('')
|
const mchName = ref<string>('')
|
||||||
|
|
||||||
|
const { input, del } = useKeyboard(amount)
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
initData()
|
initData()
|
||||||
})
|
})
|
||||||
@@ -96,48 +99,6 @@ function initData() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 输入
|
|
||||||
*/
|
|
||||||
function input(value: string) {
|
|
||||||
const amountStr = amount.value
|
|
||||||
if (amountStr === '0') {
|
|
||||||
if (value === '.') {
|
|
||||||
amount.value = '0.'
|
|
||||||
return
|
|
||||||
}
|
|
||||||
amount.value = String(value)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// 只允许有一个小数点
|
|
||||||
if (value === '.' && amountStr.includes('.')) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// 小数最多两位
|
|
||||||
if (amountStr.includes('.') && amountStr.length - amountStr.indexOf('.') > 2) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// 金额最高100万
|
|
||||||
if (amountStr.split('.')[0].length > 7 && value !== '.') {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
amount.value = amountStr.concat(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除
|
|
||||||
*/
|
|
||||||
function del() {
|
|
||||||
if (amount.value.length > 1) {
|
|
||||||
amount.value = amount.value.substring(0, amount.value.length - 1)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
amount.value = '0'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付
|
* 支付
|
||||||
*/
|
*/
|
||||||
|
@@ -1,12 +1,56 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h2>收银台</h2>
|
<div style="font-size: 28px;margin-top: 10px;">
|
||||||
|
{{ cashierInfo.cashierName || '微信收银台' }}
|
||||||
|
</div>
|
||||||
<div class="amount-display">
|
<div class="amount-display">
|
||||||
<p>付款给骏易</p>
|
<p style="font-size: 20px">
|
||||||
<p class="amount">¥ 0</p>
|
付款给{{ mchName }}
|
||||||
|
</p>
|
||||||
|
<p style="font-size: 32px;">
|
||||||
|
¥ {{ amount }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<van-dialog
|
||||||
|
v-model:show="show"
|
||||||
|
title="支付备注"
|
||||||
|
confirm-button-text="保存"
|
||||||
|
cancel-button-text="清除"
|
||||||
|
confirm-button-color="#4CAF50"
|
||||||
|
cancel-button-color="red"
|
||||||
|
show-cancel-button
|
||||||
|
@cancel="description = ''"
|
||||||
|
>
|
||||||
|
<van-field
|
||||||
|
v-model="description"
|
||||||
|
rows="2"
|
||||||
|
autosize
|
||||||
|
label=""
|
||||||
|
type="textarea"
|
||||||
|
:maxlength="50"
|
||||||
|
placeholder="请输入支付备注内容"
|
||||||
|
show-word-limit
|
||||||
|
/>
|
||||||
|
</van-dialog>
|
||||||
|
<van-number-keyboard
|
||||||
|
:show="true"
|
||||||
|
theme="custom"
|
||||||
|
extra-key="."
|
||||||
|
close-button-text="付款"
|
||||||
|
@close="pay"
|
||||||
|
@input="input"
|
||||||
|
@delete="del"
|
||||||
|
>
|
||||||
|
<template #title-left>
|
||||||
|
<div style="width: 100vw;display: flex; justify-content: center">
|
||||||
|
<div class="remark" @click="show = true">
|
||||||
|
添加备注
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</van-number-keyboard>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -16,22 +60,25 @@ import { useRoute } from 'vue-router'
|
|||||||
import type {
|
import type {
|
||||||
CashierAuthCodeParam,
|
CashierAuthCodeParam,
|
||||||
CashierPayParam,
|
CashierPayParam,
|
||||||
|
ChannelCashierConfigResult,
|
||||||
WxJsapiSignResult,
|
WxJsapiSignResult,
|
||||||
} from '@/views/daxpay/channel/ChannelCashier.api'
|
} from '@/views/daxpay/channel/ChannelCashier.api'
|
||||||
import {
|
import { cashierPay, generateAuthUrl, getCashierInfo, getMchName } from '@/views/daxpay/channel/ChannelCashier.api'
|
||||||
cashierPay,
|
|
||||||
generateAuthUrl,
|
|
||||||
} from '@/views/daxpay/channel/ChannelCashier.api'
|
|
||||||
|
|
||||||
import { CashierTypeEnum } from '@/enums/daxpay/DaxPayEnum'
|
import { CashierTypeEnum } from '@/enums/daxpay/DaxPayEnum'
|
||||||
import router from '@/router'
|
import router from '@/router'
|
||||||
|
import { useKeyboard } from '@/hooks/daxpay/useKeyboard'
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const { mchNo, appId } = route.params
|
const { mchNo, appId } = route.params
|
||||||
const { code } = route.query
|
const { code } = route.query
|
||||||
|
|
||||||
|
const show = ref<boolean>(false)
|
||||||
const loading = ref<boolean>(false)
|
const loading = ref<boolean>(false)
|
||||||
const amount = ref<number>(0.0)
|
const cashierInfo = ref<ChannelCashierConfigResult>({})
|
||||||
|
const amount = ref<string>('0')
|
||||||
|
const description = ref<string>('')
|
||||||
|
const mchName = ref<string>('')
|
||||||
|
|
||||||
// 认证参数
|
// 认证参数
|
||||||
const authParam = ref<CashierAuthCodeParam>({
|
const authParam = ref<CashierAuthCodeParam>({
|
||||||
@@ -40,6 +87,8 @@ const authParam = ref<CashierAuthCodeParam>({
|
|||||||
cashierType: CashierTypeEnum.WECHAT_PAY,
|
cashierType: CashierTypeEnum.WECHAT_PAY,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const { input, del } = useKeyboard(amount)
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
init()
|
init()
|
||||||
})
|
})
|
||||||
@@ -57,21 +106,34 @@ function init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// 发起收银台支付
|
// 初始化数据
|
||||||
wechatPay()
|
initData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化数据
|
||||||
|
*/
|
||||||
|
function initData() {
|
||||||
|
getCashierInfo(CashierTypeEnum.ALIPAY, appId as string).then(({ data }) => {
|
||||||
|
cashierInfo.value = data
|
||||||
|
})
|
||||||
|
getMchName(mchNo as string).then(({ data }) => {
|
||||||
|
mchName.value = data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信jsapi方式支付
|
* 微信jsapi方式支付
|
||||||
*/
|
*/
|
||||||
function wechatPay() {
|
function pay() {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
const from = {
|
const from = {
|
||||||
amount: amount.value,
|
amount: Number(amount.value),
|
||||||
appId,
|
appId,
|
||||||
authCode: code,
|
authCode: code,
|
||||||
cashierType: CashierTypeEnum.WECHAT_PAY,
|
cashierType: CashierTypeEnum.WECHAT_PAY,
|
||||||
|
description: description.value,
|
||||||
mchNo,
|
mchNo,
|
||||||
} as CashierPayParam
|
} as CashierPayParam
|
||||||
cashierPay(from)
|
cashierPay(from)
|
||||||
@@ -79,7 +141,7 @@ function wechatPay() {
|
|||||||
loading.value = false
|
loading.value = false
|
||||||
// 拉起jsapi支付
|
// 拉起jsapi支付
|
||||||
const json = JSON.parse(data.payBody)
|
const json = JSON.parse(data.payBody)
|
||||||
doJsapiPay(json)
|
jsapiPay(json)
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
// 跳转到错误页
|
// 跳转到错误页
|
||||||
@@ -93,7 +155,7 @@ function wechatPay() {
|
|||||||
/**
|
/**
|
||||||
* 拉起Jsapi支付窗口
|
* 拉起Jsapi支付窗口
|
||||||
*/
|
*/
|
||||||
function doJsapiPay(data: WxJsapiSignResult) {
|
function jsapiPay(data: WxJsapiSignResult) {
|
||||||
const form = {
|
const form = {
|
||||||
appId: data.appId, // 公众号ID,由商户传入
|
appId: data.appId, // 公众号ID,由商户传入
|
||||||
timeStamp: data.timeStamp, // 时间戳,自1970年以来的秒数
|
timeStamp: data.timeStamp, // 时间戳,自1970年以来的秒数
|
||||||
@@ -113,5 +175,30 @@ function doJsapiPay(data: WxJsapiSignResult) {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="less">
|
<style scoped lang="less">
|
||||||
|
@color: #4caf50;
|
||||||
|
|
||||||
|
:deep(.van-key--blue) {
|
||||||
|
background: @color;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
background-color: @color;
|
||||||
|
width: 100%;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 10px;
|
||||||
|
text-align: center;
|
||||||
|
color: white;
|
||||||
|
.amount-display {
|
||||||
|
background-color: white;
|
||||||
|
color: @color;
|
||||||
|
border-radius: 20px;
|
||||||
|
padding: 20px;
|
||||||
|
margin: 20px 0;
|
||||||
|
}
|
||||||
|
.amount-display p {
|
||||||
|
margin: 5px 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.remark {
|
||||||
|
color: @color;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
Reference in New Issue
Block a user