| @@ -2,6 +2,7 @@ | |||||
| "appid": "wx75cf14e3a0d45821", | |||||
| git commit -m "feat: " | git commit -m "feat: " | ||||
| git commit --no-verify -m "提交时的注释" 跳过检验 | git commit --no-verify -m "提交时的注释" 跳过检验 | ||||
| @@ -5,7 +5,7 @@ | |||||
| <script setup> | <script setup> | ||||
| import { onLaunch, onShow, onHide } from "@dcloudio/uni-app"; | import { onLaunch, onShow, onHide } from "@dcloudio/uni-app"; | ||||
| import { userInfoModules } from "@/store/modules/userInfo"; | import { userInfoModules } from "@/store/modules/userInfo"; | ||||
| import { loginApi } from "./api/login"; | |||||
| const userInfoModulesPinia = userInfoModules(); | const userInfoModulesPinia = userInfoModules(); | ||||
| onLaunch(() => { | onLaunch(() => { | ||||
| console.log("App Launch!"); | console.log("App Launch!"); | ||||
| @@ -14,7 +14,6 @@ onLaunch(() => { | |||||
| success: function (res) { | success: function (res) { | ||||
| let uniPlatform = ""; | let uniPlatform = ""; | ||||
| let osName = ""; | let osName = ""; | ||||
| if (res.uniPlatform == "web") { | if (res.uniPlatform == "web") { | ||||
| uniPlatform = 1; | uniPlatform = 1; | ||||
| } else if (res.uniPlatform == "mp-weixin") { | } else if (res.uniPlatform == "mp-weixin") { | ||||
| @@ -22,7 +21,6 @@ onLaunch(() => { | |||||
| } else if (res.uniPlatform == "mp-toutiao") { | } else if (res.uniPlatform == "mp-toutiao") { | ||||
| uniPlatform = 3; | uniPlatform = 3; | ||||
| } | } | ||||
| if (res.osName == "windows") { | if (res.osName == "windows") { | ||||
| osName = 1; | osName = 1; | ||||
| } else if (res.osName == "ios") { | } else if (res.osName == "ios") { | ||||
| @@ -41,6 +39,67 @@ onLaunch(() => { | |||||
| console.log(res.osName, osName, "System"); | console.log(res.osName, osName, "System"); | ||||
| }, | }, | ||||
| }); | }); | ||||
| // 微信登录授权 | |||||
| uni.login({ | |||||
| provider: "weixin", // 使用微信登录授权 | |||||
| success: async (res) => { | |||||
| console.log(res); | |||||
| if (res.code) { | |||||
| console.log(res.code); | |||||
| try { | |||||
| uni.showLoading({ | |||||
| title: "加载中...", | |||||
| mask: true, | |||||
| }); | |||||
| const data = { | |||||
| appId: "wx75cf14e3a0d45821", | |||||
| code: res.code, | |||||
| }; | |||||
| const res2 = await loginApi(data); | |||||
| userInfoModulesPinia.openId = res2.openId; | |||||
| uni.hideLoading(); | |||||
| if (res2.code == 200) { | |||||
| uni.redirectTo({ | |||||
| url: "pages/home/index", | |||||
| }); | |||||
| } else { | |||||
| // uni.redirectTo({ | |||||
| // url: "pages/index/index", | |||||
| // }); | |||||
| uni.showToast({ | |||||
| title: "登录失败,请重试", | |||||
| icon: "none", | |||||
| }); | |||||
| } | |||||
| } catch (error) { | |||||
| // uni.redirectTo({ | |||||
| // url: "pages/index/index", | |||||
| // }); | |||||
| uni.showToast({ | |||||
| title: "登录失败,请重试", | |||||
| icon: "none", | |||||
| }); | |||||
| } | |||||
| } else { | |||||
| // uni.redirectTo({ | |||||
| // url: "pages/index/index", | |||||
| // }); | |||||
| uni.showToast({ | |||||
| title: "登录失败,请重试", | |||||
| icon: "none", | |||||
| }); | |||||
| } | |||||
| }, | |||||
| fail: (err) => { | |||||
| // uni.redirectTo({ | |||||
| // url: "pages/index/index", | |||||
| // }); | |||||
| uni.showToast({ | |||||
| title: "登录失败,请重试", | |||||
| icon: "none", | |||||
| }); | |||||
| }, | |||||
| }); | |||||
| }); | }); | ||||
| onShow(() => { | onShow(() => { | ||||
| console.log("App Show!"); | console.log("App Show!"); | ||||
| @@ -5,4 +5,21 @@ export function voiceTotalApi() { | |||||
| url: `api/voiceMould/voiceTotal`, | url: `api/voiceMould/voiceTotal`, | ||||
| method: 'GET', | method: 'GET', | ||||
| }) | }) | ||||
| } | |||||
| // 微信登录 | |||||
| export function loginApi(data) { | |||||
| return request({ | |||||
| url: `api/miniApp/login`, | |||||
| method: 'POST', | |||||
| data | |||||
| }) | |||||
| } | |||||
| // 授权手机号登陆 | |||||
| export function loginPhoneApi(data) { | |||||
| return request({ | |||||
| url: `api/miniApp/loginPhone`, | |||||
| method: 'POST', | |||||
| data | |||||
| }) | |||||
| } | } | ||||
| @@ -37,7 +37,8 @@ | |||||
| <script setup> | <script setup> | ||||
| //#region 导入 | //#region 导入 | ||||
| import { ref, reactive } from "vue"; | import { ref, reactive } from "vue"; | ||||
| import { voiceTotalApi } from "../../api/login.js"; | |||||
| import { voiceTotalApi, loginPhoneApi } from "../../api/login.js"; | |||||
| //#endregion | //#endregion | ||||
| //#region 勾选 | //#region 勾选 | ||||
| @@ -48,12 +49,9 @@ const checkboxList1 = reactive([ | |||||
| disabled: false, | disabled: false, | ||||
| }, | }, | ||||
| ]); | ]); | ||||
| function toCreate() { | |||||
| async function toCreate() { | |||||
| if (checkboxValue1.value[0]) { | if (checkboxValue1.value[0]) { | ||||
| handleLogin(); | |||||
| uni.redirectTo({ | |||||
| url: "/pages/uploadPhoto/uploadPhoto", | |||||
| }); | |||||
| await handleLogin(); | |||||
| } else { | } else { | ||||
| uni.showModal({ | uni.showModal({ | ||||
| title: "提示", | title: "提示", | ||||
| @@ -61,29 +59,31 @@ function toCreate() { | |||||
| success: function (res) { | success: function (res) { | ||||
| if (res.confirm) { | if (res.confirm) { | ||||
| handleLogin(); | handleLogin(); | ||||
| uni.redirectTo({ | |||||
| url: "/pages/uploadPhoto/uploadPhoto", | |||||
| }); | |||||
| } else if (res.cancel) { | } else if (res.cancel) { | ||||
| } | } | ||||
| }, | }, | ||||
| }); | }); | ||||
| } | } | ||||
| } | } | ||||
| function handleLogin() { | |||||
| uni.login({ | |||||
| provider: "weixin", // 使用微信登录授权 | |||||
| success: (res) => { | |||||
| console.log(res); | |||||
| if (res.code) { | |||||
| // 获取到微信授权登录的code,将code发送给后端 | |||||
| // this.loginWithCode(res.code); | |||||
| } else { | |||||
| console.log("登录失败:", res.errMsg); | |||||
| } | |||||
| const userInfo = ref(null); | |||||
| async function handleLogin() { | |||||
| // uni.getUserInfo({}); | |||||
| uni.getUserProfile({ | |||||
| desc: "用于完善用户信息", | |||||
| success: (res1) => { | |||||
| userInfo.value = res1.userInfo; | |||||
| console.log(res1); | |||||
| uni.showToast({ | |||||
| icon: "none", | |||||
| title: "获取成功", | |||||
| }); | |||||
| }, | }, | ||||
| fail: (err) => { | fail: (err) => { | ||||
| console.log("登录失败:", err.errMsg); | |||||
| console.log(err); | |||||
| uni.showToast({ | |||||
| icon: "none", | |||||
| title: "用户拒绝获取", | |||||
| }); | |||||
| }, | }, | ||||
| }); | }); | ||||
| } | } | ||||
| @@ -3,7 +3,7 @@ import { ref, reactive } from "vue"; | |||||
| export const userInfoModules = defineStore("userInfoStore", () => { | export const userInfoModules = defineStore("userInfoStore", () => { | ||||
| // state | // state | ||||
| const userInfo = ref(null) | const userInfo = ref(null) | ||||
| const openId = ref(null) | |||||
| /** | /** | ||||
| * @description:依托平台:(web、mp-weixin、mp-toutiao) | * @description:依托平台:(web、mp-weixin、mp-toutiao) | ||||
| * @example 平台名:"web-H5",枚举值:1 | * @example 平台名:"web-H5",枚举值:1 | ||||
| @@ -1,4 +1,5 @@ | |||||
| const BASE_URL = 'https://test.metavatar.cc/C/'; | const BASE_URL = 'https://test.metavatar.cc/C/'; | ||||
| // const BASE_URL = 'https://test.metavatar.cc/'; | |||||
| // 通用的网络请求函数,接收请求的URL和请求参数,返回一个Promise | // 通用的网络请求函数,接收请求的URL和请求参数,返回一个Promise | ||||
| const request = (requestObj) => { | const request = (requestObj) => { | ||||
| @@ -6,7 +7,7 @@ const request = (requestObj) => { | |||||
| uni.request({ | uni.request({ | ||||
| url: BASE_URL + requestObj.url, | url: BASE_URL + requestObj.url, | ||||
| method: requestObj.method, // 这里可以根据需要更改请求方法 | method: requestObj.method, // 这里可以根据需要更改请求方法 | ||||
| data: requestObj.params, | |||||
| data: requestObj.data, | |||||
| success: (res) => { | success: (res) => { | ||||
| if (res.statusCode === 200) { | if (res.statusCode === 200) { | ||||
| resolve(res.data) | resolve(res.data) | ||||