feat:测试支付

This commit is contained in:
dzc committed 2025-01-20 14:00:59 +08:00
1 parent 4a495558d7
commit 94290006bb
2 files changed
+66 -64

No files matched your search

+65 -63
View File
@@ -1,83 +1,85 @@
<script setup lang="ts">
import { ref, reactive } from "vue";
import { onLoad, onShow } from "@dcloudio/uni-app";
import { ref, reactive } from "vue"
import { onLoad, onShow } from "@dcloudio/uni-app"
import { hooks, constant, router } from "@@/index";
import { userApi } from "@@/api";
import { hooks, constant, router } from "@@/index"
import { userApi } from "@@/api"
const data = {};
const data = {}
const state = reactive<any>({
userInfo: null,
});
userInfo: null,
})
const applyForm = reactive<any>({
username: "",
password: "",
});
username: "",
password: "",
})
const applyFormRules = reactive<any>({
username: [{ required: true, message: "请输入用户名" }],
password: [{ required: true, message: "请输入密码" }],
});
username: [{ required: true, message: "请输入用户名" }],
password: [{ required: true, message: "请输入密码" }],
})
onLoad(() => { });
onLoad(() => {})
onShow(() => {
const userInfoKey = constant.storageConstant.USERINFO;
state.userInfo = uni.getStorageSync(userInfoKey);
});
const userInfoKey = constant.storageConstant.USERINFO
state.userInfo = uni.getStorageSync(userInfoKey)
})
const applyFormRef = ref<any>(null);
const applyFormRef = ref<any>(null)
const doSubmit = async () => {
applyFormRef.value.submit();
const { isPass } = applyFormRef.value.validate();
if (!isPass) return;
const tokenKey = constant.storageConstant.TOKEN;
const userInfoKey = constant.storageConstant.USERINFO;
uni.removeStorageSync(tokenKey)
uni.showLoading({ title: "登录中...", mask: true });
const res = await userApi.login({
...applyForm,
grant_type: 'password',
scope: 'server',
});
if (res.code != 0) {
uni.showToast({ title: res.msg + ",登录失败,请重新登录", icon: "error" });
return;
}
uni.setStorageSync(tokenKey, res.data);
const { data: userData } = await userApi.userInfo();
uni.setStorageSync(userInfoKey, userData);
uni.hideLoading();
uni.showToast({ title: "登录成功", icon: "none" });
router.back();
};
applyFormRef.value.submit()
const { isPass } = applyFormRef.value.validate()
if (!isPass) return
const tokenKey = constant.storageConstant.TOKEN
const userInfoKey = constant.storageConstant.USERINFO
uni.removeStorageSync(tokenKey)
uni.showLoading({ title: "登录中...", mask: true })
const res = await userApi.login({
...applyForm,
grant_type: "password",
scope: "server",
})
if (res.code != 0) {
uni.showToast({ title: res.msg + ",登录失败,请重新登录", icon: "error" })
return
}
uni.setStorageSync(tokenKey, res.data)
const { data: userData } = await userApi.userInfo()
uni.setStorageSync(userInfoKey, userData)
uni.hideLoading()
uni.showToast({ title: "登录成功", icon: "none" })
router.back()
}
</script>
<template>
<crud-layout title="登录" bg="/static/page/blue-bg.png">
<view class="h-30rpx" />
<view class="card p-x-30rpx p-y-40rpx">
<tm-form ref="applyFormRef" v-model="applyForm" :rules="applyFormRules" direction="vertical">
<tm-form-item name="username" label="用户名" :showBottom="false">
<tm-input v-model="applyForm.username" placeholder="请输入用户名.." />
</tm-form-item>
<view class="h-30rpx" />
<tm-form-item name="password" label="验证码" :showBottom="false">
<tm-input password showEye v-model="applyForm.password" placeholder="请输入用户密码.." />
</tm-form-item>
</tm-form>
</view>
<view v-if="state.detailType != 'view'"
class="bg-#0094ff p-y-20rpx text-center rounded-40rpx m-x-30rpx m-t-60rpx sub-text-30 color-white!"
@tap="doSubmit">
登录
</view>
</crud-layout>
<crud-layout title="登录" bg="/static/page/blue-bg.png">
<view class="h-30rpx" />
<view class="card p-x-30rpx p-y-40rpx">
<tm-form ref="applyFormRef" v-model="applyForm" :rules="applyFormRules" direction="vertical">
<tm-form-item name="username" label="用户名" :showBottom="false">
<tm-input v-model="applyForm.username" placeholder="请输入用户名.." />
</tm-form-item>
<view class="h-30rpx" />
<tm-form-item name="password" label="密码" :showBottom="false">
<tm-input password showEye v-model="applyForm.password" placeholder="请输入用户密码.." />
</tm-form-item>
</tm-form>
</view>
<view
v-if="state.detailType != 'view'"
class="bg-#0094ff p-y-20rpx text-center rounded-40rpx m-x-30rpx m-t-60rpx sub-text-30 color-white!"
@tap="doSubmit"
>
登录
</view>
</crud-layout>
</template>
<style lang="scss" scoped>
:deep() {
.tmFormItemLabel {
padding-bottom: 10rpx !important;
}
.tmFormItemLabel {
padding-bottom: 10rpx !important;
}
}
</style>
+1 -1
View File
@@ -8,7 +8,7 @@ import { walletApi, payApi } from "@@/api"
const data = {
payType: [
{ text: "模拟支付", disabled: false, type: "0", value: "mock" },
// { text: "模拟支付", disabled: false, type: "0", value: "mock" },
{ text: "微信支付", disabled: true, type: "1", value: "wx_pub" },
{ text: "支付宝支付", disabled: true, type: "2", value: "alipay_wap" },
],