首次完整推送,

V:1.20240808.006
This commit is contained in:
fm453
2024-08-13 18:32:37 +08:00
parent 15be3e9373
commit c62d15b288
939 changed files with 111777 additions and 0 deletions

View File

@ -0,0 +1,16 @@
function checkIdCard (idCardNumber) {
if (!idCardNumber || typeof idCardNumber !== 'string' || idCardNumber.length !== 18) return false
const coefficient = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
const checkCode = [1, 0, 'x', 9, 8, 7, 6, 5, 4, 3, 2]
const code = idCardNumber.substring(17)
let sum = 0
for (let i = 0; i < 17; i++) {
sum += Number(idCardNumber.charAt(i)) * coefficient[i]
}
return checkCode[sum % 11].toString() === code.toLowerCase()
}
export default checkIdCard

View File

@ -0,0 +1,95 @@
import {
mutations
} from '@/uni_modules/uni-id-pages/common/store.js'
import config from '@/uni_modules/uni-id-pages/config.js'
const mixin = {
data() {
return {
config,
uniIdRedirectUrl: '',
isMounted: false
}
},
onUnload() {
// #ifdef H5
document.onkeydown = false
// #endif
},
mounted() {
this.isMounted = true
},
onLoad(e) {
if (e.is_weixin_redirect) {
uni.showLoading({
mask: true
})
if (window.location.href.includes('#')) {
// 将url通过 ? 分割获取后面的参数字符串 再通过 & 将每一个参数单独分割出来
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 => {
// console.log(this.$refs.uniFabLogin);
this.$refs.uniFabLogin.login({
code: e.code
}, 'weixin')
})
}
if (e.uniIdRedirectUrl) {
this.uniIdRedirectUrl = decodeURIComponent(e.uniIdRedirectUrl)
}
// #ifdef MP-WEIXIN
if (getCurrentPages().length === 1) {
uni.hideHomeButton()
console.log('已隐藏:返回首页按钮');
}
// #endif
},
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 {
console.log('不存在 隐私政策协议组件');
}
}
}
},
methods: {
loginSuccess(e) {
mutations.loginSuccess({
...e,
uniIdRedirectUrl: this.uniIdRedirectUrl
})
}
}
}
export default mixin

View File

@ -0,0 +1,126 @@
// 隐藏 edge 浏览器的密码查看按钮
/* #ifdef H5 */
.input-box ::v-deep{
.uni-input-input[type="password"] {
&::-ms-reveal {
display: none;
}
}
}
/* #endif */
.uni-content {
padding: 0 60rpx;
}
.login-logo {
display: none;
}
/* #ifndef APP-NVUE */
@media screen and (min-width: 690px) {
.uni-content {
/* #ifndef H5 */
padding: 0;
max-width: 300px;
margin-left: calc(50% - 200px);
/* #endif */
/* #ifdef H5 */
margin: 0 auto;
position: relative;
top: 100px;
padding: 30px 40px 80px 40px;
max-width: 450px;
max-height: 450px;
border-radius: 10px;
box-shadow: 0 0 20px #efefef;
background-color: #FFF;
/* #endif */
}
/* #ifdef H5 */
.login-logo {
display: flex;
justify-content: center;
}
.login-logo image {
width: 60px;
height: 60px;
}
.register-back{
display: none;
}
uni-button{
padding-bottom: 1px;
}
/* #endif */
}
.uni-content view {
box-sizing: border-box;
}
/* #endif */
.title {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
padding: 18px 0;
font-weight: 800;
flex-direction: column;
}
.tip {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
color: #BDBDC0;
font-size: 11px;
margin: 6px 0;
}
/* #ifndef APP-NVUE */
// 解决小程序端开启虚拟节点virtualHost引起的 class = input-box丢失的问题 [详情参考](https://uniapp.dcloud.net.cn/matter.html#%E5%90%84%E5%AE%B6%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%AE%9E%E7%8E%B0%E6%9C%BA%E5%88%B6%E4%B8%8D%E5%90%8C-%E5%8F%AF%E8%83%BD%E5%AD%98%E5%9C%A8%E7%9A%84%E5%B9%B3%E5%8F%B0%E5%85%BC%E5%AE%B9%E9%97%AE%E9%A2%98)
.uni-content ::v-deep .uni-easyinput__content,
/* #endif */
.input-box {
height: 44px;
background-color: #F8F8F8 !important;
border-radius: 0;
font-size: 14px;
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex: 1;
}
.link {
color: #04498c;
cursor: pointer;
}
.uni-content ::v-deep .uni-forms-item__inner {
padding-bottom: 8px;
}
.uni-btn {
text-align: center;
height: 40px;
line-height: 40px;
margin: 15px 0 10px 0;
color: #FFF !important;
border-radius: 5px;
font-size: 16px;
}
.uni-body.uni_modules-uni-id-pages-pages-login-login-withoutpwd{
height: auto !important;
}

View File

@ -0,0 +1,85 @@
// 导入配置
import config from '@/uni_modules/uni-id-pages/config.js'
const {passwordStrength} = 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
}
export default {
ERROR,
validPwd,
getPwdRules
}

View File

@ -0,0 +1,174 @@
import pagesJson from '@/pages.json'
import config from '@/uni_modules/uni-id-pages/config.js'
const uniIdCo = uniCloud.importObject("uni-id-co")
const db = uniCloud.database();
const usersTable = db.collection('uni-id-users')
let hostUserInfo = uni.getStorageSync('uni-id-pages-userInfo')||{}
// console.log( hostUserInfo);
const data = {
userInfo: hostUserInfo,
hasLogin: Object.keys(hostUserInfo).length != 0
}
// console.log('data', data);
// 定义 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 {
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);
}
}
},
async 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() {
// 1. 已经过期就不需要调用服务端的注销接口 2.即使调用注销接口失败,不能阻塞客户端
if(uniCloud.getCurrentUserInfo().tokenExpired > Date.now()){
try{
await uniIdCo.logout()
}catch(e){
console.error(e);
}
}
uni.removeStorageSync('uni_id_token');
uni.setStorageSync('uni_id_token_expired', 0)
uni.redirectTo({
url: `/${pagesJson.uniIdRouter && pagesJson.uniIdRouter.loginPage ? pagesJson.uniIdRouter.loginPage: 'uni_modules/uni-id-pages/pages/login/login-withoutpwd'}`,
});
uni.$emit('uni-id-pages-logout')
this.setUserInfo({},{cover:true})
},
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