微信小程序发布试用版本
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
mutations
|
||||
} from '@/uni_modules/uni-id-pages/common/store.js'
|
||||
} from '@/common/store.js'
|
||||
import config from '@/uni_modules/uni-id-pages/config.js'
|
||||
const mixin = {
|
||||
data() {
|
||||
|
||||
@@ -1,193 +0,0 @@
|
||||
import pagesJson from '@/pages.json'
|
||||
import config from '@/uni_modules/uni-id-pages/config.js'
|
||||
import { getApiUrl } from '@/common/config.js'
|
||||
|
||||
const db = uniCloud.database();
|
||||
const usersTable = db.collection('uni-id-users')
|
||||
|
||||
let hostUserInfo = uni.getStorageSync('uni-id-pages-userInfo')||{}
|
||||
|
||||
const data = {
|
||||
userInfo: hostUserInfo,
|
||||
hasLogin: Object.keys(hostUserInfo).length != 0
|
||||
}
|
||||
|
||||
// 定义 mutations, 修改属性
|
||||
export const mutations = {
|
||||
// data不为空,表示传递要更新的值(注意不是覆盖是合并),什么也不传时,直接查库获取更新
|
||||
async updateUserInfo(data = false) {
|
||||
if (data) {
|
||||
usersTable.where('_id==$env.uid').update(data).then(e => {
|
||||
// console.log(e);
|
||||
if (e.result.updated) {
|
||||
uni.showToast({
|
||||
title: "更新成功",
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
});
|
||||
this.setUserInfo(data)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: "没有改变",
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
} else {
|
||||
// 不等待联网查询,立即更新用户_id确保store.userInfo中的_id是最新的
|
||||
const _id = uniCloud.getCurrentUserInfo().uid
|
||||
this.setUserInfo({_id},{cover:true})
|
||||
// 查库获取用户信息,更新store.userInfo
|
||||
const uniIdCo = uniCloud.importObject("uni-id-co", {
|
||||
customUI: true
|
||||
})
|
||||
try {
|
||||
let res = await usersTable.where("'_id' == $cloudEnv_uid")
|
||||
.field('mobile,nickname,username,email,avatar_file')
|
||||
.get()
|
||||
|
||||
const realNameRes = await uniIdCo.getRealNameInfo()
|
||||
|
||||
// console.log('fromDbData',res.result.data);
|
||||
this.setUserInfo({
|
||||
...res.result.data[0],
|
||||
realNameAuth: realNameRes
|
||||
})
|
||||
} catch (e) {
|
||||
this.setUserInfo({},{cover:true})
|
||||
console.error(e.message, e.errCode);
|
||||
}
|
||||
}
|
||||
},
|
||||
setUserInfo(data, {cover}={cover:false}) {
|
||||
// console.log('set-userInfo', data);
|
||||
let userInfo = cover?data:Object.assign(store.userInfo,data)
|
||||
store.userInfo = Object.assign({},userInfo)
|
||||
store.hasLogin = Object.keys(store.userInfo).length != 0
|
||||
// console.log('store.userInfo', store.userInfo);
|
||||
uni.setStorageSync('uni-id-pages-userInfo', store.userInfo)
|
||||
return data
|
||||
},
|
||||
async logout() {
|
||||
// 优先调用后端自定义登出接口(/api/sys/auth/logout),失败也不影响本地清理
|
||||
const backendUserId = uni.getStorageSync('backend-user-id')
|
||||
if (backendUserId) {
|
||||
try {
|
||||
await uni.request({
|
||||
url: getApiUrl('/api/sys/auth/logout'),
|
||||
method: 'POST',
|
||||
header: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
data: {
|
||||
userId: backendUserId
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
console.error('后端登出接口调用失败:', e)
|
||||
}
|
||||
}
|
||||
|
||||
// 清理本地登录状态(后端 token + 旧 uni-id token + tenantId)
|
||||
uni.removeStorageSync('backend-token')
|
||||
uni.removeStorageSync('backend-login-response')
|
||||
uni.removeStorageSync('backend-user-id')
|
||||
uni.removeStorageSync('backend-tenant-id') // 清除 tenantId
|
||||
uni.removeStorageSync('uni_id_token');
|
||||
uni.setStorageSync('uni_id_token_expired', 0)
|
||||
this.setUserInfo({},{cover:true})
|
||||
uni.$emit('uni-id-pages-logout')
|
||||
uni.redirectTo({
|
||||
url: `/${pagesJson.uniIdRouter && pagesJson.uniIdRouter.loginPage ? pagesJson.uniIdRouter.loginPage: 'uni_modules/uni-id-pages/pages/login/login-withoutpwd'}`,
|
||||
});
|
||||
},
|
||||
loginBack (e = {}) {
|
||||
const {uniIdRedirectUrl = ''} = e
|
||||
let delta = 0; //判断需要返回几层
|
||||
let pages = getCurrentPages();
|
||||
// console.log(pages);
|
||||
pages.forEach((page, index) => {
|
||||
if (pages[pages.length - index - 1].route.split('/')[3] == 'login') {
|
||||
delta++
|
||||
}
|
||||
})
|
||||
// console.log('判断需要返回几层:', delta);
|
||||
if (uniIdRedirectUrl) {
|
||||
return uni.redirectTo({
|
||||
url: uniIdRedirectUrl,
|
||||
fail: (err1) => {
|
||||
uni.switchTab({
|
||||
url:uniIdRedirectUrl,
|
||||
fail: (err2) => {
|
||||
console.log(err1,err2)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
// #ifdef H5
|
||||
if (e.loginType == 'weixin') {
|
||||
// console.log('window.history', window.history);
|
||||
return window.history.go(-3)
|
||||
}
|
||||
// #endif
|
||||
|
||||
if (delta) {
|
||||
const page = pagesJson.pages[0]
|
||||
return uni.reLaunch({
|
||||
url: `/${page.path}`
|
||||
})
|
||||
}
|
||||
|
||||
uni.navigateBack({
|
||||
delta
|
||||
})
|
||||
},
|
||||
loginSuccess(e = {}){
|
||||
const {
|
||||
showToast = true, toastText = '登录成功', autoBack = true, uniIdRedirectUrl = '', passwordConfirmed
|
||||
} = e
|
||||
// console.log({toastText,autoBack});
|
||||
if (showToast) {
|
||||
uni.showToast({
|
||||
title: toastText,
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
});
|
||||
}
|
||||
// 异步调用(更新用户信息)防止获取头像等操作阻塞页面返回
|
||||
this.updateUserInfo()
|
||||
|
||||
uni.$emit('uni-id-pages-login-success')
|
||||
|
||||
if (config.setPasswordAfterLogin && !passwordConfirmed) {
|
||||
return uni.redirectTo({
|
||||
url: uniIdRedirectUrl ? `/uni_modules/uni-id-pages/pages/userinfo/set-pwd/set-pwd?uniIdRedirectUrl=${uniIdRedirectUrl}&loginType=${e.loginType}`: `/uni_modules/uni-id-pages/pages/userinfo/set-pwd/set-pwd?loginType=${e.loginType}`,
|
||||
fail: (err) => {
|
||||
console.log(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (autoBack) {
|
||||
this.loginBack({uniIdRedirectUrl})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// #ifdef VUE2
|
||||
import Vue from 'vue'
|
||||
// 通过Vue.observable创建一个可响应的对象
|
||||
export const store = Vue.observable(data)
|
||||
// #endif
|
||||
|
||||
// #ifdef VUE3
|
||||
import {
|
||||
reactive
|
||||
} from 'vue'
|
||||
// 通过Vue.observable创建一个可响应的对象
|
||||
export const store = reactive(data)
|
||||
// #endif
|
||||
@@ -10,7 +10,7 @@
|
||||
import {
|
||||
store,
|
||||
mutations
|
||||
} from '@/uni_modules/uni-id-pages/common/store.js'
|
||||
} from '@/common/store.js'
|
||||
/**
|
||||
* uni-id-pages-avatar
|
||||
* @description 用户头像组件
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<script>
|
||||
import config from '@/uni_modules/uni-id-pages/config.js'
|
||||
//前一个窗口的页面地址。控制点击切换快捷登录方式是创建还是返回
|
||||
import {store,mutations} from '@/uni_modules/uni-id-pages/common/store.js'
|
||||
import {store,mutations} from '@/common/store.js'
|
||||
let allServicesList = []
|
||||
export default {
|
||||
computed: {
|
||||
|
||||
@@ -1,95 +1,23 @@
|
||||
// 导入配置
|
||||
import config from '@/uni_modules/uni-id-pages/config.js'
|
||||
// uni-id的云对象
|
||||
const uniIdCo = uniCloud.importObject('uni-id-co', {
|
||||
customUI: true
|
||||
})
|
||||
// 用户配置的登录方式、是否打开调试模式
|
||||
const {
|
||||
loginTypes,
|
||||
debug
|
||||
} = config
|
||||
// 简化版的 uni-id-pages 初始化
|
||||
// 由于项目不使用 uniCloud,移除了所有 uniCloud 相关功能
|
||||
// 主包中使用 common/uni-id-pages-init.js,此文件保留用于子包兼容性
|
||||
|
||||
// 导入配置(在子包中,config.js 也在同一子包中,可以直接导入)
|
||||
import config from './config.js'
|
||||
|
||||
export default async function () {
|
||||
// 有打开调试模式的情况下
|
||||
if (debug) {
|
||||
// 1. 检查本地uni-id-pages中配置的登录方式,服务器端是否已经配置正确。否则提醒并引导去配置
|
||||
// 调用云对象,获取服务端已正确配置的登录方式
|
||||
const {
|
||||
supportedLoginType
|
||||
} = await uniIdCo.getSupportedLoginType()
|
||||
console.log('supportedLoginType: ' + JSON.stringify(supportedLoginType))
|
||||
// 登录方式,服务端和客户端的映射关系
|
||||
const data = {
|
||||
smsCode: 'mobile-code',
|
||||
univerify: 'univerify',
|
||||
username: 'username-password',
|
||||
weixin: 'weixin',
|
||||
qq: 'qq',
|
||||
xiaomi: 'xiaomi',
|
||||
sinaweibo: 'sinaweibo',
|
||||
taobao: 'taobao',
|
||||
facebook: 'facebook',
|
||||
google: 'google',
|
||||
alipay: 'alipay',
|
||||
apple: 'apple',
|
||||
weixinMobile: 'weixin'
|
||||
}
|
||||
// 遍历客户端配置的登录方式,与服务端比对。并在错误时抛出错误提示
|
||||
const list = loginTypes.filter(type => !supportedLoginType.includes(data[type]))
|
||||
if (list.length) {
|
||||
console.error(
|
||||
`错误:前端启用的登录方式:${list.join(',')};没有在服务端完成配置。配置文件路径:"/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-id/config.json"`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
// 如果uni-id-pages配置的登录功能有一键登录,有则执行预登录(异步)
|
||||
if (loginTypes.includes('univerify')) {
|
||||
uni.preLogin({
|
||||
provider: 'univerify',
|
||||
complete: e => {
|
||||
// console.log(e);
|
||||
}
|
||||
})
|
||||
}
|
||||
// #endif
|
||||
|
||||
// 3. 绑定clientDB错误事件
|
||||
// clientDB对象
|
||||
const db = uniCloud.database()
|
||||
db.on('error', onDBError)
|
||||
// clientDB的错误提示
|
||||
function onDBError ({
|
||||
code, // 错误码详见https://uniapp.dcloud.net.cn/uniCloud/clientdb?id=returnvalue
|
||||
message
|
||||
}) {
|
||||
// console.error('onDBError', {code,message});
|
||||
}
|
||||
// 解绑clientDB错误事件
|
||||
// db.off('error', onDBError)
|
||||
|
||||
// 4. 同步客户端push_clientid至device表
|
||||
if (uniCloud.onRefreshToken) {
|
||||
uniCloud.onRefreshToken(() => {
|
||||
// console.log('onRefreshToken');
|
||||
if (uni.getPushClientId) {
|
||||
uni.getPushClientId({
|
||||
success: async function (e) {
|
||||
// console.log(e)
|
||||
const pushClientId = e.cid
|
||||
// console.log(pushClientId);
|
||||
const res = await uniIdCo.setPushCid({
|
||||
pushClientId
|
||||
})
|
||||
// console.log('getPushClientId', res);
|
||||
},
|
||||
fail (e) {
|
||||
// console.log(e)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
// #ifdef APP-PLUS
|
||||
// 如果配置的登录功能有一键登录,执行预登录(异步)
|
||||
if (config && config.loginTypes && config.loginTypes.includes('univerify')) {
|
||||
uni.preLogin({
|
||||
provider: 'univerify',
|
||||
complete: e => {
|
||||
// console.log(e);
|
||||
}
|
||||
})
|
||||
}
|
||||
// #endif
|
||||
|
||||
// 其他初始化逻辑已移除(因为不需要 uniCloud)
|
||||
// 主包中会调用 common/uni-id-pages-init.js 进行初始化
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
<script>
|
||||
import mixin from '@/uni_modules/uni-id-pages/common/login-page.mixin.js';
|
||||
import { mutations } from '@/uni_modules/uni-id-pages/common/store.js'
|
||||
import { mutations } from '@/common/store.js'
|
||||
import { getApiUrl } from '@/common/config.js'
|
||||
export default {
|
||||
mixins: [mixin],
|
||||
@@ -194,10 +194,20 @@
|
||||
duration: 800
|
||||
})
|
||||
|
||||
// 登录成功后跳转到 tabBar 首页(接待页)
|
||||
// 更新全局角色信息
|
||||
try {
|
||||
const app = getApp();
|
||||
if (app && app.setGlobalRoleInfo) {
|
||||
app.setGlobalRoleInfo();
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[Login] Failed to update global role info:', e);
|
||||
}
|
||||
|
||||
// 登录成功后跳转到首页(接待页面)
|
||||
setTimeout(() => {
|
||||
uni.switchTab({
|
||||
url: '/pages/reception/reception'
|
||||
url: '/pages/furniture_reception/furniture_reception'
|
||||
})
|
||||
}, 300)
|
||||
} catch (err) {
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
import {
|
||||
store,
|
||||
mutations
|
||||
} from '@/uni_modules/uni-id-pages/common/store.js'
|
||||
} from '@/common/store.js'
|
||||
|
||||
const uniIdCo = uniCloud.importObject("uni-id-co")
|
||||
export default {
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
import {
|
||||
store,
|
||||
mutations
|
||||
} from '@/uni_modules/uni-id-pages/common/store.js'
|
||||
} from '@/common/store.js'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
|
||||
@@ -46,7 +46,7 @@ import mixin from '@/uni_modules/uni-id-pages/common/login-page.mixin.js';
|
||||
import {
|
||||
store,
|
||||
mutations
|
||||
} from '@/uni_modules/uni-id-pages/common/store.js'
|
||||
} from '@/common/store.js'
|
||||
|
||||
const uniIdCo = uniCloud.importObject('uni-id-co')
|
||||
const tempFrvInfoKey = 'uni-id-pages-temp-frv'
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
<script>
|
||||
import passwordMod from '@/uni_modules/uni-id-pages/common/password.js'
|
||||
import {store, mutations} from '@/uni_modules/uni-id-pages/common/store.js'
|
||||
import {store, mutations} from '@/common/store.js'
|
||||
import config from '@/uni_modules/uni-id-pages/config.js'
|
||||
|
||||
const uniIdCo = uniCloud.importObject("uni-id-co", {
|
||||
|
||||
@@ -41,7 +41,7 @@ const uniIdCo = uniCloud.importObject("uni-id-co")
|
||||
import {
|
||||
store,
|
||||
mutations
|
||||
} from '@/uni_modules/uni-id-pages/common/store.js'
|
||||
} from '@/common/store.js'
|
||||
export default {
|
||||
computed: {
|
||||
userInfo() {
|
||||
|
||||
Reference in New Issue
Block a user