|
@@ -1,25 +1,40 @@
|
|
|
-const {
|
|
|
- windowHeight,
|
|
|
- titleBarHeight,
|
|
|
- statusBarHeight
|
|
|
-} = my.getSystemInfoSync();
|
|
|
+const { windowHeight, titleBarHeight, statusBarHeight } =
|
|
|
+ my.getSystemInfoSync();
|
|
|
/**
|
|
|
* 时间搓分开返回日期、时间、星期
|
|
|
* @param time
|
|
|
* @returns {{date: string, time: string, am: (string), day: string}}
|
|
|
*/
|
|
|
|
|
|
-export function cuttingDate(time = '') {
|
|
|
- const d = time ? new Date(time.replace(/-/g, '/')) : new Date();
|
|
|
- const hours = d.getHours();
|
|
|
- return {
|
|
|
- date: d.toLocaleDateString().replace(/\//g, '-'),
|
|
|
- day: getWeek(d),
|
|
|
- am: hours < 12 ? '上午' : '下午',
|
|
|
- type: hours < 12 ? 'am' : 'pm',
|
|
|
- time: `${`0${hours}`.slice(-2)}:${`0${d.getMinutes()}`.slice(-2)}`
|
|
|
- };
|
|
|
+export function cuttingDate(time = "") {
|
|
|
+ const d = time ? new Date(time.replace(/-/g, "/")) : new Date();
|
|
|
+ const hours = d.getHours();
|
|
|
+ return {
|
|
|
+ date: d.toLocaleDateString().replace(/\//g, "-"),
|
|
|
+ day: getWeek(d),
|
|
|
+ am: hours < 12 ? "上午" : "下午",
|
|
|
+ type: hours < 12 ? "am" : "pm",
|
|
|
+ time: `${`0${hours}`.slice(-2)}:${`0${d.getMinutes()}`.slice(-2)}`,
|
|
|
+ };
|
|
|
}
|
|
|
+
|
|
|
+export function selectDate(content = "") {
|
|
|
+ switch (content) {
|
|
|
+ case 2:
|
|
|
+ return "am";
|
|
|
+ case 3:
|
|
|
+ return "pm";
|
|
|
+ case 6:
|
|
|
+ return "mm";
|
|
|
+ case 4:
|
|
|
+ return "nm";
|
|
|
+ case 5:
|
|
|
+ return "mnm";
|
|
|
+ default:
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* 返回星期
|
|
|
* @param date
|
|
@@ -27,43 +42,56 @@ export function cuttingDate(time = '') {
|
|
|
*/
|
|
|
|
|
|
export function getWeek(date) {
|
|
|
- const d = Object.prototype.toString.call(date) === '[object Date]' ? date : new Date(date);
|
|
|
- return ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][d.getDay()];
|
|
|
+ const d =
|
|
|
+ Object.prototype.toString.call(date) === "[object Date]"
|
|
|
+ ? date
|
|
|
+ : new Date(date);
|
|
|
+ return ["周日", "周一", "周二", "周三", "周四", "周五", "周六"][d.getDay()];
|
|
|
}
|
|
|
|
|
|
-const excludeEmptyValue = data => {
|
|
|
- const obj = {};
|
|
|
- Object.keys(data).forEach(key => {
|
|
|
- const value = data[key];
|
|
|
- if (value !== undefined) obj[key] = value;
|
|
|
- });
|
|
|
- return obj;
|
|
|
+const excludeEmptyValue = (data) => {
|
|
|
+ const obj = {};
|
|
|
+ Object.keys(data).forEach((key) => {
|
|
|
+ const value = data[key];
|
|
|
+ if (value !== undefined) obj[key] = value;
|
|
|
+ });
|
|
|
+ return obj;
|
|
|
};
|
|
|
|
|
|
-export const queryToUrl = query => Object.keys(excludeEmptyValue(query)).reduce((sum, item) => `${sum}&${item}=${query[item]}`, '');
|
|
|
+export const queryToUrl = (query) =>
|
|
|
+ Object.keys(excludeEmptyValue(query)).reduce(
|
|
|
+ (sum, item) => `${sum}&${item}=${query[item]}`,
|
|
|
+ ""
|
|
|
+ );
|
|
|
export const getHeaderHeight = () => titleBarHeight + statusBarHeight;
|
|
|
export const getContentHeight = () => windowHeight - getHeaderHeight();
|
|
|
-export const ID_CARD_18 = /^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
|
|
|
-export const ID_CARD_15 = /^([1-6][1-9]|50)\d{4}\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}$/;
|
|
|
+export const ID_CARD_18 =
|
|
|
+ /^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
|
|
|
+export const ID_CARD_15 =
|
|
|
+ /^([1-6][1-9]|50)\d{4}\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}$/;
|
|
|
export const PHONE_CHECK = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
|
|
|
/* 校验身份证 */
|
|
|
|
|
|
export function checkIdCard(idCardNo) {
|
|
|
- return ID_CARD_18.test(idCardNo) || ID_CARD_15.test(idCardNo) || idCardNo.indexOf('*') > -1;
|
|
|
+ return (
|
|
|
+ ID_CARD_18.test(idCardNo) ||
|
|
|
+ ID_CARD_15.test(idCardNo) ||
|
|
|
+ idCardNo.indexOf("*") > -1
|
|
|
+ );
|
|
|
}
|
|
|
/* 校验手机 */
|
|
|
|
|
|
export function checkPhone(phoneNumber) {
|
|
|
- return PHONE_CHECK.test(phoneNumber) || phoneNumber.indexOf('*') > -1;
|
|
|
+ return PHONE_CHECK.test(phoneNumber) || phoneNumber.indexOf("*") > -1;
|
|
|
} // 防抖函数
|
|
|
|
|
|
export function debounce(fn, delay = 0) {
|
|
|
- let timer;
|
|
|
- return function _(...args) {
|
|
|
- clearTimeout(timer);
|
|
|
- const context = this;
|
|
|
- timer = setTimeout(() => {
|
|
|
- fn.apply(context, [...args, context]);
|
|
|
- }, delay);
|
|
|
- };
|
|
|
-}
|
|
|
+ let timer;
|
|
|
+ return function _(...args) {
|
|
|
+ clearTimeout(timer);
|
|
|
+ const context = this;
|
|
|
+ timer = setTimeout(() => {
|
|
|
+ fn.apply(context, [...args, context]);
|
|
|
+ }, delay);
|
|
|
+ };
|
|
|
+}
|