微信小程序一键登录
This commit is contained in:
1 parent
955c13429a
commit
f31015deb0
12 files changed
+132
-86
No files matched your search
+7
-7
@@ -16,13 +16,6 @@
|
||||
"disableScroll": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/root/login",
|
||||
"style": {
|
||||
"navigationBarTitleText": "登录",
|
||||
"disableScroll": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/tabbar/order",
|
||||
"style": {
|
||||
@@ -36,6 +29,13 @@
|
||||
"navigationBarTitleText": "我的",
|
||||
"disableScroll": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/root/login",
|
||||
"style": {
|
||||
"navigationBarTitleText": "登录",
|
||||
"disableScroll": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"globalStyle": {
|
||||
|
||||
+51
-47
@@ -1,73 +1,59 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive } from "vue"
|
||||
import { onLoad, onShow } from "@dcloudio/uni-app"
|
||||
import { onShow } from "@dcloudio/uni-app"
|
||||
import { constant, router } from "@@/index"
|
||||
import { userApi } from "@@/api"
|
||||
import { userApi, miniPlatformApi } from "@@/api"
|
||||
import { getAppInfo } from "@@/utils/app"
|
||||
|
||||
import AffirmCheck from "@/sheep/components/common/affirm-check.vue"
|
||||
import AffirmModal from "@/sheep/components/common/affirm-modal.vue"
|
||||
import ServiceText from "@/sheep/components/common/service-text.vue"
|
||||
|
||||
const affirmModalRef = ref()
|
||||
const state = reactive<any>({
|
||||
userInfo: null,
|
||||
isAgree: false,
|
||||
})
|
||||
const applyForm = reactive<any>({
|
||||
username: "",
|
||||
password: "",
|
||||
|
||||
loginErrorVisible: false,
|
||||
loginErrorCode: null,
|
||||
})
|
||||
|
||||
onLoad(() => {
|
||||
const rememberUser = uni.getStorageSync(constant.storageConstant.REMEMBER_USER)
|
||||
if (rememberUser) {
|
||||
applyForm.username = rememberUser.username
|
||||
applyForm.password = rememberUser.password
|
||||
}
|
||||
})
|
||||
const serviceTextRef = ref<any>(null)
|
||||
|
||||
onShow(() => {
|
||||
const userInfoKey = constant.storageConstant.USERINFO
|
||||
state.userInfo = uni.getStorageSync(userInfoKey)
|
||||
})
|
||||
|
||||
|
||||
const applyFormRef = ref<any>(null)
|
||||
const doSubmit = async () => {
|
||||
applyFormRef.value.submit()
|
||||
const { isPass } = applyFormRef.value.validate()
|
||||
if (!isPass) return
|
||||
const tokenKey = constant.storageConstant.TOKEN
|
||||
const userInfoKey = constant.storageConstant.USERINFO
|
||||
const rememberUser = constant.storageConstant.REMEMBER_USER
|
||||
uni.removeStorageSync(tokenKey)
|
||||
uni.showLoading({ title: "登录中...", mask: true })
|
||||
const res: any = await userApi.login({
|
||||
...applyForm,
|
||||
grant_type: "password",
|
||||
scope: "server",
|
||||
})
|
||||
if (res.code != 0) {
|
||||
uni.showToast({ title: res.msg + ",登录失败,请重新登录", icon: "error" })
|
||||
return
|
||||
}
|
||||
uni.setStorageSync(tokenKey, res.data)
|
||||
const { data: userData } = await userApi.userInfo()
|
||||
uni.setStorageSync(userInfoKey, userData)
|
||||
uni.setStorageSync(rememberUser, {
|
||||
username: applyForm.username,
|
||||
password: applyForm.password,
|
||||
} as GlobalSetting.RememberUser)
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: "登录成功", icon: "none" })
|
||||
router.jump("/pages/tabbar/canteen")
|
||||
}
|
||||
|
||||
// 小程序获取手机号
|
||||
const minAppGetphone = (e) => {
|
||||
const minAppGetphone = async (e) => {
|
||||
const phoneDetail = e?.detail
|
||||
if (!phoneDetail) {
|
||||
uni.showToast({ title: "获取手机号失败", icon: "none" })
|
||||
return
|
||||
}
|
||||
try {
|
||||
uni.showLoading({ title: '登录中...', mask: true })
|
||||
// 获取用户手机号
|
||||
const { data, code }: any = await miniPlatformApi.autoAdminLogin({
|
||||
miniPlatformType: await getAppInfo(),
|
||||
code: phoneDetail.code,
|
||||
})
|
||||
if (data.errorCode) {
|
||||
state.loginErrorCode = data.errorCode
|
||||
state.loginErrorVisible = true
|
||||
uni.hideLoading()
|
||||
return
|
||||
}
|
||||
const { data: userData } = await userApi.userInfo()
|
||||
uni.setStorageSync(constant.storageConstant.USERINFO, userData)
|
||||
uni.setStorageSync(constant.storageConstant.TOKEN, data)
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: "登录成功", icon: "success" })
|
||||
router.jump("/pages/tabbar/canteen")
|
||||
} catch (error) {
|
||||
console.error("登录错误", error);
|
||||
}
|
||||
}
|
||||
|
||||
// 没有授权点击登录
|
||||
@@ -79,6 +65,9 @@ const doLogin = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const affirmConfirm = () => {
|
||||
state.isAgree = true
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
@@ -103,7 +92,22 @@ const doLogin = () => {
|
||||
</view>
|
||||
|
||||
<affirm-check v-model="state.isAgree" class="absolute bottom-30rpx" />
|
||||
<affirm-modal ref="affirmModalRef" @confirm="state.isAgree = true" />
|
||||
<affirm-modal ref="affirmModalRef" @confirm="affirmConfirm" />
|
||||
<service-text ref="serviceTextRef" :showPhoneText="false" />
|
||||
<tm-modal :show="state.loginErrorVisible" title="登录错误" cancelText="取消" confirmText="联系客服" height="auto"
|
||||
@close="state.loginErrorVisible = false" @confirm="serviceTextRef?.openModal?.()">
|
||||
<view class="px-20rpx bottom-40rpx">
|
||||
<view v-if="state.loginErrorCode == '10'" class="sub-text-26">
|
||||
<text>登录错误,获取本机微信手机号失败,请联系客服</text>
|
||||
</view>
|
||||
<view v-if="state.loginErrorCode == '20'" class="sub-text-26">
|
||||
<text>登录错误,本系统只为浦江县机关事务服务,如有疑问请联系客服</text>
|
||||
</view>
|
||||
<view v-if="state.loginErrorCode == '30'" class="sub-text-26">
|
||||
<text>登录错误,请联系客服</text>
|
||||
</view>
|
||||
</view>
|
||||
</tm-modal>
|
||||
</crud-layout>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -16,14 +16,16 @@ const state = reactive<any>({
|
||||
|
||||
onLoad(() => {
|
||||
const app = getApp({ allowDefault: true })
|
||||
console.log("app:", app);
|
||||
|
||||
app._initTabbar()
|
||||
if (app._initTabbar) {
|
||||
app._initTabbar()
|
||||
}
|
||||
})
|
||||
|
||||
onShow(() => {
|
||||
const app = getApp({ allowDefault: true })
|
||||
app._initTabbar()
|
||||
if (app._initTabbar) {
|
||||
app._initTabbar()
|
||||
}
|
||||
reportPageAccess("pages/tabbar/canteen")
|
||||
if (pageRef.value) {
|
||||
pageRef.value.reload(false)
|
||||
|
||||
+14
-13
@@ -1,6 +1,5 @@
|
||||
<template>
|
||||
<crud-layout title="我的" mainIsScroll bg="/static/page/blue-bg.png" navRightIcon="setting"
|
||||
@navRightClick="onNavRightClick">
|
||||
<crud-layout title="我的" mainIsScroll bg="/static/page/blue-bg.png">
|
||||
<template #main-top>
|
||||
<view class="flex items-center py-3 mx-30rpx">
|
||||
<image v-if="state.userInfo?.sysUser?.avatar && false" class="size-100rpx rounded-full"
|
||||
@@ -18,7 +17,7 @@
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<view class="mt-10rpx rounded-20rpx shadow-main p-30rpx pb-40rpx bg-white">
|
||||
<view class="mt-30rpx rounded-20rpx shadow-main p-30rpx pb-40rpx bg-white">
|
||||
<view class="service_item flex items-center justify-between" v-for="(v, i) in state.menuList" :key="i"
|
||||
@tap="onTabMenu(v)">
|
||||
<view class="flex-row-center">
|
||||
@@ -71,12 +70,12 @@ const state = reactive<any>({
|
||||
wallet: [],
|
||||
userInfo: {},
|
||||
menuList: [
|
||||
// { text: "扫一扫", icon: "/static/icon/scan.png", path: "" },
|
||||
{ text: "钱包", icon: "/static/icon/service_3.png", path: "/pages/wallet/list" },
|
||||
{ text: "喜好", icon: "/static/icon/service_4.png", path: "/pages/tabbar/canteenAnalyse" },
|
||||
// { text: "我的人脸", icon: "/static/icon/service_5.png", path: "/pages/human-face/list" },
|
||||
{ text: "赚米", icon: "/static/icon/service_7.png", path: "/pages/ad/make-money" },
|
||||
// { text: "车辆管理", icon: "/static/icon/service_6.png", path: "/pages/car/user-car/list" },
|
||||
{ text: "扫一扫", icon: "/static/icon/scan.png", path: "" },
|
||||
{ text: "我参加的活动", icon: "/static/icon/act.png", path: "/pages/merchant/my-act-list" },
|
||||
{ text: "我的钱包", icon: "/static/icon/service_3.png", path: "/pages/wallet/list" },
|
||||
{ text: "我的人脸", icon: "/static/icon/service_5.png", path: "/pages/human-face/list" },
|
||||
{ text: "车辆管理", icon: "/static/icon/service_6.png", path: "/pages/car/user-car/list" },
|
||||
{ text: "清除缓存", icon: "/static/icon/clear-storage.png", path: "" },
|
||||
],
|
||||
appInfo: "",
|
||||
actModalShow: false,
|
||||
@@ -339,7 +338,9 @@ const initMenuConfig = () => {
|
||||
|
||||
onLoad(async () => {
|
||||
const app = getApp({ allowDefault: true })
|
||||
app._initTabbar()
|
||||
if (app._initTabbar) {
|
||||
app._initTabbar()
|
||||
}
|
||||
// 初始化配置菜单
|
||||
initMenuConfig()
|
||||
// 获取应用信息
|
||||
@@ -352,12 +353,12 @@ onLoad(async () => {
|
||||
})
|
||||
onShow(() => {
|
||||
const app = getApp({ allowDefault: true })
|
||||
app._initTabbar()
|
||||
if (app._initTabbar) {
|
||||
app._initTabbar()
|
||||
}
|
||||
reportPageAccess("pages/tabbar/my")
|
||||
// 获取存储中的用户信息
|
||||
storage.getUserInfo()
|
||||
// 刷新用户
|
||||
app._getUserInfo()
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -17,12 +17,16 @@ const state = reactive<any>({
|
||||
|
||||
onLoad(() => {
|
||||
const app = getApp({ allowDefault: true })
|
||||
app._initTabbar()
|
||||
if (app._initTabbar) {
|
||||
app._initTabbar()
|
||||
}
|
||||
})
|
||||
|
||||
onShow(() => {
|
||||
const app = getApp({ allowDefault: true })
|
||||
app._initTabbar()
|
||||
if (app._initTabbar) {
|
||||
app._initTabbar()
|
||||
}
|
||||
reportPageAccess("pages/tabbar/canteen")
|
||||
if (pageRef.value) {
|
||||
pageRef.value.reload(false)
|
||||
|
||||
@@ -5,6 +5,7 @@ export { default as boxesApi } from "./boxes"
|
||||
export { default as faceApi } from "./face"
|
||||
export { default as foodApi } from "./food"
|
||||
export { default as merchantApi } from "./merchant"
|
||||
export { default as miniPlatformApi } from "./mini-platform"
|
||||
export { default as orderApi } from "./order"
|
||||
export { default as payApi } from "./pay"
|
||||
export { default as productApi } from "./product"
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import request from "@/sheep/utils/request"
|
||||
|
||||
type AutoAdminLoginDto = {
|
||||
miniPlatformType?: string
|
||||
code?: string
|
||||
}
|
||||
|
||||
export default {
|
||||
autoAdminLogin: (data: AutoAdminLoginDto) =>
|
||||
request({
|
||||
url: "/third/third-mini-app-oath/auto-admin-login",
|
||||
method: "POST",
|
||||
data,
|
||||
}),
|
||||
}
|
||||
@@ -3,6 +3,13 @@ import { reactive } from "vue"
|
||||
|
||||
import { useMakePhoneCall } from "@@/hooks"
|
||||
|
||||
const props = defineProps({
|
||||
showPhoneText: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
})
|
||||
|
||||
const state = reactive<any>({
|
||||
showModal: false,
|
||||
phoneList: ['15557321501']
|
||||
@@ -16,11 +23,19 @@ const doPhone = (v: string) => {
|
||||
useMakePhoneCall(v)
|
||||
}
|
||||
|
||||
const openModal = () => {
|
||||
state.showModal = true
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
openModal,
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view>
|
||||
<view class="w-full second-text-26 text-center mb-2 mt-10" @tap="doServiceText">
|
||||
<view v-if="showPhoneText" class="w-full second-text-26 text-center mb-2 mt-10" @tap="doServiceText">
|
||||
<text>联系热线</text>
|
||||
</view>
|
||||
<tm-drawer :show="state.showModal" title="联系热线" size="30%" position="bottom" @close="state.showModal = false">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export default {
|
||||
// 微信小程序
|
||||
WECHAT: "wechat",
|
||||
WECHAT: "WECHAT",
|
||||
// 支付宝
|
||||
ALI_PAY: "ali_pay",
|
||||
ALI_PAY: "ALI_PAY",
|
||||
} as const
|
||||
@@ -55,6 +55,12 @@ const actCancelStatusEnum = {
|
||||
"3": "已过期",
|
||||
}
|
||||
|
||||
const errorMsginiPlatformLoginErrorEnum = {
|
||||
"10": "获取手机号错误",
|
||||
"20": "用户不存在",
|
||||
"30": "登录错误",
|
||||
}
|
||||
|
||||
export default {
|
||||
hardwareOrderStatusEnum,
|
||||
hardwareOrderTypeEnum,
|
||||
@@ -64,4 +70,5 @@ export default {
|
||||
hardwareRefundStatusEnum,
|
||||
carTypeEnum,
|
||||
actCancelStatusEnum,
|
||||
errorMsginiPlatformLoginErrorEnum,
|
||||
}
|
||||
@@ -52,9 +52,13 @@ export const usePage = (ref: any = null, fn: Function | null = null, sticky = nu
|
||||
}
|
||||
let _arr = res
|
||||
for (let key of struct.split(".")) {
|
||||
if (_arr == null) {
|
||||
break
|
||||
}
|
||||
_arr = _arr[key]
|
||||
}
|
||||
setPage(_arr)
|
||||
const list = Array.isArray(_arr) ? _arr : (_arr?.records ?? [])
|
||||
setPage(list)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
setPage([])
|
||||
|
||||
@@ -20,17 +20,10 @@ const SKIP_REFRESH_TOKEN = ["/sys/auth/refresh-token", "/auth/token/check_token"
|
||||
|
||||
let refreshTokenLock = true
|
||||
|
||||
// 创建https请求实例
|
||||
let baseUrl = ""
|
||||
// #ifdef WEB
|
||||
baseUrl = import.meta.env.VITE_API_URL
|
||||
// #endif
|
||||
// #ifndef WEB
|
||||
baseUrl = getBaseApiUrl()
|
||||
// #endif
|
||||
console.log("getBaseApiUrl:", getBaseApiUrl())
|
||||
|
||||
const https = new Request({
|
||||
baseURL: baseUrl,
|
||||
baseURL: getBaseApiUrl(),
|
||||
timeout: 15000,
|
||||
method: "GET",
|
||||
header: {
|
||||
|
||||
Reference in new issue
Block a user