Commit 5ebaff9e5286455717bd646fa5338e2d28e3e3d1

Authored by fengwotao
1 parent cd0435b8

fix: 修复登录密码正则验证不支持下划线_这种特殊字符

@@ -135,6 +135,7 @@ @@ -135,6 +135,7 @@
135 mapState, 135 mapState,
136 mapMutations 136 mapMutations
137 } from 'vuex'; 137 } from 'vuex';
  138 + import { loginPasswordReg } from '@/plugins/utils.js'
138 139
139 export default { 140 export default {
140 components: { 141 components: {
@@ -244,14 +245,13 @@ @@ -244,14 +245,13 @@
244 if (this.bindAccountObj.appUserKey == '' || this.bindAccountObj.appUserKey == undefined) { 245 if (this.bindAccountObj.appUserKey == '' || this.bindAccountObj.appUserKey == undefined) {
245 return uni.$u.toast('请输入登录账号~'); 246 return uni.$u.toast('请输入登录账号~');
246 } 247 }
247 - const passReg = /^(?=.*?[A-Z])(?=(.*[a-z]){1,})(?=(.*[\d]){1,})(?=(.*[\W]){1,})(?!.*\s).{8,}$/;  
248 if (this.bindAccountObj.appUserSecret == '') { 248 if (this.bindAccountObj.appUserSecret == '') {
249 uni.showToast({ 249 uni.showToast({
250 title: '请输入登录密码~', 250 title: '请输入登录密码~',
251 icon: 'none' 251 icon: 'none'
252 }); 252 });
253 return; 253 return;
254 - } else if (!passReg.test(this.bindAccountObj.appUserSecret)) { 254 + } else if (!loginPasswordReg.test(this.bindAccountObj.appUserSecret)) {
255 uni.showModal({ 255 uni.showModal({
256 title: '提示', 256 title: '提示',
257 content: '密码格式不正确(至少一个大写英文字母、至少一个小写英文字母、至少一位数字、至少一个特殊字符、最少八个字符)~', 257 content: '密码格式不正确(至少一个大写英文字母、至少一个小写英文字母、至少一位数字、至少一个特殊字符、最少八个字符)~',
1 -import Vue from "vue";  
2 -import moment from "moment";  
3 -const DATE_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";  
4 -//手机号中间4位为*  
5 -Vue.filter("phone", function (val) {  
6 - var tel = val;  
7 - tel = "" + tel;  
8 - var telShort = tel.replace(tel.substring(3, 7), "****");  
9 - return telShort;  
10 -});  
11 -//获取系统信息、判断ipX安全距离  
12 -export const getTabbarHeight = function () {  
13 - var systemInfo = uni.getSystemInfoSync();  
14 - var data = {  
15 - ...systemInfo,  
16 - tabbarH: 50, //tabbar高度--单位px  
17 - tabbarPaddingB: 0, //tabbar底部安全距离高度--单位px  
18 - device: systemInfo.system.indexOf("iOS") != -1 ? "iOS" : "Android", //苹果或者安卓设备  
19 - };  
20 - let modelArr = [  
21 - "10,3",  
22 - "10,6",  
23 - "X",  
24 - "XR",  
25 - "XS",  
26 - "11",  
27 - "12",  
28 - "13",  
29 - "14",  
30 - "15",  
31 - "16",  
32 - ];  
33 - let model = systemInfo.model;  
34 - model &&  
35 - modelArr.forEach((item) => {  
36 - //适配iphoneX以上的底部,给tabbar一定高度的padding-bottom  
37 - if (  
38 - model.indexOf(item) != -1 &&  
39 - (model.indexOf("iPhone") != -1 || model.indexOf("iphone") != -1)  
40 - ) {  
41 - data.tabbarH = 70;  
42 - data.tabbarPaddingB = 20;  
43 - }  
44 - });  
45 - return data;  
46 -};  
47 -  
48 -// px转upx  
49 -export const px2upx = function (n) {  
50 - return n / (uni.upx2px(n) / n);  
51 -};  
52 -  
53 -// 小程序获取定位权限判断  
54 -// isOpenSetting 默认false:不检验授权,true:检验授权后获取地址  
55 -function getMpLocation(successCallback, errCallback, isOpenSetting) {  
56 - uni.getSetting({  
57 - success: (res) => {  
58 - if (res.authSetting["scope.userLocation"] || !isOpenSetting) {  
59 - uni.getLocation({  
60 - // #ifndef MP-ALIPAY  
61 - type: "gcj02",  
62 - // #endif  
63 - success(res) {  
64 - console.log("successCallback");  
65 - successCallback(res);  
66 - },  
67 - fail(err) {  
68 - console.log("位置信息错误", err);  
69 - errCallback("位置信息获取失败");  
70 - },  
71 - });  
72 - } else {  
73 - errCallback("“位置信息”未授权");  
74 - isOpenSetting &&  
75 - uni.showModal({  
76 - title: "提示",  
77 - content: "请先在设置页面打开“位置信息”使用权限",  
78 - confirmText: "去设置",  
79 - cancelText: "再逛会",  
80 - success: (res) => {  
81 - if (res.confirm) {  
82 - uni.openSetting();  
83 - }  
84 - },  
85 - });  
86 - }  
87 - },  
88 - });  
89 -}  
90 -// 获取地址信息  
91 -let locationAuthorize = true;  
92 -export const getAppLatLon = function (  
93 - successCallback,  
94 - errCallback,  
95 - isOpenSetting  
96 -) {  
97 - const _this = this;  
98 - // #ifdef MP-WEIXIN  
99 - if (locationAuthorize && isOpenSetting) {  
100 - uni.authorize({  
101 - scope: "scope.userLocation",  
102 - success: () => {  
103 - getMpLocation(successCallback, errCallback, isOpenSetting);  
104 - locationAuthorize = false;  
105 - },  
106 - fail: () => {  
107 - locationAuthorize = false;  
108 - },  
109 - });  
110 - } else {  
111 - getMpLocation(successCallback, errCallback, isOpenSetting);  
112 - }  
113 - // #endif  
114 - // #ifdef MP-ALIPAY  
115 - getMpLocation(successCallback, errCallback, false);  
116 - // #endif  
117 - // #ifdef H5  
118 - uni.getLocation({  
119 - type: "gcj02",  
120 - success(res) {  
121 - console.log("successCallback");  
122 - successCallback(res);  
123 - },  
124 - fail(err) {  
125 - console.log("位置信息错误", err);  
126 - errCallback("位置信息获取失败");  
127 - },  
128 - });  
129 - // #endif  
130 -};  
131 -  
132 -export function formatToDate(date = undefined, format = DATE_TIME_FORMAT) {  
133 - return moment(date).format(format);  
134 -} 1 +import Vue from "vue";
  2 +import moment from "moment";
  3 +const DATE_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
  4 +
  5 +/**
  6 + 登录密码正则验证
  7 + 最短8位,最长16位
  8 + 必须包含1个数字
  9 + 必须包含1个小写字母
  10 + 必须包含1个大写字母
  11 + 必须包含1个特殊字符
  12 + */
  13 +export const loginPasswordReg =/^.*(?=.{6,16})(?=.*\d)(?=.*[A-Z]{1,})(?=.*[a-z]{1,})(?=.*[_!@#$%^&*?\(\)]).*$/;
  14 +
  15 +//手机号中间4位为*
  16 +Vue.filter("phone", function (val) {
  17 + var tel = val;
  18 + tel = "" + tel;
  19 + var telShort = tel.replace(tel.substring(3, 7), "****");
  20 + return telShort;
  21 +});
  22 +//获取系统信息、判断ipX安全距离
  23 +export const getTabbarHeight = function () {
  24 + var systemInfo = uni.getSystemInfoSync();
  25 + var data = {
  26 + ...systemInfo,
  27 + tabbarH: 50, //tabbar高度--单位px
  28 + tabbarPaddingB: 0, //tabbar底部安全距离高度--单位px
  29 + device: systemInfo.system.indexOf("iOS") != -1 ? "iOS" : "Android", //苹果或者安卓设备
  30 + };
  31 + let modelArr = [
  32 + "10,3",
  33 + "10,6",
  34 + "X",
  35 + "XR",
  36 + "XS",
  37 + "11",
  38 + "12",
  39 + "13",
  40 + "14",
  41 + "15",
  42 + "16",
  43 + ];
  44 + let model = systemInfo.model;
  45 + model &&
  46 + modelArr.forEach((item) => {
  47 + //适配iphoneX以上的底部,给tabbar一定高度的padding-bottom
  48 + if (
  49 + model.indexOf(item) != -1 &&
  50 + (model.indexOf("iPhone") != -1 || model.indexOf("iphone") != -1)
  51 + ) {
  52 + data.tabbarH = 70;
  53 + data.tabbarPaddingB = 20;
  54 + }
  55 + });
  56 + return data;
  57 +};
  58 +
  59 +// px转upx
  60 +export const px2upx = function (n) {
  61 + return n / (uni.upx2px(n) / n);
  62 +};
  63 +
  64 +// 小程序获取定位权限判断
  65 +// isOpenSetting 默认false:不检验授权,true:检验授权后获取地址
  66 +function getMpLocation(successCallback, errCallback, isOpenSetting) {
  67 + uni.getSetting({
  68 + success: (res) => {
  69 + if (res.authSetting["scope.userLocation"] || !isOpenSetting) {
  70 + uni.getLocation({
  71 + // #ifndef MP-ALIPAY
  72 + type: "gcj02",
  73 + // #endif
  74 + success(res) {
  75 + console.log("successCallback");
  76 + successCallback(res);
  77 + },
  78 + fail(err) {
  79 + console.log("位置信息错误", err);
  80 + errCallback("位置信息获取失败");
  81 + },
  82 + });
  83 + } else {
  84 + errCallback("“位置信息”未授权");
  85 + isOpenSetting &&
  86 + uni.showModal({
  87 + title: "提示",
  88 + content: "请先在设置页面打开“位置信息”使用权限",
  89 + confirmText: "去设置",
  90 + cancelText: "再逛会",
  91 + success: (res) => {
  92 + if (res.confirm) {
  93 + uni.openSetting();
  94 + }
  95 + },
  96 + });
  97 + }
  98 + },
  99 + });
  100 +}
  101 +// 获取地址信息
  102 +let locationAuthorize = true;
  103 +export const getAppLatLon = function (
  104 + successCallback,
  105 + errCallback,
  106 + isOpenSetting
  107 +) {
  108 + const _this = this;
  109 + // #ifdef MP-WEIXIN
  110 + if (locationAuthorize && isOpenSetting) {
  111 + uni.authorize({
  112 + scope: "scope.userLocation",
  113 + success: () => {
  114 + getMpLocation(successCallback, errCallback, isOpenSetting);
  115 + locationAuthorize = false;
  116 + },
  117 + fail: () => {
  118 + locationAuthorize = false;
  119 + },
  120 + });
  121 + } else {
  122 + getMpLocation(successCallback, errCallback, isOpenSetting);
  123 + }
  124 + // #endif
  125 + // #ifdef MP-ALIPAY
  126 + getMpLocation(successCallback, errCallback, false);
  127 + // #endif
  128 + // #ifdef H5
  129 + uni.getLocation({
  130 + type: "gcj02",
  131 + success(res) {
  132 + console.log("successCallback");
  133 + successCallback(res);
  134 + },
  135 + fail(err) {
  136 + console.log("位置信息错误", err);
  137 + errCallback("位置信息获取失败");
  138 + },
  139 + });
  140 + // #endif
  141 +};
  142 +
  143 +export function formatToDate(date = undefined, format = DATE_TIME_FORMAT) {
  144 + return moment(date).format(format);
  145 +}
@@ -52,6 +52,7 @@ @@ -52,6 +52,7 @@
52 52
53 <script> 53 <script>
54 import api from '@/api/index.js' 54 import api from '@/api/index.js'
  55 + import { loginPasswordReg } from '@/plugins/utils.js'
55 56
56 var clear; 57 var clear;
57 export default { 58 export default {
@@ -156,14 +157,13 @@ @@ -156,14 +157,13 @@
156 this.nextStatus = false; 157 this.nextStatus = false;
157 }, 158 },
158 onSubmit() { 159 onSubmit() {
159 - const passReg = /^(?=.*?[A-Z])(?=(.*[a-z]){1,})(?=(.*[\d]){1,})(?=(.*[\W]){1,})(?!.*\s).{8,}$/;  
160 if (this.password == '' && this.rePassword == '') { 160 if (this.password == '' && this.rePassword == '') {
161 uni.showToast({ 161 uni.showToast({
162 title: '请输入密码~', 162 title: '请输入密码~',
163 icon: 'none' 163 icon: 'none'
164 }); 164 });
165 return; 165 return;
166 - } else if (!passReg.test(this.password) && !passReg.test(this.rePassword)) { 166 + } else if (!loginPasswordReg.test(this.password) && !loginPasswordReg.test(this.rePassword)) {
167 //uni.showToast,字数过长,会造成手机上显示不完全,官方bug,采用uni.showModal 167 //uni.showToast,字数过长,会造成手机上显示不完全,官方bug,采用uni.showModal
168 uni.showModal({ 168 uni.showModal({
169 title: '提示', 169 title: '提示',
@@ -69,6 +69,7 @@ @@ -69,6 +69,7 @@
69 mapState 69 mapState
70 } from "vuex"; 70 } from "vuex";
71 import api from '@/api' 71 import api from '@/api'
  72 + import { loginPasswordReg } from '@/plugins/utils.js'
72 73
73 export default { 74 export default {
74 data() { 75 data() {
@@ -237,18 +238,15 @@ @@ -237,18 +238,15 @@
237 if (this.loginForm.username == "") { 238 if (this.loginForm.username == "") {
238 return uni.$u.toast("请输入登录账号~"); 239 return uni.$u.toast("请输入登录账号~");
239 } 240 }
240 - const passReg =  
241 - /^(?=.*?[A-Z])(?=(.*[a-z]){1,})(?=(.*[\d]){1,})(?=(.*[\W]){1,})(?!.*\s).{8,}$/;  
242 -  
243 if (this.loginForm.password == "") { 241 if (this.loginForm.password == "") {
244 uni.showToast({ 242 uni.showToast({
245 title: "请输入登录密码~", 243 title: "请输入登录密码~",
246 icon: "none", 244 icon: "none",
247 }); 245 });
248 return; 246 return;
249 - } else if (!passReg.test(this.loginForm.password)) { 247 + } else if (!loginPasswordReg.test(this.loginForm.password)) {
250 uni.showModal({ 248 uni.showModal({
251 - title: "提示", 249 + title: "提示",
252 content: "密码格式不正确(至少一个大写英文字母、至少一个小写英文字母、至少一位数字、至少一个特殊字符、最少八个字符)~", 250 content: "密码格式不正确(至少一个大写英文字母、至少一个小写英文字母、至少一位数字、至少一个特殊字符、最少八个字符)~",
253 showCancel: false, 251 showCancel: false,
254 }); 252 });