Browse Source

1

dev_YWQ
congzc 1 year ago
parent
commit
a02d0afaf8
7 changed files with 305 additions and 216 deletions
  1. +1
    -1
      README.md
  2. +1
    -2
      src/App.vue
  3. +3
    -3
      src/pages/closeStyle/multiplayer.vue
  4. +102
    -49
      src/pages/index/buyCoin.vue
  5. +11
    -11
      src/pages/index/index.vue
  6. +182
    -146
      src/pages/login/index.vue
  7. +5
    -4
      src/pages/uploadPhoto/uploadPhoto.vue

+ 1
- 1
README.md View File

@@ -1,6 +1,6 @@
# Suimang-wxapp

setStorageSync 键名
# setStorageSync 键名
userId --用户id,用于邀请分享功能
loginAwardCoin --注册奖励金币
inviteAwardCoin --邀请奖励金币


+ 1
- 2
src/App.vue View File

@@ -10,7 +10,6 @@ import { findImageApi, findGlodApi } from "./api/home";
const userInfoModulesPinia = userInfoModules();
onLaunch(() => {
console.log("App Launch!");
// 获取平台及系统信息
uni.getSystemInfo({
success: function (res) {
@@ -22,7 +21,7 @@ onLaunch(() => {
uni.setStorageSync("plat", 1);
uniPlatform = 2;
} else if (res.uniPlatform == "mp-toutiao") {
uni.setStorageSync("plat", 2);
uni.setStorageSync("plat", 3);
uniPlatform = 3;
}
if (res.osName == "windows") {


+ 3
- 3
src/pages/closeStyle/multiplayer.vue View File

@@ -200,7 +200,7 @@ function chooseImg(index) {
},
header: {
// Authorization: userInfoModulesPinia.token,
token: userInfoModulesPinia.token,
token: uni.getStorageSync("token"),
},
success: async (res2) => {
if (JSON.parse(res2.data).code != 200) {
@@ -221,7 +221,7 @@ function chooseImg(index) {
},
header: {
// Authorization: userInfoModulesPinia.token,
token: userInfoModulesPinia.token,
token: uni.getStorageSync("token"),
},
success: (res3) => {
if (JSON.parse(res3.data).code != 200) {
@@ -242,7 +242,7 @@ function chooseImg(index) {
},
header: {
"Content-Type": "multipart/form-data",
token: userInfoModulesPinia.token,
token: uni.getStorageSync("token"),
},
success: async (res4) => {
if (JSON.parse(res4.data).code != 200) {


+ 102
- 49
src/pages/index/buyCoin.vue View File

@@ -29,6 +29,7 @@ import {
} from "../../api/coin.js";
import { userInfoModules } from "@/store/modules/userInfo";
const userInfoModulesPinia = userInfoModules();
//#endregion ----------------------------------

const active = ref("");
const orderNumber = ref("");
@@ -78,7 +79,7 @@ const createProductPay = async (orderNumber) => {
const data = {
orderNumber,
openId,
payVendor: 1, //Number,1:微信;2:抖音
payVendor: userInfoModulesPinia.platForm == 2 ? 1 : 5, //Number,1:微信;5:抖音
};
const res = await createPay(data);
startPay(res.data);
@@ -90,54 +91,106 @@ const createProductPay = async (orderNumber) => {

// 拉起收银台
const startPay = (data) => {
const orderInfo = {
package: data.package,
nonceStr: data.nonceStr,
timeStamp: data.timeStamp,
paySign: data.paySign,
signType: data.signType,
};
console.log(orderInfo, "orderInfo");
uni.hideLoading();
uni.requestPayment({
provider: "wxpay", //固定值为"wxpay"
...orderInfo,
success: function (res) {
console.log(res, "res");
getStatusOfOrder(orderNumber.value).then((res) => {
console.log(res, "status");
if (res == 1) {
uni.showToast({
title: "支付取消",
icon: "exception",
});
} else if (res == 2) {
} else if (res == 3) {
uni.showToast({
title: "支付成功!",
icon: "success",
success() {
setTimeout(() => {
uni.navigateBack();
}, 2000);
},
});
} else if (res == 4) {
uni.showToast({
title: "支付取消",
icon: "exception",
});
}
});
},
fail: function (err) {
uni.showToast({
title: "支付失败!",
icon: "error",
});
console.log("支付失败", err);
},
});
let orderInfo = null;
if (userInfoModulesPinia.platForm == 2) {
orderInfo = {
package: data.package,
nonceStr: data.nonceStr,
timeStamp: data.timeStamp,
paySign: data.paySign,
signType: data.signType,
};
console.log(orderInfo, "orderInfo");
uni.hideLoading();
uni.requestPayment({
provider: "wxpay", //固定值为"wxpay"
...orderInfo,
success: function (res) {
console.log(res, "res");
getStatusOfOrder(orderNumber.value).then((res) => {
console.log(res, "status");
if (res == 1) {
uni.showToast({
title: "支付取消",
icon: "exception",
});
} else if (res == 2) {
} else if (res == 3) {
uni.showToast({
title: "支付成功!",
icon: "success",
success() {
setTimeout(() => {
uni.navigateBack();
}, 2000);
},
});
} else if (res == 4) {
uni.showToast({
title: "支付取消",
icon: "exception",
});
}
});
},
fail: function (err) {
uni.showToast({
title: "支付失败!",
icon: "fail",
});
console.log("支付失败", err);
},
});
}
// 抖音支付
else if (userInfoModulesPinia.platForm == 3) {
orderInfo = {
order_id: data.orderId,
order_token: data.token,
};
console.log(orderInfo, "orderInfo");
uni.hideLoading();
uni.requestPayment({
provider: "toutiao", //固定值为"wxpay"
orderInfo: orderInfo,
service: 5,
success: function (res) {
console.log(res, "res");
getStatusOfOrder(orderNumber.value).then((res) => {
console.log(res, "status");
if (res == 1) {
uni.showToast({
title: "支付取消",
icon: "exception",
});
} else if (res == 2) {
} else if (res == 3) {
uni.showToast({
title: "支付成功!",
icon: "success",
success() {
setTimeout(() => {
uni.navigateBack();
}, 2000);
},
});
} else if (res == 4) {
uni.showToast({
title: "支付取消",
icon: "exception",
});
}
});
},
fail: function (err) {
uni.showToast({
title: "支付失败!",
icon: "fail",
});
console.log("支付失败", err);
},
});
}
};

const getStatusOfOrder = async (orderNumber) => {


+ 11
- 11
src/pages/index/index.vue View File

@@ -256,17 +256,17 @@ function chooseAvatar() {
//#region 路由跳转
function goBuyCoin() {
if (userInfoModulesPinia.platForm == 3) {
uni.showToast({
title: "暂未开放",
icon: "none",
mask: true,
});
} else {
uni.navigateTo({
url: "/pages/index/buyCoin",
});
}
// if (userInfoModulesPinia.platForm == 3) {
// uni.showToast({
// title: "暂未开放",
// icon: "none",
// mask: true,
// });
// } else {
// }
uni.navigateTo({
url: "/pages/index/buyCoin",
});
}
function goLookPhoto(id, status) {


+ 182
- 146
src/pages/login/index.vue View File

@@ -205,6 +205,7 @@ async function dogetphonenumber(e) {
title: "获取成功",
});
userInfoModulesPinia.token = res2.data.token;
uni.setStorageSync("token", userInfoModulesPinia.token);
uni.switchTab({
url: "/pages/uploadPhoto/uploadPhoto",
});
@@ -465,180 +466,215 @@ const handleOpenPrivacyContract = () => {
//#region 初始化
const urlUid = ref(""); //通过邀请来的会携带邀请人ID参数
onLoad((options) => {
// 二维码扫描进入时
if (options.scene) {
const str = decodeURIComponent(options.scene);
const regex = /_u:(\d+)/; // 正则表达式匹配_u:后面的数字
const match = str.match(regex);
urlUid.value = match[1];
}
// 分享链接进入时
else if (options.userId) {
urlUid.value = options.userId;
} else {
urlUid.value = null;
}
console.log(urlUid.value, "邀请人id");
uni.hideHomeButton();
// workId.value = options.id;
// 获取平台及系统信息
uni.getSystemInfo({
success: function (res) {
let uniPlatform = "";
let osName = "";
if (res.uniPlatform == "web") {
uniPlatform = 1;
} else if (res.uniPlatform == "mp-weixin") {
uni.setStorageSync("plat", 1);
uniPlatform = 2;
} else if (res.uniPlatform == "mp-toutiao") {
uni.setStorageSync("plat", 3);
uniPlatform = 3;
}
if (res.osName == "windows") {
osName = 1;
} else if (res.osName == "ios") {
osName = 2;
} else if (res.osName == "android") {
osName = 3;
} else if (res.osName == "mac") {
osName = 4;
} else if (res.osName == "linux") {
osName = 5;
}

if (options.type == "tokenFfalse") {
uni.showToast({
title: "登录失效,请重新登录",
icon: "none",
});
}
// 已有token时直接登录
if (uni.getStorageSync("token")) {
uni.switchTab({ url: "/pages/uploadPhoto/uploadPhoto" });
}
userInfoModulesPinia.platForm = uniPlatform; // 平台
userInfoModulesPinia.hostSystem = osName; // 系统
console.log(res.uniPlatform, uniPlatform, "PlatForm");
console.log(res.osName, osName, "System");

// 原来的登录逻辑
// 二维码扫描进入时
if (options.scene) {
const str = decodeURIComponent(options.scene);
const regex = /_u:(\d+)/; // 正则表达式匹配_u:后面的数字
const match = str.match(regex);
urlUid.value = match[1];
}
// 分享链接进入时
else if (options.userId) {
urlUid.value = options.userId;
} else {
urlUid.value = null;
}
console.log(urlUid.value, "邀请人id");
uni.hideHomeButton();
// workId.value = options.id;

if (userInfoModulesPinia.platForm == 2) {
uni.login({
provider: "weixin", // 使用微信登录授权
success: async (res) => {
console.log(res, "uni.login");
if (res.code) {
try {
uni.showLoading({
title: "加载中...",
mask: true,
});
const data = {
appId: userInfoModulesPinia.getAppId(),
code: res.code,
};
const res2 = await loginApi(data);
userInfoModulesPinia.openId = res2.data.openId;
if (res2.data.token) {
userInfoModulesPinia.token = res2.data.token;
uni.setStorageSync("token", userInfoModulesPinia.token);
console.log(userInfoModulesPinia.openId, "获取openid");
// 获取头像和金币
const res3 = await findImageApi();
if (res3.data) {
uni.setStorageSync("userId", res3.data.id);
}
userInfoModulesPinia.myAvatar =
res3.data && res3.data.image ? res3.data.image : "";
const res4 = await findGlodApi();
if (res4.data) {
uni.setStorageSync("userId", res4.data.id);
}
if (!res4.data) {
userInfoModulesPinia.myGlod = 0;
} else {
userInfoModulesPinia.myGlod = res4.data.digitalAvatarResidueGlod
? res4.data.digitalAvatarResidueGlod
: 0;
}
uni.hideLoading();
if (res2.data.token) {
getPrivacySetting(1);
} else {
console.log("error1");
if (options.type == "tokenFfalse") {
uni.showToast({
title: "登录失效,请重新登录",
icon: "none",
});
}
// 已有token时直接登录
if (uni.getStorageSync("token")) {
uni.switchTab({ url: "/pages/uploadPhoto/uploadPhoto" });
}

if (userInfoModulesPinia.platForm == 2) {
uni.login({
provider: "weixin", // 使用微信登录授权
success: async (res) => {
console.log(res, "uni.login");
if (res.code) {
try {
uni.showLoading({
title: "加载中...",
mask: true,
});
const data = {
appId: userInfoModulesPinia.getAppId(),
code: res.code,
};
const res2 = await loginApi(data);
userInfoModulesPinia.openId = res2.data.openId;
if (res2.data.token) {
userInfoModulesPinia.token = res2.data.token;
uni.setStorageSync("token", userInfoModulesPinia.token);
console.log(userInfoModulesPinia.openId, "获取openid");
// 获取头像和金币
const res3 = await findImageApi();
if (res3.data) {
uni.setStorageSync("userId", res3.data.id);
}
userInfoModulesPinia.myAvatar =
res3.data && res3.data.image ? res3.data.image : "";
const res4 = await findGlodApi();
if (res4.data) {
uni.setStorageSync("userId", res4.data.id);
}
if (!res4.data) {
userInfoModulesPinia.myGlod = 0;
} else {
userInfoModulesPinia.myGlod = res4.data
.digitalAvatarResidueGlod
? res4.data.digitalAvatarResidueGlod
: 0;
}
uni.hideLoading();
if (res2.data.token) {
getPrivacySetting(1);
} else {
console.log("error1");
uni.showToast({
title: "登录失败,请重试",
icon: "none",
});
}
} else {
getPrivacySetting(2);
}
uni.hideLoading();
} catch (error) {
// uni.redirectTo({
// url: "pages/index/index",
// });
console.log(error, "error2");
uni.showToast({
title: "登录失败,请重试",
icon: "none",
});
}
} else {
getPrivacySetting(2);
// uni.redirectTo({
// url: "pages/index/index",
// });
console.log("error3");
uni.showToast({
title: "登录失败,请重试",
icon: "none",
});
}
uni.hideLoading();
} catch (error) {
},
fail: (err) => {
// uni.redirectTo({
// url: "pages/index/index",
// });
console.log(error, "error2");
console.log("error4");
uni.showToast({
title: "登录失败,请重试",
icon: "none",
});
}
} else {
// uni.redirectTo({
// url: "pages/index/index",
// });
console.log("error3");
uni.showToast({
title: "登录失败,请重试",
icon: "none",
});
}
},
fail: (err) => {
// uni.redirectTo({
// url: "pages/index/index",
// });
console.log("error4");
uni.showToast({
title: "登录失败,请重试",
icon: "none",
},
});
},
});
}
// 抖音头条授权
else if (userInfoModulesPinia.platForm == 3) {
uni.login({
provider: "toutiao", // 使用微信登录授权
success: async (res) => {
console.log(res, "uni.login");
if (res.code) {
try {
uni.showLoading({
title: "加载中...",
mask: true,
});
const data = {
appId: userInfoModulesPinia.getAppId(),
code: res.code,
};
const res2 = await loginApi(data);
userInfoModulesPinia.openId = res2.data.openId;
if (res2.data.token) {
userInfoModulesPinia.token = res2.data.token;
// uni.setStorageSync("token", userInfoModulesPinia.token);
console.log(userInfoModulesPinia.openId, "获取openid");
uni.hideLoading();
}
// 抖音头条授权
else if (userInfoModulesPinia.platForm == 3) {
uni.login({
provider: "toutiao", // 使用微信登录授权
success: async (res) => {
console.log(res, "uni.login");
if (res.code) {
try {
uni.showLoading({
title: "加载中...",
mask: true,
});
const data = {
appId: userInfoModulesPinia.getAppId(),
code: res.code,
};
const res2 = await loginApi(data);
userInfoModulesPinia.openId = res2.data.openId;
if (res2.data.token) {
userInfoModulesPinia.token = res2.data.token;
// uni.setStorageSync("token", userInfoModulesPinia.token);
console.log(userInfoModulesPinia.openId, "获取openid");
uni.hideLoading();
} else {
uni.hideLoading();
// uni.redirectTo({
// url: "/pages/login/index",
// });
console.log("error1");
uni.showToast({
title: "登录失败,请重试",
icon: "none",
});
}
uni.hideLoading();
} catch (error) {
uni.hideLoading();
console.log(error, "error2");
uni.showToast({
title: "登录失败,请重试",
icon: "none",
});
}
} else {
uni.hideLoading();
// uni.redirectTo({
// url: "/pages/login/index",
// });
console.log("error1");
console.log("error3");
uni.showToast({
title: "登录失败,请重试",
icon: "none",
});
}
uni.hideLoading();
} catch (error) {
uni.hideLoading();
console.log(error, "error2");
},
fail: (err) => {
console.log("error4");
uni.showToast({
title: "登录失败,请重试",
icon: "none",
});
}
} else {
console.log("error3");
uni.showToast({
title: "登录失败,请重试",
icon: "none",
});
}
},
fail: (err) => {
console.log("error4");
uni.showToast({
title: "登录失败,请重试",
icon: "none",
},
});
},
});
}
}
},
});
});
//#endregion ---------------------------------



+ 5
- 4
src/pages/uploadPhoto/uploadPhoto.vue View File

@@ -117,7 +117,7 @@ const showImgUrl2 = ref(null); //回显路径 未压缩
// 点击上传图片或打开相机
function chooseImage() {
// 检查token
if (!userInfoModulesPinia.token) {
if (!uni.getStorageSync("token")) {
uni.showModal({
title: "提示",
content: "登录以体验完整功能",
@@ -178,7 +178,7 @@ function chooseImage() {
// console.log(userInfoModulesPinia.token, "token");
async function toCloseStyle() {
// 检查token
if (!userInfoModulesPinia.token) {
if (!uni.getStorageSync("token")) {
uni.showModal({
title: "提示",
content: "登录以体验完整功能",
@@ -220,7 +220,7 @@ async function toCloseStyle() {
},
header: {
// Authorization: userInfoModulesPinia.token,
token: userInfoModulesPinia.token,
token: uni.getStorageSync("token"),
},
success: (res0) => {
if (JSON.parse(res0.data).code != 200) {
@@ -238,7 +238,7 @@ async function toCloseStyle() {
},
header: {
// Authorization: userInfoModulesPinia.token,
token: userInfoModulesPinia.token,
token: uni.getStorageSync("token"),
},
success: (res) => {
if (JSON.parse(res.data).code != 200) {
@@ -499,6 +499,7 @@ onLoad((options) => {
uni.hideLoading();
} else {
uni.hideLoading();
uni.setStorageSync("token", null);
uni.redirectTo({
url: "/pages/login/index",
});


Loading…
Cancel
Save