diff --git a/src/apis.js b/src/apis.js index 9375928..2f32381 100644 --- a/src/apis.js +++ b/src/apis.js @@ -162,13 +162,14 @@ export const getProvinceData = () => { return request("GET", "/index/provinces/list"); }; -export const loginAPI = async (nickName, avatarData, code) => { +export const loginAPI = async (phone, nickName, avatarData, code) => { const result = await request("POST", "/index/code", { appName: "shoot", appId: "wxa8f5989dcd45cc23", nickName, avatarData, code, + phone, }); uni.setStorageSync( `${uni.getAccountInfoSync().miniProgram.envVersion}_token`, @@ -519,3 +520,7 @@ export const addNoteAPI = async (id, remark) => { export const removePointRecord = async (id) => { return request("DELETE", `/user/score/sheet/delete?id=${id}`); }; + +export const getPhoneNumberAPI = (data) => { + return request("POST", "/index/getPhone", data); +}; diff --git a/src/components/SModal.vue b/src/components/SModal.vue index e963ec5..1ebedb6 100644 --- a/src/components/SModal.vue +++ b/src/components/SModal.vue @@ -7,7 +7,7 @@ const props = defineProps({ }, height: { type: String, - default: "260px", + default: "630rpx", }, onClose: { type: Function, @@ -56,12 +56,9 @@ watch( > - - - @@ -94,14 +91,4 @@ watch( position: absolute; z-index: -1; } -.close-btn { - display: flex; - justify-content: flex-end; - position: absolute; - right: 0; -} -.close-btn > image { - width: 40px; - height: 40px; -} diff --git a/src/components/Signin.vue b/src/components/Signin.vue index abfad4e..b9d7e39 100644 --- a/src/components/Signin.vue +++ b/src/components/Signin.vue @@ -3,7 +3,14 @@ import { ref } from "vue"; import { onShow } from "@dcloudio/uni-app"; import Avatar from "@/components/Avatar.vue"; import SButton from "@/components/SButton.vue"; -import { getMyDevicesAPI, loginAPI, getHomeData } from "@/apis"; + +import { wxLogin } from "@/util"; +import { + getMyDevicesAPI, + loginAPI, + getHomeData, + getPhoneNumberAPI, +} from "@/apis"; import useStore from "@/store"; const store = useStore(); const { updateUser, updateDevice } = store; @@ -18,6 +25,7 @@ const props = defineProps({ }, }); const agree = ref(false); +const phone = ref(""); const avatarUrl = ref(""); const nickName = ref(""); const loading = ref(false); @@ -25,6 +33,17 @@ const handleAgree = () => { agree.value = !agree.value; }; +async function getphonenumber(e) { + if (e.detail.code) { + const wxResult = await wxLogin(); + const result = await getPhoneNumberAPI({ + ...e.detail, + code: wxResult.code, + }); + if (result.phone) phone.value = result.phone; + } +} + function onChooseAvatar(e) { avatarUrl.value = e.detail.avatarUrl; } @@ -33,8 +52,14 @@ function onNicknameChange(e) { nickName.value = e.detail.value; } -const handleLogin = () => { +const handleLogin = async () => { if (loading.value) return; + if (!phone.value) { + return uni.showToast({ + title: "请获取手机号", + icon: "none", + }); + } if (!avatarUrl.value) { return uni.showToast({ title: "请选择头像", @@ -54,34 +79,24 @@ const handleLogin = () => { }); } loading.value = true; - uni.login({ - provider: "weixin", - success: async (loginRes) => { - const { code } = loginRes; - const fileManager = uni.getFileSystemManager(); - const avatarBase64 = fileManager.readFileSync(avatarUrl.value, "base64"); - const base64Url = `data:image/png;base64,${avatarBase64}`; - const result = await loginAPI(nickName.value, base64Url, code); - const data = await getHomeData(); - if (data.user) updateUser(data.user); - const devices = await getMyDevicesAPI(); - if (devices.bindings && devices.bindings.length) { - updateDevice( - devices.bindings[0].deviceId, - devices.bindings[0].deviceName - ); - } - props.onClose(); - }, - fail: (err) => { - loading.value = false; - uni.showToast({ - title: "登录失败", - icon: "none", - }); - console.error("登录失败:", err); - }, - }); + const wxResult = await wxLogin(); + const fileManager = uni.getFileSystemManager(); + const avatarBase64 = fileManager.readFileSync(avatarUrl.value, "base64"); + const base64Url = `data:image/png;base64,${avatarBase64}`; + const result = await loginAPI( + phone.value, + nickName.value, + base64Url, + wxResult.code + ); + const data = await getHomeData(); + if (data.user) updateUser(data.user); + const devices = await getMyDevicesAPI(); + if (devices.bindings && devices.bindings.length) { + updateDevice(devices.bindings[0].deviceId, devices.bindings[0].deviceName); + } + loading.value = false; + props.onClose(); }; const openServiceLink = () => { @@ -111,6 +126,21 @@ onShow(() => {