feat: add charge page
This commit is contained in:
@@ -11,6 +11,9 @@
|
||||
</van-field>
|
||||
</van-cell-group>
|
||||
|
||||
<van-cell-group title="充值码" v-if="user.is_admin">
|
||||
<van-cell v-for="c in codes" size="large" :title="getCodeAmountTitle(c)" :value="c.code" @click="copyCode(c)" />
|
||||
</van-cell-group>
|
||||
|
||||
|
||||
|
||||
@@ -19,12 +22,17 @@
|
||||
<script setup>
|
||||
import request from "@/utils/request";
|
||||
|
||||
const codes = ref({});
|
||||
const user = ref({});
|
||||
const chargeCode = ref("")
|
||||
|
||||
const loadUserInfo = () => {
|
||||
request.get("/users/info").then((res) => {
|
||||
user.value = res.data;
|
||||
|
||||
if (user.value.is_admin) {
|
||||
loadChargeCodes();
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
@@ -34,6 +42,18 @@ onMounted(() => {
|
||||
loadUserInfo();
|
||||
});
|
||||
|
||||
const loadChargeCodes = () => {
|
||||
if (!user.value.is_admin) {
|
||||
return;
|
||||
}
|
||||
|
||||
request.get("/users/codes").then((res) => {
|
||||
codes.value = res.data;
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
};
|
||||
|
||||
const confirmCharge = () => {
|
||||
if (!chargeCode.value) {
|
||||
return showFailToast('请输入充值码');
|
||||
@@ -59,6 +79,17 @@ const confirmCharge = () => {
|
||||
console.log("取消充值");
|
||||
});
|
||||
};
|
||||
|
||||
const getCodeAmountTitle = (code) => {
|
||||
return code.amount / 100 + " 元/ " + code.amount + " 点";
|
||||
};
|
||||
|
||||
const copyCode = (c) => {
|
||||
// h5 copy c.code to clipboard
|
||||
navigator.clipboard.writeText(c.code);
|
||||
|
||||
showSuccessToast("充值码已复制");
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user