| | |
| | | import { computed, ref } from "vue"; |
| | | import { onShow } from "@dcloudio/uni-app"; |
| | | import { useCool, useStore, useWx } from "/@/cool"; |
| | | import { phoneAuthState } from "/@/cool/mini-login"; |
| | | import { useUi } from "/$/cool-ui"; |
| | | |
| | | const authState = ((globalThis as any).__phoneAuthState ||= { dismissed: false }); |
| | | const authState = phoneAuthState(); |
| | | |
| | | const { service, router } = useCool(); |
| | | const { user } = useStore(); |
| | |
| | | |
| | | const visible = computed(() => { |
| | | tick.value; |
| | | return !authState.dismissed && !user.info?.phone; |
| | | return authState.ready && !authState.dismissed && (!user.token || !user.info?.phone); |
| | | }); |
| | | |
| | | function later() { |
| | |
| | | submitting.value = true; |
| | | ui.showLoading(); |
| | | |
| | | const payload = phonePayload(detail); |
| | | const task = user.token |
| | | ? service.user.info.miniPhone(payload).then(async (phone: string) => { |
| | | const info = user.info || (await service.user.info.person()); |
| | | if (info) { |
| | | user.set({ ...info, phone }); |
| | | } |
| | | return phone; |
| | | }) |
| | | : service.user.login.miniPhone(payload).then(async (res) => { |
| | | user.setToken(res); |
| | | const info = await service.user.info.person(); |
| | | if (info) { |
| | | user.set(info); |
| | | } |
| | | return info?.phone as string | undefined; |
| | | const task = new Promise<string>((resolve) => { |
| | | uni.login({ |
| | | provider: "weixin", |
| | | success: (res) => resolve(res.code || ""), |
| | | fail: () => resolve(""), |
| | | }); |
| | | }) |
| | | .then((loginCode) => { |
| | | return service.user.login.miniPhone({ |
| | | ...phonePayload(detail), |
| | | loginCode, |
| | | }); |
| | | }) |
| | | .then(async (res) => { |
| | | user.setToken(res); |
| | | let info = user.info; |
| | | try { |
| | | info = (await service.user.info.person()) || info; |
| | | } catch (err) { |
| | | console.error(err); |
| | | } |
| | | const phone = info?.phone || res.phone; |
| | | user.set({ |
| | | ...(info || {}), |
| | | phone, |
| | | }); |
| | | return phone as string | undefined; |
| | | }); |
| | | |
| | | task |
| | | .then((phone) => { |