适配小程序代码结构
This commit is contained in:
2
unpackage/dist/dev/mp-weixin/uni_modules/uni-id-pages/common/check-id-card.js
vendored
Normal file
2
unpackage/dist/dev/mp-weixin/uni_modules/uni-id-pages/common/check-id-card.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
//# sourceMappingURL=../../../../.sourcemap/mp-weixin/uni_modules/uni-id-pages/common/check-id-card.js.map
|
||||
85
unpackage/dist/dev/mp-weixin/uni_modules/uni-id-pages/common/login-page.mixin.js
vendored
Normal file
85
unpackage/dist/dev/mp-weixin/uni_modules/uni-id-pages/common/login-page.mixin.js
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../../common/vendor.js");
|
||||
const uni_modules_uniIdPages_common_store = require("./store.js");
|
||||
const uni_modules_uniIdPages_config = require("../config.js");
|
||||
const mixin = {
|
||||
data() {
|
||||
return {
|
||||
config: uni_modules_uniIdPages_config.config,
|
||||
uniIdRedirectUrl: "",
|
||||
isMounted: false
|
||||
};
|
||||
},
|
||||
onUnload() {
|
||||
},
|
||||
mounted() {
|
||||
this.isMounted = true;
|
||||
},
|
||||
onLoad(e) {
|
||||
if (e.is_weixin_redirect) {
|
||||
common_vendor.index.showLoading({
|
||||
mask: true
|
||||
});
|
||||
if (window.location.href.includes("#")) {
|
||||
const paramsArr = window.location.href.split("?")[1].split("&");
|
||||
paramsArr.forEach((item) => {
|
||||
const arr = item.split("=");
|
||||
if (arr[0] == "code") {
|
||||
e.code = arr[1];
|
||||
}
|
||||
});
|
||||
}
|
||||
this.$nextTick((n) => {
|
||||
this.$refs.uniFabLogin.login({
|
||||
code: e.code
|
||||
}, "weixin");
|
||||
});
|
||||
}
|
||||
if (e.uniIdRedirectUrl) {
|
||||
this.uniIdRedirectUrl = decodeURIComponent(e.uniIdRedirectUrl);
|
||||
}
|
||||
if (getCurrentPages().length === 1) {
|
||||
common_vendor.index.hideHomeButton();
|
||||
common_vendor.index.__f__("log", "at uni_modules/uni-id-pages/common/login-page.mixin.js:52", "已隐藏:返回首页按钮");
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
needAgreements() {
|
||||
if (this.isMounted) {
|
||||
if (this.$refs.agreements) {
|
||||
return this.$refs.agreements.needAgreements;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
agree: {
|
||||
get() {
|
||||
if (this.isMounted) {
|
||||
if (this.$refs.agreements) {
|
||||
return this.$refs.agreements.isAgree;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
},
|
||||
set(agree) {
|
||||
if (this.$refs.agreements) {
|
||||
this.$refs.agreements.isAgree = agree;
|
||||
} else {
|
||||
common_vendor.index.__f__("log", "at uni_modules/uni-id-pages/common/login-page.mixin.js:80", "不存在 隐私政策协议组件");
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
loginSuccess(e) {
|
||||
uni_modules_uniIdPages_common_store.mutations.loginSuccess({
|
||||
...e,
|
||||
uniIdRedirectUrl: this.uniIdRedirectUrl
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.mixin = mixin;
|
||||
//# sourceMappingURL=../../../../.sourcemap/mp-weixin/uni_modules/uni-id-pages/common/login-page.mixin.js.map
|
||||
80
unpackage/dist/dev/mp-weixin/uni_modules/uni-id-pages/common/password.js
vendored
Normal file
80
unpackage/dist/dev/mp-weixin/uni_modules/uni-id-pages/common/password.js
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
"use strict";
|
||||
const uni_modules_uniIdPages_config = require("../config.js");
|
||||
const { passwordStrength } = uni_modules_uniIdPages_config.config;
|
||||
const passwordRules = {
|
||||
// 密码必须包含大小写字母、数字和特殊符号
|
||||
super: /^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[~!@#$%^&*_\-+=`|\\(){}[\]:;"'<>,.?/])[0-9a-zA-Z~!@#$%^&*_\-+=`|\\(){}[\]:;"'<>,.?/]{8,16}$/,
|
||||
// 密码必须包含字母、数字和特殊符号
|
||||
strong: /^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[~!@#$%^&*_\-+=`|\\(){}[\]:;"'<>,.?/])[0-9a-zA-Z~!@#$%^&*_\-+=`|\\(){}[\]:;"'<>,.?/]{8,16}$/,
|
||||
// 密码必须为字母、数字和特殊符号任意两种的组合
|
||||
medium: /^(?![0-9]+$)(?![a-zA-Z]+$)(?![~!@#$%^&*_\-+=`|\\(){}[\]:;"'<>,.?/]+$)[0-9a-zA-Z~!@#$%^&*_\-+=`|\\(){}[\]:;"'<>,.?/]{8,16}$/,
|
||||
// 密码必须包含字母和数字
|
||||
weak: /^(?=.*[0-9])(?=.*[a-zA-Z])[0-9a-zA-Z~!@#$%^&*_\-+=`|\\(){}[\]:;"'<>,.?/]{6,16}$/
|
||||
};
|
||||
const ERROR = {
|
||||
normal: {
|
||||
noPwd: "请输入密码",
|
||||
noRePwd: "再次输入密码",
|
||||
rePwdErr: "两次输入密码不一致"
|
||||
},
|
||||
passwordStrengthError: {
|
||||
super: "密码必须包含大小写字母、数字和特殊符号,密码长度必须在8-16位之间",
|
||||
strong: "密码必须包含字母、数字和特殊符号,密码长度必须在8-16位之间",
|
||||
medium: "密码必须为字母、数字和特殊符号任意两种的组合,密码长度必须在8-16位之间",
|
||||
weak: "密码必须包含字母,密码长度必须在6-16位之间"
|
||||
}
|
||||
};
|
||||
function validPwd(password) {
|
||||
if (passwordStrength && passwordRules[passwordStrength]) {
|
||||
if (!new RegExp(passwordRules[passwordStrength]).test(password)) {
|
||||
return ERROR.passwordStrengthError[passwordStrength];
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function getPwdRules(pwdName = "password", rePwdName = "password2") {
|
||||
const rules = {};
|
||||
rules[pwdName] = {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
errorMessage: ERROR.normal.noPwd
|
||||
},
|
||||
{
|
||||
validateFunction: function(rule, value, data, callback) {
|
||||
const checkRes = validPwd(value);
|
||||
if (checkRes !== true) {
|
||||
callback(checkRes);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
if (rePwdName) {
|
||||
rules[rePwdName] = {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
errorMessage: ERROR.normal.noRePwd
|
||||
},
|
||||
{
|
||||
validateFunction: function(rule, value, data, callback) {
|
||||
if (value != data[pwdName]) {
|
||||
callback(ERROR.normal.rePwdErr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
return rules;
|
||||
}
|
||||
const passwordMod = {
|
||||
ERROR,
|
||||
validPwd,
|
||||
getPwdRules
|
||||
};
|
||||
exports.passwordMod = passwordMod;
|
||||
//# sourceMappingURL=../../../../.sourcemap/mp-weixin/uni_modules/uni-id-pages/common/password.js.map
|
||||
153
unpackage/dist/dev/mp-weixin/uni_modules/uni-id-pages/common/store.js
vendored
Normal file
153
unpackage/dist/dev/mp-weixin/uni_modules/uni-id-pages/common/store.js
vendored
Normal file
@@ -0,0 +1,153 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../../common/vendor.js");
|
||||
const uni_modules_uniIdPages_config = require("../config.js");
|
||||
const common_config = require("../../../common/config.js");
|
||||
const db = common_vendor.tr.database();
|
||||
const usersTable = db.collection("uni-id-users");
|
||||
let hostUserInfo = common_vendor.index.getStorageSync("uni-id-pages-userInfo") || {};
|
||||
const data = {
|
||||
userInfo: hostUserInfo,
|
||||
hasLogin: Object.keys(hostUserInfo).length != 0
|
||||
};
|
||||
const mutations = {
|
||||
// data不为空,表示传递要更新的值(注意不是覆盖是合并),什么也不传时,直接查库获取更新
|
||||
async updateUserInfo(data2 = false) {
|
||||
if (data2) {
|
||||
usersTable.where("_id==$env.uid").update(data2).then((e) => {
|
||||
if (e.result.updated) {
|
||||
common_vendor.index.showToast({
|
||||
title: "更新成功",
|
||||
icon: "none",
|
||||
duration: 3e3
|
||||
});
|
||||
this.setUserInfo(data2);
|
||||
} else {
|
||||
common_vendor.index.showToast({
|
||||
title: "没有改变",
|
||||
icon: "none",
|
||||
duration: 3e3
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
const _id = common_vendor.tr.getCurrentUserInfo().uid;
|
||||
this.setUserInfo({ _id }, { cover: true });
|
||||
const uniIdCo = common_vendor.tr.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();
|
||||
this.setUserInfo({
|
||||
...res.result.data[0],
|
||||
realNameAuth: realNameRes
|
||||
});
|
||||
} catch (e) {
|
||||
this.setUserInfo({}, { cover: true });
|
||||
common_vendor.index.__f__("error", "at uni_modules/uni-id-pages/common/store.js:60", e.message, e.errCode);
|
||||
}
|
||||
}
|
||||
},
|
||||
setUserInfo(data2, { cover } = { cover: false }) {
|
||||
let userInfo = cover ? data2 : Object.assign(store.userInfo, data2);
|
||||
store.userInfo = Object.assign({}, userInfo);
|
||||
store.hasLogin = Object.keys(store.userInfo).length != 0;
|
||||
common_vendor.index.setStorageSync("uni-id-pages-userInfo", store.userInfo);
|
||||
return data2;
|
||||
},
|
||||
async logout() {
|
||||
const backendUserId = common_vendor.index.getStorageSync("backend-user-id");
|
||||
if (backendUserId) {
|
||||
try {
|
||||
await common_vendor.index.request({
|
||||
url: common_config.getApiUrl("/api/sys/auth/logout"),
|
||||
method: "POST",
|
||||
header: {
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
data: {
|
||||
userId: backendUserId
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
common_vendor.index.__f__("error", "at uni_modules/uni-id-pages/common/store.js:89", "后端登出接口调用失败:", e);
|
||||
}
|
||||
}
|
||||
common_vendor.index.removeStorageSync("backend-token");
|
||||
common_vendor.index.removeStorageSync("backend-login-response");
|
||||
common_vendor.index.removeStorageSync("backend-user-id");
|
||||
common_vendor.index.removeStorageSync("backend-tenant-id");
|
||||
common_vendor.index.removeStorageSync("uni_id_token");
|
||||
common_vendor.index.setStorageSync("uni_id_token_expired", 0);
|
||||
this.setUserInfo({}, { cover: true });
|
||||
common_vendor.index.$emit("uni-id-pages-logout");
|
||||
common_vendor.index.redirectTo({
|
||||
url: `/${common_vendor.pagesJson.uniIdRouter && common_vendor.pagesJson.uniIdRouter.loginPage ? common_vendor.pagesJson.uniIdRouter.loginPage : "uni_modules/uni-id-pages/pages/login/login-withoutpwd"}`
|
||||
});
|
||||
},
|
||||
loginBack(e = {}) {
|
||||
const { uniIdRedirectUrl = "" } = e;
|
||||
let delta = 0;
|
||||
let pages = getCurrentPages();
|
||||
pages.forEach((page, index) => {
|
||||
if (pages[pages.length - index - 1].route.split("/")[3] == "login") {
|
||||
delta++;
|
||||
}
|
||||
});
|
||||
if (uniIdRedirectUrl) {
|
||||
return common_vendor.index.redirectTo({
|
||||
url: uniIdRedirectUrl,
|
||||
fail: (err1) => {
|
||||
common_vendor.index.switchTab({
|
||||
url: uniIdRedirectUrl,
|
||||
fail: (err2) => {
|
||||
common_vendor.index.__f__("log", "at uni_modules/uni-id-pages/common/store.js:124", err1, err2);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
if (delta) {
|
||||
const page = common_vendor.pagesJson.pages[0];
|
||||
return common_vendor.index.reLaunch({
|
||||
url: `/${page.path}`
|
||||
});
|
||||
}
|
||||
common_vendor.index.navigateBack({
|
||||
delta
|
||||
});
|
||||
},
|
||||
loginSuccess(e = {}) {
|
||||
const {
|
||||
showToast = true,
|
||||
toastText = "登录成功",
|
||||
autoBack = true,
|
||||
uniIdRedirectUrl = "",
|
||||
passwordConfirmed
|
||||
} = e;
|
||||
if (showToast) {
|
||||
common_vendor.index.showToast({
|
||||
title: toastText,
|
||||
icon: "none",
|
||||
duration: 3e3
|
||||
});
|
||||
}
|
||||
this.updateUserInfo();
|
||||
common_vendor.index.$emit("uni-id-pages-login-success");
|
||||
if (uni_modules_uniIdPages_config.config.setPasswordAfterLogin && !passwordConfirmed) {
|
||||
return common_vendor.index.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) => {
|
||||
common_vendor.index.__f__("log", "at uni_modules/uni-id-pages/common/store.js:169", err);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (autoBack) {
|
||||
this.loginBack({ uniIdRedirectUrl });
|
||||
}
|
||||
}
|
||||
};
|
||||
const store = common_vendor.reactive(data);
|
||||
exports.mutations = mutations;
|
||||
exports.store = store;
|
||||
//# sourceMappingURL=../../../../.sourcemap/mp-weixin/uni_modules/uni-id-pages/common/store.js.map
|
||||
Reference in New Issue
Block a user