Selaa lähdekoodia

upload

master
HolyKnightIX 1 vuosi sitten
vanhempi
commit
a0e1caed60
3 muutettua tiedostoa jossa 44 lisäystä ja 8 poistoa
  1. +1
    -1
      src/api/coin.js
  2. +38
    -6
      src/pages/index/buyCoin.vue
  3. +5
    -1
      src/store/modules/userInfo.js

+ 1
- 1
src/api/coin.js Näytä tiedosto

@@ -28,7 +28,7 @@ export function createOrder(productId) {
} }


/** /**
* @description:获取收银台数据
* @description:获取订单数据
* @param data * @param data
* @return: data * @return: data
*/ */


+ 38
- 6
src/pages/index/buyCoin.vue Näytä tiedosto

@@ -22,9 +22,9 @@
//#region 导入 //#region 导入
import { ref, reactive } from "vue"; import { ref, reactive } from "vue";
import { getCoinList, createOrder, createPay } from "../../api/coin.js"; import { getCoinList, createOrder, createPay } from "../../api/coin.js";
//#endregion --------------
import { userInfoModules } from "@/store/modules/userInfo";
const userInfoModulesPinia = userInfoModules();


//#region 列表数据
const active = ref(""); const active = ref("");
const coinList = ref([]); const coinList = ref([]);
function select(item) { function select(item) {
@@ -36,6 +36,7 @@ const goPro = () => {
}); });
}; };


// 获取金币价格列表
const getList = async () => { const getList = async () => {
try { try {
const res = await getCoinList(5, 1); const res = await getCoinList(5, 1);
@@ -46,25 +47,56 @@ const getList = async () => {
} }
}; };


// 创建订单
const createProductOrder = async () => { const createProductOrder = async () => {
try { try {
const res = await createOrder(1); const res = await createOrder(1);
console.log(res, "res");
// createProductPay()
console.log(res.data, "res");
createProductPay(res.data);
} catch (error) { } catch (error) {
console.log(error, "error"); console.log(error, "error");
} }
}; };


const createProductPay = async () => {
// 获取订单数据
const createProductPay = async (orderNumber) => {
const openId = userInfoModulesPinia.openId;
try { try {
const res = await createPay(1);
const data = {
orderNumber,
openId,
payVendor: 1, //Number,1:微信;2:抖音
};
const res = await createPay(data);
console.log(res, "res"); console.log(res, "res");
} catch (error) { } catch (error) {
console.log(error, "error"); console.log(error, "error");
} }
}; };


// 拉起收银台
const startPay = (data) => {
var orderInfo = {
appid: "wx499********7c70e",
partnerid: "148*****52",
prepayid: "wx202254********************fbe90000",
package: "Sign=WXPay",
noncestr: "c5sEwbaNPiXAF3iv",
timestamp: 1597935292,
sign: "A842B45937F6EFF60DEC7A2EAA52D5A0",
};
uni.requestPayment({
provider: "wxpay", //固定值为"wxpay"
orderInfo: orderInfo,
success: function (res) {
console.log(res, "res");
},
fail: function (err) {
console.log("支付失败", err);
},
});
};

getList(); getList();
</script> </script>




+ 5
- 1
src/store/modules/userInfo.js Näytä tiedosto

@@ -1,5 +1,9 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { ref, reactive } from "vue"; import { ref, reactive } from "vue";
/**
* @description:用户信息持久化数据
*/
export const userInfoModules = defineStore("userInfoStore", () => { export const userInfoModules = defineStore("userInfoStore", () => {
// state // state
const userInfo = ref(null) const userInfo = ref(null)
@@ -31,7 +35,7 @@ export const userInfoModules = defineStore("userInfoStore", () => {
function loginOut(params) { function loginOut(params) {
} }
return { userInfo, platForm, hostSystem, getUserInfo, loginOut };
return { userInfo, openId, platForm, hostSystem, getUserInfo, loginOut };
}, },
{ {
persist: true, persist: true,

Ladataan…
Peruuta
Tallenna