jiuyiUniapp/jiuyi2/components/mine/payPwd.vue

121 lines
2.2 KiB
Vue
Raw Normal View History

2025-01-04 20:33:45 +08:00
<script setup>
// 支付密码
import {
computed,
defineExpose,
ref,
getCurrentInstance,
defineEmits
} from 'vue';
import {
useStore
} from 'vuex'
2025-01-11 03:51:29 +08:00
// 工具库
2025-01-04 20:33:45 +08:00
import util from '@/common/js/util.js'
2025-01-11 03:51:29 +08:00
// api
import api from '@/api/index.js'
2025-01-04 20:33:45 +08:00
// 加密
import CryptoJS from 'crypto-js';
2025-01-11 03:51:29 +08:00
//
const props = defineProps({
// 是否验证
check: {
type: Boolean,
default: false
}
})
2025-01-04 20:33:45 +08:00
//
const {
proxy
} = getCurrentInstance()
2025-01-11 03:51:29 +08:00
// 触发父组件事件
const emits = defineEmits(['confirm'])
2025-01-04 20:33:45 +08:00
// 仓库
const store = useStore()
// 密码
const pwd = ref('')
// 用户信息
2025-01-12 02:05:25 +08:00
const userinfo = computed(() => store.state.userinfo)
2025-01-04 20:33:45 +08:00
// 打开弹窗
function open() {
// 如果用户没有二级密码
if (userinfo.value.hasSecondCipher) {
proxy.$refs.pwdRef.open()
} else {
uni.navigateTo({
url: '/pages/mine/setting/secondPwd'
})
}
}
// 关闭弹窗
function close() {
2025-01-11 03:51:29 +08:00
proxy.$refs.pwdRef.close()
setTimeout(() => {
// 清空二级密码
pwd.value = ''
}, 500)
2025-01-04 20:33:45 +08:00
}
// 确认
function handleConfirm() {
if (!/^\d{6}$/.test(pwd.value)) {
util.alert('二级密码不正确')
return
}
2025-01-11 03:51:29 +08:00
// 加密后的密码
let password = CryptoJS.MD5(pwd.value).toString()
//
if (!props.check) {
// 验证
emits('confirm', password)
close()
return
}
// 验证二级密码
api.mine.checkSecondLevelCipher({
data: {
secondLevelCipher: password,
}
}).then(rs => {
if (rs.code == 200) {
emits('confirm', password)
close()
return
}
util.alert({
content: rs.msg,
showCancel: false,
})
})
2025-01-04 20:33:45 +08:00
}
//
defineExpose({
open,
close,
})
</script>
<template>
<uni-popup ref="pwdRef" type="center">
<view class="pwdAlt popMid plr30 bfff">
<view class="title mtb30 f30">验证二级密码</view>
<view class="inputBox mtb20 plr30">
<input v-model="pwd" :maxlength="6" type="number" placeholder="输入二级密码" />
</view>
<view class="btns mtb30 rows">
<view class="btn lg cancel plr40 f1" @click="$refs.pwd.close()">取消</view>
<view class="btn lg black plr40 f1" @click="handleConfirm">验证</view>
</view>
</view>
</uni-popup>
</template>
<style>
</style>