diff --git a/vue/gold-system/src/api/index.js b/vue/gold-system/src/api/index.js new file mode 100644 index 0000000..eae8ed7 --- /dev/null +++ b/vue/gold-system/src/api/index.js @@ -0,0 +1,9 @@ +import http from '../util/http.js'; + +const API={ + post: function(url,data){ + return http({url:url,method:'post',data:data}) + }, +}; + +export default API; \ No newline at end of file diff --git a/vue/gold-system/src/assets/background.jpg b/vue/gold-system/src/assets/background.jpg new file mode 100644 index 0000000..8135c88 Binary files /dev/null and b/vue/gold-system/src/assets/background.jpg differ diff --git a/vue/gold-system/src/router/index.js b/vue/gold-system/src/router/index.js index a4fcf30..40b1180 100644 --- a/vue/gold-system/src/router/index.js +++ b/vue/gold-system/src/router/index.js @@ -3,9 +3,11 @@ import { createRouter,createWebHashHistory } from 'vue-router'; const router=createRouter({ history:createWebHashHistory(), routes:[ + {path:'/login', name:"login", component:()=>import("../views/login.vue")}, {path:'/',redirect:"/workspace"}, {path:'/test',component:()=>import("../views/z.vue")}, { + meta:{requireAuth:true}, path:'/index',component:()=>import("../views/index.vue"), children:[ // 工作台 @@ -40,4 +42,13 @@ const router=createRouter({ ] }); +router.beforeEach((to,from,next)=>{ + const token=localStorage.getItem("token"); + if(to.name!="login"&&!token){ + next({name:"login"}); + }else{ + next(); + } +}) + export default router; \ No newline at end of file diff --git a/vue/gold-system/src/util/http.js b/vue/gold-system/src/util/http.js new file mode 100644 index 0000000..07c2402 --- /dev/null +++ b/vue/gold-system/src/util/http.js @@ -0,0 +1,32 @@ +import axios from 'axios'; + +export default function (options) { + //配置每次发送请求都从localStorage中获取名字叫token的数据, + //添加到请求头部的Authorization属性中 + + //Object.assign用于合并对象的数据 + options.headers = Object.assign( + { Authorization: localStorage.getItem('token') }, + options.headers || {} + ); + //axios() 返回一个promise对象,用于异步请求 + //options是一个对象,其中包含了许多用于配置请求的参数, + //例如请求的url、请求方法(GET、POST等)、请求头等 + return axios(options) + .then(({ status, data, statusText }) => { + //该函数在请求成功并返回数据时被调用 + //status:HTTP状态码,例如200表示请求成功。 + //data:服务器返回的数据。 + // statusText:HTTP状态文本,例如"OK"表示请求成功。 + console.log(data); + if (status == 200) { + return data; + } else { + throw new Error(statusText); + } + }) + .catch(e=>{ + return Promise.reject(e); + //return Promise.reject(e.message); + }); +} \ No newline at end of file diff --git a/vue/gold-system/src/views/consume/addConsume.vue b/vue/gold-system/src/views/consume/addConsume.vue index 5b1119c..637222b 100644 --- a/vue/gold-system/src/views/consume/addConsume.vue +++ b/vue/gold-system/src/views/consume/addConsume.vue @@ -6,14 +6,19 @@ import { Plus } from "@element-plus/icons-vue"; import axios from "axios"; import { ElMessageBox } from "element-plus"; -// 这是添加充值信息的表单 -const addConsume = ref({}); -// 这是添加充值信息的接口 +// 这是添加消费信息的表单 +const addConsume = ref({ + freeCoin: 0, + rechargeCoin: 0, + taskCoin: 0, + updateType: "消费", +}); +// 这是添加消费信息的接口 const add = async function () { try { // 发送POST请求 const result = await axios.post( - "http://192.168.8.93:10010/recharge/recharge/add", + "http://192.168.8.147:10030/consume/add", addConsume.value ); @@ -59,7 +64,7 @@ const checkEndTime = function (rule, value, callback) { }; const rules = reactive({ jwcode: [{ required: true, message: "请输入精网号", trigger: "blur" }], - refundGoods: [{ required: true, message: "请选择退款商品", trigger: "blur" }], + goods: [{ required: true, message: "请选择消费商品", trigger: "blur" }], taskCoin: [{ required: true, message: "请输入任务金币", trigger: "blur" }], freeCoin: [{ required: true, message: "请输入免费金币", trigger: "blur" }], rechargeCoin: [ @@ -94,97 +99,70 @@ const getUser = async function (jwcode) { } }; -// 这是查询活动的接口 -const activity = ref([]); -const getActivity = async function () { +// 查询商品的接口 +const goods = ref([]); +const getGoods = async function () { try { // 发送POST请求 - const result = await axios.post( - "http://192.168.8.93:10010/recharge/activity/select", - {} - ); - + const result = await axios.post("http://192.168.8.93:10020/product", {}); // 将响应结果存储到响应式数据中 console.log("请求成功", result); - // 存储表格数据 - activity.value = result.data.data; - console.log("活动信息", activity.value); + // 存储全部数据 + goods.value = result.data.data; + console.log("allData", allData.value); + console.log("地区", area.value); } catch (error) { console.log("请求失败", error); // 在这里可以处理错误逻辑,比如显示错误提示等 } }; -getActivity(); +getGoods(); -// 这是查询货币的接口 -const currency = ref([]); -const getCurrency = async function () { +//这是查询用户金币信息的接口 +const userGold = ref({}); +const getUserGold = async function (jwcode) { try { - // 发送POST请求 const result = await axios.post( - "http://192.168.8.174:10010/rates/search", - {} + "http://192.168.8.147:10070/statistics/getMess/" + jwcode ); - - // 将响应结果存储到响应式数据中 - console.log("货币请求成功", result); - // 存储表格数据 - currency.value = result.data.data; - console.log("tableData", currency.value); - // 在这里可以根据需求进一步处理成功后的逻辑,比如更新UI显示成功消息等 + console.log("请求成功", result); + // 存储全部数据 + userGold.value = result.data.data; + console.log("userGold", userGold.value); } catch (error) { console.log("请求失败", error); - // 在这里可以处理错误逻辑,比如显示错误提示等 } }; -getCurrency(); -// 这是添加上传图片的接口 -const imageUrl = ref(""); +function calculateCoins() { + // 保存原始的allGold值 + const originalAllGold = addConsume.value.allGold; -// 上传图片成功的回调函数 -const handleAvatarSuccess = (response, uploadFile) => { - imageUrl.value = URL.createObjectURL(uploadFile.raw); - console.log("图片上传成功", response, uploadFile); - addConsume.value.rechargeVoucher = - "http://192.168.8.93:10010/upload/" + response.data; - console.log("图片名称", addConsume.value.rechargeVoucher); -}; -// 上传图片之前的校验函数 -const beforeAvatarUpload = (rawFile) => { - if (rawFile.type !== "image/jpeg") { - ElMessage.error("Avatar picture must be JPG format!"); - return false; - } else if (rawFile.size / 1024 / 1024 > 2) { - ElMessage.error("Avatar picture size can not exceed 2MB!"); - return false; - } - return true; -}; + // 确保todayTask和todayFree是有效的数字 + const todayTask = + typeof userGold.value.todayTask === "number" ? userGold.value.todayTask : 0; + const todayFree = + typeof userGold.value.todayFree === "number" ? userGold.value.todayFree : 0; -//充值方式条目 -const options = [ - { - value: "现金充值", - label: "现金充值", - }, - { - value: "龙鳞卡", - label: "龙鳞卡", - }, - { - value: "弘粉卡", - label: "弘粉卡", - }, -]; + // 根据用户输入的消费金币总数和已有的金币数量进行计算 + addConsume.value.taskCoin = Math.min(originalAllGold, todayTask); + let remainingGold = originalAllGold - addConsume.value.taskCoin; -const calculatedFreeGold = computed(() => { - return addConsume.value.paidGold * addConsume.value.activityId; -}); + addConsume.value.freeCoin = Math.min(remainingGold, todayFree); + remainingGold -= addConsume.value.freeCoin; -watch(calculatedFreeGold, (newVal) => { - addConsume.value.freeGold = newVal; -}); + addConsume.value.rechargeCoin = remainingGold; // 剩余的都算作充值金币 + + // 恢复allGold的原始值 + addConsume.value.allGold = originalAllGold; + + // 确保taskCoin, freeCoin, rechargeCoin不是NaN,如果是,则设置为0 + if (isNaN(addConsume.value.taskCoin)) addConsume.value.taskCoin = 0; + if (isNaN(addConsume.value.freeCoin)) addConsume.value.freeCoin = 0; + if (isNaN(addConsume.value.rechargeCoin)) addConsume.value.rechargeCoin = 0; + + console.log("计算结果", addConsume.value); +}