首次完整推送,

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

166
common/appInit.js Normal file
View File

@ -0,0 +1,166 @@
import _app_Config from '@/app.config.js';
//应用初始化页
// #ifdef APP-PLUS
import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update';
import callCheckVersion from '@/uni_modules/uni-upgrade-center-app/utils/call-check-version';
// 实现,路由拦截。当应用无访问摄像头/相册权限,引导跳到设置界面 https://ext.dcloud.net.cn/plugin?id=5095
import interceptorChooseImage from '@/uni_modules/json-interceptor-chooseImage/js_sdk/main.js';
interceptorChooseImage()
// #endif
const db = uniCloud.database()
export default async function() {
const debug = _app_Config.debug;
// _app_Config挂载到getApp().globalData.config
setTimeout(() => {
getApp({
allowDefault: true
}).globalData.config = _app_Config;
}, 1)
// 初始化appVersion仅app生效
initAppVersion();
//clientDB的错误提示
function onDBError({
code, // 错误码详见https://uniapp.dcloud.net.cn/uniCloud/clientdb?id=returnvalue
message
}) {
console.log('onDBError', {
code,
message
});
// 处理错误
console.error(code, message);
}
// 绑定clientDB错误事件
db.on('error', onDBError)
//拦截云对象请求
uniCloud.interceptObject({
async invoke({
objectName, // 云对象名称
methodName, // 云对象的方法名称
params // 参数列表
}) {
// console.log('interceptObject',{
// objectName, // 云对象名称
// methodName, // 云对象的方法名称
// params // 参数列表
// });
if (objectName == "uni-id-co" && (methodName.includes('loginBy') || ['login',
'registerUser'
].includes(methodName))) {
// console.log('执行登录相关云对象');
params[0].inviteCode = await new Promise((callBack) => {
uni.getClipboardData({
success: function(res) {
// console.log('剪切板内容:' + res.data);
if (res.data.slice(0, 18) == 'uniInvitationCode:') {
let uniInvitationCode = res.data.slice(18, 38)
// console.log('当前用户是其他用户推荐下载的,推荐者的code是' +uniInvitationCode);
// uni.showModal({
// content: '当前用户是其他用户推荐下载的,推荐者的code是'+uniInvitationCode,
// showCancel: false
// });
callBack(uniInvitationCode)
//当前用户是其他用户推荐下载的。这里登记他的推荐者id 为当前用户的myInviteCode。判断如果是注册
} else {
callBack()
}
},
fail() {
// console.log('error--');
callBack()
},
complete() {
// #ifdef MP-WEIXIN
uni.hideToast()
// #endif
}
});
})
// console.log(params);
}
// console.log(params);
},
success(e) {
// console.log(e);
},
complete() {
},
fail(e) {
// console.error(e);
// if (debug) {
// uni.showModal({
// content: JSON.stringify(e),
// showCancel: false
// });
// }else{
// uni.showToast({
// title: '系统错误请稍后再试',
// icon:'error'
// });
// }
}
})
// #ifdef APP-PLUS
// 监听并提示设备网络状态变化
uni.onNetworkStatusChange(res => {
// console.log(res.isConnected);
// console.log(res.networkType);
if (res.networkType != 'none') {
uni.showToast({
title: '当前网络类型:' + res.networkType,
icon: 'none',
duration: 3000
})
} else {
uni.showToast({
title: '网络类型:' + res.networkType,
icon: 'none',
duration: 3000
})
}
});
// #endif
}
/**
* // 初始化appVersion
*/
function initAppVersion() {
// #ifdef APP-PLUS
let appid = plus.runtime.appid;
plus.runtime.getProperty(appid, (wgtInfo) => {
let appVersion = plus.runtime;
let currentVersion = appVersion.versionCode > wgtInfo.versionCode ? appVersion : wgtInfo;
getApp({
allowDefault: true
}).appVersion = {
...currentVersion,
appid,
hasNew: false
}
// 检查更新小红点
callCheckVersion().then(res => {
// console.log('检查是否有可以更新的版本', res);
if (res.result.code > 0) {
// 有新版本
getApp({
allowDefault: true
}).appVersion.hasNew = true;
// console.log(checkUpdate());
}
})
});
// 检查更新
// #endif
}

24
common/car-p.js Normal file
View File

@ -0,0 +1,24 @@
export default {
list0: [
'京', '津', '冀', '晋', '蒙', '辽', '吉',
'黑', '沪', '苏', '浙', '皖', '闽', '赣',
'鲁', '豫', '鄂', '湘', '粤', '桂',
'琼', '渝', '川', '贵', '云', '藏',
'陕', '甘', '青', '宁', '新', '港', '澳', '台'
],
//默认排序
list: [
'琼',
'京', '津', '冀',
'黑', '吉', '辽',
'川', '渝', '贵',
'晋', '蒙', '鲁', '豫',
'陕', '甘', '青', '宁', '新',
'沪', '苏', '浙',
'皖', '闽', '赣', '鄂', '湘', '粤', '桂',
'云', '藏',
'港', '澳', '台'
],
// 自定义排序
}

97
common/graceChecker.js Normal file
View File

@ -0,0 +1,97 @@
/**
数据验证(表单验证)
来自 grace.hcoder.net
作者 hcoder 深海
*/
export default {
error:'',
check : function (data, rule){
for(var i = 0; i < rule.length; i++){
if (!rule[i].checkType){return true;}
if (!rule[i].name) {return true;}
if (!rule[i].errorMsg) {return true;}
if (!data[rule[i].name]) {this.error = rule[i].errorMsg; return false;}
switch (rule[i].checkType){
case 'string':
var reg = new RegExp('^.{' + rule[i].checkRule + '}$');
if(!reg.test(data[rule[i].name])) {this.error = rule[i].errorMsg; return false;}
break;
case 'int':
var reg = new RegExp('^(-[1-9]|[1-9])[0-9]{' + rule[i].checkRule + '}$');
if(!reg.test(data[rule[i].name])) {this.error = rule[i].errorMsg; return false;}
break;
break;
case 'between':
if (!this.isNumber(data[rule[i].name])){
this.error = rule[i].errorMsg;
return false;
}
var minMax = rule[i].checkRule.split(',');
minMax[0] = Number(minMax[0]);
minMax[1] = Number(minMax[1]);
if (data[rule[i].name] > minMax[1] || data[rule[i].name] < minMax[0]) {
this.error = rule[i].errorMsg;
return false;
}
break;
case 'betweenD':
var reg = /^-?[1-9][0-9]?$/;
if (!reg.test(data[rule[i].name])) { this.error = rule[i].errorMsg; return false; }
var minMax = rule[i].checkRule.split(',');
minMax[0] = Number(minMax[0]);
minMax[1] = Number(minMax[1]);
if (data[rule[i].name] > minMax[1] || data[rule[i].name] < minMax[0]) {
this.error = rule[i].errorMsg;
return false;
}
break;
case 'betweenF':
var reg = /^-?[0-9][0-9]?.+[0-9]+$/;
if (!reg.test(data[rule[i].name])){this.error = rule[i].errorMsg; return false;}
var minMax = rule[i].checkRule.split(',');
minMax[0] = Number(minMax[0]);
minMax[1] = Number(minMax[1]);
if (data[rule[i].name] > minMax[1] || data[rule[i].name] < minMax[0]) {
this.error = rule[i].errorMsg;
return false;
}
break;
case 'same':
if (data[rule[i].name] != rule[i].checkRule) { this.error = rule[i].errorMsg; return false;}
break;
case 'notsame':
if (data[rule[i].name] == rule[i].checkRule) { this.error = rule[i].errorMsg; return false; }
break;
case 'email':
var reg = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
if (!reg.test(data[rule[i].name])) { this.error = rule[i].errorMsg; return false; }
break;
case 'phoneno':
var reg = /^1[0-9]{10,10}$/;
if (!reg.test(data[rule[i].name])) { this.error = rule[i].errorMsg; return false; }
break;
case 'zipcode':
var reg = /^[0-9]{6}$/;
if (!reg.test(data[rule[i].name])) { this.error = rule[i].errorMsg; return false; }
break;
case 'reg':
var reg = new RegExp(rule[i].checkRule);
if (!reg.test(data[rule[i].name])) { this.error = rule[i].errorMsg; return false; }
break;
case 'in':
if(rule[i].checkRule.indexOf(data[rule[i].name]) == -1){
this.error = rule[i].errorMsg; return false;
}
break;
case 'notnull':
if(data[rule[i].name] == null || data[rule[i].name].length < 1){this.error = rule[i].errorMsg; return false;}
break;
}
}
return true;
},
isNumber : function (checkVal){
var reg = /^-?[1-9][0-9]?.?[0-9]*$/;
return reg.test(checkVal);
}
}

352
common/html-parser.js Normal file
View File

@ -0,0 +1,352 @@
/*
* HTML5 Parser By Sam Blowes
*
* Designed for HTML5 documents
*
* Original code by John Resig (ejohn.org)
* http://ejohn.org/blog/pure-javascript-html-parser/
* Original code by Erik Arvidsson, Mozilla Public License
* http://erik.eae.net/simplehtmlparser/simplehtmlparser.js
*
* ----------------------------------------------------------------------------
* License
* ----------------------------------------------------------------------------
*
* This code is triple licensed using Apache Software License 2.0,
* Mozilla Public License or GNU Public License
*
* ////////////////////////////////////////////////////////////////////////////
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* ////////////////////////////////////////////////////////////////////////////
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Simple HTML Parser.
*
* The Initial Developer of the Original Code is Erik Arvidsson.
* Portions created by Erik Arvidssson are Copyright (C) 2004. All Rights
* Reserved.
*
* ////////////////////////////////////////////////////////////////////////////
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* ----------------------------------------------------------------------------
* Usage
* ----------------------------------------------------------------------------
*
* // Use like so:
* HTMLParser(htmlString, {
* start: function(tag, attrs, unary) {},
* end: function(tag) {},
* chars: function(text) {},
* comment: function(text) {}
* });
*
* // or to get an XML string:
* HTMLtoXML(htmlString);
*
* // or to get an XML DOM Document
* HTMLtoDOM(htmlString);
*
* // or to inject into an existing document/DOM node
* HTMLtoDOM(htmlString, document);
* HTMLtoDOM(htmlString, document.body);
*
*/
// Regular Expressions for parsing tags and attributes
var startTag = /^<([-A-Za-z0-9_]+)((?:\s+[a-zA-Z_:][-a-zA-Z0-9_:.]*(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/;
var endTag = /^<\/([-A-Za-z0-9_]+)[^>]*>/;
var attr = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g; // Empty Elements - HTML 5
var empty = makeMap('area,base,basefont,br,col,frame,hr,img,input,link,meta,param,embed,command,keygen,source,track,wbr'); // Block Elements - HTML 5
// fixed by xxx 将 ins 标签从块级名单中移除
var block = makeMap('a,address,article,applet,aside,audio,blockquote,button,canvas,center,dd,del,dir,div,dl,dt,fieldset,figcaption,figure,footer,form,frameset,h1,h2,h3,h4,h5,h6,header,hgroup,hr,iframe,isindex,li,map,menu,noframes,noscript,object,ol,output,p,pre,section,script,table,tbody,td,tfoot,th,thead,tr,ul,video'); // Inline Elements - HTML 5
var inline = makeMap('abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'); // Elements that you can, intentionally, leave open
// (and which close themselves)
var closeSelf = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'); // Attributes that have their values filled in disabled="disabled"
var fillAttrs = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'); // Special Elements (can contain anything)
var special = makeMap('script,style');
function HTMLParser(html, handler) {
var index;
var chars;
var match;
var stack = [];
var last = html;
stack.last = function () {
return this[this.length - 1];
};
while (html) {
chars = true; // Make sure we're not in a script or style element
if (!stack.last() || !special[stack.last()]) {
// Comment
if (html.indexOf('<!--') == 0) {
index = html.indexOf('-->');
if (index >= 0) {
if (handler.comment) {
handler.comment(html.substring(4, index));
}
html = html.substring(index + 3);
chars = false;
} // end tag
} else if (html.indexOf('</') == 0) {
match = html.match(endTag);
if (match) {
html = html.substring(match[0].length);
match[0].replace(endTag, parseEndTag);
chars = false;
} // start tag
} else if (html.indexOf('<') == 0) {
match = html.match(startTag);
if (match) {
html = html.substring(match[0].length);
match[0].replace(startTag, parseStartTag);
chars = false;
}
}
if (chars) {
index = html.indexOf('<');
var text = index < 0 ? html : html.substring(0, index);
html = index < 0 ? '' : html.substring(index);
if (handler.chars) {
handler.chars(text);
}
}
} else {
html = html.replace(new RegExp('([\\s\\S]*?)<\/' + stack.last() + '[^>]*>'), function (all, text) {
text = text.replace(/<!--([\s\S]*?)-->|<!\[CDATA\[([\s\S]*?)]]>/g, '$1$2');
if (handler.chars) {
handler.chars(text);
}
return '';
});
parseEndTag('', stack.last());
}
if (html == last) {
throw 'Parse Error: ' + html;
}
last = html;
} // Clean up any remaining tags
parseEndTag();
function parseStartTag(tag, tagName, rest, unary) {
tagName = tagName.toLowerCase();
if (block[tagName]) {
while (stack.last() && inline[stack.last()]) {
parseEndTag('', stack.last());
}
}
if (closeSelf[tagName] && stack.last() == tagName) {
parseEndTag('', tagName);
}
unary = empty[tagName] || !!unary;
if (!unary) {
stack.push(tagName);
}
if (handler.start) {
var attrs = [];
rest.replace(attr, function (match, name) {
var value = arguments[2] ? arguments[2] : arguments[3] ? arguments[3] : arguments[4] ? arguments[4] : fillAttrs[name] ? name : '';
attrs.push({
name: name,
value: value,
escaped: value.replace(/(^|[^\\])"/g, '$1\\\"') // "
});
});
if (handler.start) {
handler.start(tagName, attrs, unary);
}
}
}
function parseEndTag(tag, tagName) {
// If no tag name is provided, clean shop
if (!tagName) {
var pos = 0;
} // Find the closest opened tag of the same type
else {
for (var pos = stack.length - 1; pos >= 0; pos--) {
if (stack[pos] == tagName) {
break;
}
}
}
if (pos >= 0) {
// Close all the open elements, up the stack
for (var i = stack.length - 1; i >= pos; i--) {
if (handler.end) {
handler.end(stack[i]);
}
} // Remove the open elements from the stack
stack.length = pos;
}
}
}
function makeMap(str) {
var obj = {};
var items = str.split(',');
for (var i = 0; i < items.length; i++) {
obj[items[i]] = true;
}
return obj;
}
function removeDOCTYPE(html) {
return html.replace(/<\?xml.*\?>\n/, '').replace(/<!doctype.*>\n/, '').replace(/<!DOCTYPE.*>\n/, '');
}
function parseAttrs(attrs) {
return attrs.reduce(function (pre, attr) {
var value = attr.value;
var name = attr.name;
if (pre[name]) {
pre[name] = pre[name] + " " + value;
} else {
pre[name] = value;
}
return pre;
}, {});
}
function parseHtml(html) {
html = removeDOCTYPE(html);
var stacks = [];
var results = {
node: 'root',
children: []
};
HTMLParser(html, {
start: function start(tag, attrs, unary) {
var node = {
name: tag
};
if (attrs.length !== 0) {
node.attrs = parseAttrs(attrs);
}
if (unary) {
var parent = stacks[0] || results;
if (!parent.children) {
parent.children = [];
}
parent.children.push(node);
} else {
stacks.unshift(node);
}
},
end: function end(tag) {
var node = stacks.shift();
if (node.name !== tag) console.error('invalid state: mismatch end tag');
if (stacks.length === 0) {
results.children.push(node);
} else {
var parent = stacks[0];
if (!parent.children) {
parent.children = [];
}
parent.children.push(node);
}
},
chars: function chars(text) {
var node = {
type: 'text',
text: text
};
if (stacks.length === 0) {
results.children.push(node);
} else {
var parent = stacks[0];
if (!parent.children) {
parent.children = [];
}
parent.children.push(node);
}
},
comment: function comment(text) {
var node = {
node: 'comment',
text: text
};
var parent = stacks[0];
if (!parent.children) {
parent.children = [];
}
parent.children.push(node);
}
});
return results.children;
}
export default parseHtml;

84
common/letter.js Normal file
View File

@ -0,0 +1,84 @@
export default {
list: [
'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z'
],
listDatacom: [{
value: 'A',
text: "A"
}, {
value: 'B',
text: "B"
}, {
value: 'C',
text: "C"
}, {
value: 'D',
text: "D"
}, {
value: 'E',
text: "F"
}, {
value: 'G',
text: "G"
}, {
value: 'H',
text: "H"
}, {
value: 'I',
text: "I"
}, {
value: 'J',
text: "J"
}, {
value: 'K',
text: "K"
}, {
value: 'L',
text: "L"
}, {
value: 'M',
text: "M"
}, {
value: 'N',
text: "N"
}, {
value: 'O',
text: "O"
}, {
value: 'P',
text: "P"
}, {
value: 'Q',
text: "Q"
}, {
value: 'R',
text: "R"
}, {
value: 'S',
text: "S"
}, {
value: 'T',
text: "T"
}, {
value: 'U',
text: "U"
}, {
value: 'V',
text: "V"
}, {
value: 'W',
text: "W"
}, {
value: 'X',
text: "X"
}, {
value: 'Y',
text: "Y"
}, {
value: 'Z',
text: "Z"
}]
}

36
common/openApp.js Normal file
View File

@ -0,0 +1,36 @@
/*
创建在h5端全局悬浮引导用户下载app的功能
如不需要本功能直接移除配置文件app.config.js下的h5/openApp即可
*/
import CONFIG from '../app.config.js';
const CONFIG_OPEN = CONFIG.h5.openApp || {};
// 仅H5端添加"打开APP"
export default function() {
// #ifdef H5
if (!CONFIG_OPEN.openUrl) return;
let openLogo = CONFIG_OPEN.logo ?
`<img src="${CONFIG_OPEN.logo}" style="width: 2rem;height: 2rem;border-radius: 3px;">` : '';
let openApp = document.createElement("div");
openApp.id = 'openApp';
openApp.style =
'position: fixed;background:#FFFFFF;box-shadow: #eeeeee 1px 1px 9px; ;top: 0;left: 0;right: 0;z-index: 999;width: 100%;height: 45px;display: flex;flex-direction: row;justify-content: space-between;align-items: center;box-sizing: border-box;padding: 0 0.5rem;'
openApp.innerHTML = `
<div style="display: flex;flex-direction: row;justify-content: flex-start;align-items: center;">
${openLogo}
<div style="padding-left: 0.3rem;font-size: 12px;">${CONFIG_OPEN.appname || ''}</div>
</div>
<div class="openBtn" style="padding: 5px;font-size:12px;border-radius: 2px;border: 1px solid #007AFF;color: #007AFF;">下载app</div>
`;
document.body.insertBefore(openApp, document.body.firstChild);
document.body.style = 'height:calc(100% - 45px); margin-top:45px;';
openApp.addEventListener('click', e => {
var target = e.target || e.srcElement;
if (target.className.indexOf('openBtn') >= 0) {
window.location.href = CONFIG_OPEN.openUrl;
}
})
//#endif
}

245
common/permission.js Normal file
View File

@ -0,0 +1,245 @@
/// null = 未请求1 = 已允许0 = 拒绝|受限, 2 = 系统未开启
var isIOS
function album() {
var result = 0;
var PHPhotoLibrary = plus.ios.import("PHPhotoLibrary");
var authStatus = PHPhotoLibrary.authorizationStatus();
if (authStatus === 0) {
result = null;
} else if (authStatus == 3) {
result = 1;
} else {
result = 0;
}
plus.ios.deleteObject(PHPhotoLibrary);
return result;
}
function camera() {
var result = 0;
var AVCaptureDevice = plus.ios.import("AVCaptureDevice");
var authStatus = AVCaptureDevice.authorizationStatusForMediaType('vide');
if (authStatus === 0) {
result = null;
} else if (authStatus == 3) {
result = 1;
} else {
result = 0;
}
plus.ios.deleteObject(AVCaptureDevice);
return result;
}
function location() {
var result = 0;
var cllocationManger = plus.ios.import("CLLocationManager");
var enable = cllocationManger.locationServicesEnabled();
var status = cllocationManger.authorizationStatus();
if (!enable) {
result = 2;
} else if (status === 0) {
result = null;
} else if (status === 3 || status === 4) {
result = 1;
} else {
result = 0;
}
plus.ios.deleteObject(cllocationManger);
return result;
}
function push() {
var result = 0;
var UIApplication = plus.ios.import("UIApplication");
var app = UIApplication.sharedApplication();
var enabledTypes = 0;
if (app.currentUserNotificationSettings) {
var settings = app.currentUserNotificationSettings();
enabledTypes = settings.plusGetAttribute("types");
if (enabledTypes == 0) {
result = 0;
console.log("推送权限没有开启");
} else {
result = 1;
console.log("已经开启推送功能!")
}
plus.ios.deleteObject(settings);
} else {
enabledTypes = app.enabledRemoteNotificationTypes();
if (enabledTypes == 0) {
result = 3;
console.log("推送权限没有开启!");
} else {
result = 4;
console.log("已经开启推送功能!")
}
}
plus.ios.deleteObject(app);
plus.ios.deleteObject(UIApplication);
return result;
}
function contact() {
var result = 0;
var CNContactStore = plus.ios.import("CNContactStore");
var cnAuthStatus = CNContactStore.authorizationStatusForEntityType(0);
if (cnAuthStatus === 0) {
result = null;
} else if (cnAuthStatus == 3) {
result = 1;
} else {
result = 0;
}
plus.ios.deleteObject(CNContactStore);
return result;
}
function record() {
var result = null;
var avaudiosession = plus.ios.import("AVAudioSession");
var avaudio = avaudiosession.sharedInstance();
var status = avaudio.recordPermission();
// console.log("permissionStatus:" + status);
if (status === 1970168948) {
result = null;
} else if (status === 1735552628) {
result = 1;
} else {
result = 0;
}
plus.ios.deleteObject(avaudiosession);
return result;
}
function calendar() {
var result = null;
var EKEventStore = plus.ios.import("EKEventStore");
var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(0);
if (ekAuthStatus == 3) {
result = 1;
console.log("日历权限已经开启");
} else {
console.log("日历权限没有开启");
}
plus.ios.deleteObject(EKEventStore);
return result;
}
function memo() {
var result = null;
var EKEventStore = plus.ios.import("EKEventStore");
var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(1);
if (ekAuthStatus == 3) {
result = 1;
console.log("备忘录权限已经开启");
} else {
console.log("备忘录权限没有开启");
}
plus.ios.deleteObject(EKEventStore);
return result;
}
function requestIOS(permissionID) {
return new Promise((resolve, reject) => {
switch (permissionID) {
case "push":
resolve(push());
break;
case "location":
resolve(location());
break;
case "record":
resolve(record());
break;
case "camera":
resolve(camera());
break;
case "album":
resolve(album());
break;
case "contact":
resolve(contact());
break;
case "calendar":
resolve(calendar());
break;
case "memo":
resolve(memo());
break;
default:
resolve(0);
break;
}
});
}
function requestAndroid(permissionID) {
return new Promise((resolve, reject) => {
plus.android.requestPermissions(
[permissionID],
function(resultObj) {
var result = 0;
for (var i = 0; i < resultObj.granted.length; i++) {
var grantedPermission = resultObj.granted[i];
console.log('已获取的权限:' + grantedPermission);
result = 1
}
for (var i = 0; i < resultObj.deniedPresent.length; i++) {
var deniedPresentPermission = resultObj.deniedPresent[i];
console.log('拒绝本次申请的权限:' + deniedPresentPermission);
result = 0
}
for (var i = 0; i < resultObj.deniedAlways.length; i++) {
var deniedAlwaysPermission = resultObj.deniedAlways[i];
console.log('永久拒绝申请的权限:' + deniedAlwaysPermission);
result = -1
}
resolve(result);
},
function(error) {
console.log('result error: ' + error.message)
resolve({
code: error.code,
message: error.message
});
}
);
});
}
function gotoAppPermissionSetting() {
if (permission.isIOS) {
var UIApplication = plus.ios.import("UIApplication");
var application2 = UIApplication.sharedApplication();
var NSURL2 = plus.ios.import("NSURL");
var setting2 = NSURL2.URLWithString("app-settings:");
application2.openURL(setting2);
plus.ios.deleteObject(setting2);
plus.ios.deleteObject(NSURL2);
plus.ios.deleteObject(application2);
} else {
var Intent = plus.android.importClass("android.content.Intent");
var Settings = plus.android.importClass("android.provider.Settings");
var Uri = plus.android.importClass("android.net.Uri");
var mainActivity = plus.android.runtimeMainActivity();
var intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
intent.setData(uri);
mainActivity.startActivity(intent);
}
}
const permission = {
get isIOS() {
return typeof isIOS === 'boolean' ? isIOS : (isIOS = uni.getSystemInfoSync().platform === 'ios')
},
requestIOS: requestIOS,
requestAndroid: requestAndroid,
gotoAppSetting: gotoAppPermissionSetting
}
export default permission

503
common/province.js Normal file
View File

@ -0,0 +1,503 @@
export default {
listByCode: {
'110000': "北京",
'120000': "天津",
'130000': "河北省",
'140000': "山西省",
'150000': "内蒙古自治区",
'210000': "辽宁省",
'220000': "吉林省",
'230000': "黑龙江省",
'310000': "上海",
'320000': "江苏省",
'330000': "浙江省",
'340000': "安徽省",
'350000': "福建省",
'360000': "江西省",
'370000': "山东省",
'410000': "河南省",
'420000': "湖北省",
'430000': "湖南省",
'440000': "广东省",
'450000': "广西壮族自治区",
'460000': "海南省",
'500000': "重庆",
'510000': "四川省",
'520000': "贵州省",
'530000': "云南省",
'540000': "西藏自治区",
'610000': "陕西省",
'620000': "甘肃省",
'630000': "青海省",
'640000': "宁夏回族自治区",
'650000': "新疆维吾尔自治区",
'710000': "台湾省",
'810000': "香港特别行政区",
'820000': "澳门特别行政区",
'990000': "海外",
},
listByTitle: {
"北京": '110000',
"天津": '120000',
"河北省": '130000',
"山西省": '140000',
"内蒙古自治区": '150000',
"辽宁省": '210000',
"吉林省": '220000',
"黑龙江省": '230000',
"上海": '310000',
"江苏省": '320000',
"浙江省": '330000',
"安徽省": '340000',
"福建省": '350000',
"江西省": '360000',
"山东省": '370000',
"河南省": '410000',
"湖北省": '420000',
"湖南省": '430000',
"广东省": '440000',
"广西壮族自治区": '450000',
"海南省": '460000',
"重庆": '500000',
"四川省": '510000',
"贵州省": '520000',
"云南省": '530000',
"西藏自治区": '540000',
"陕西省": '610000',
"甘肃省": '620000',
"青海省": '630000',
"宁夏回族自治区": '640000',
"新疆维吾尔自治区": '650000',
"台湾省": '710000',
"香港特别行政区": '810000',
"澳门特别行政区": '820000',
"海外": '990000',
},
listByChar: {
beijing: {
k: '110000',
v: "北京"
},
tianjin: {
k: '120000',
v: "天津"
},
hebei: {
k: '130000',
v: "河北省"
},
shanxi1: {
k: '140000',
v: "山西省"
},
neimenggu: {
k: '150000',
v: "内蒙古自治区"
},
liaoning: {
k: '210000',
v: "辽宁省"
},
jilin: {
k: '220000',
v: "吉林省"
},
heilongjiang: {
k: '230000',
v: "黑龙江省"
},
shanghai: {
k: '310000',
v: "上海"
},
jiangsu: {
k: '320000',
v: "江苏省"
},
zhejiang: {
k: '330000',
v: "浙江省"
},
anhui: {
k: '340000',
v: "安徽省"
},
fujian: {
k: '350000',
v: "福建省"
},
jiangxi: {
k: '360000',
v: "江西省"
},
shandong: {
k: '370000',
v: "山东省"
},
henan: {
k: '410000',
v: "河南省"
},
hubei: {
k: '420000',
v: "湖北省"
},
hunan: {
k: '430000',
v: "湖南省"
},
guangdong: {
k: '440000',
v: "广东省"
},
guangxi: {
k: '450000',
v: "广西壮族自治区"
},
hainan: {
k: '460000',
v: "海南省"
},
chongqing: {
k: '500000',
v: "重庆"
},
sichuan: {
k: '510000',
v: "四川省"
},
guizhou: {
k: '520000',
v: "贵州省"
},
yunnan: {
k: '530000',
v: "云南省"
},
xizang: {
k: '540000',
v: "西藏自治区"
},
shanxi2: {
k: '610000',
v: "陕西省"
},
gansu: {
k: '620000',
v: "甘肃省"
},
qinghai: {
k: '630000',
v: "青海省"
},
ningxia: {
k: '640000',
v: "宁夏回族自治区"
},
xinjiang: {
k: '650000',
v: "新疆维吾尔自治区"
},
taiwan: {
k: '710000',
v: "台湾省"
},
xianggang: {
k: '810000',
v: "香港特别行政区"
},
aomen: {
k: '820000',
v: "澳门特别行政区"
},
haiwai: {
k: '990000',
v: "海外"
},
},
listDatacom: [{
value: '110000',
text: "北京"
},
{
value: '120000',
text: "天津"
},
{
value: '130000',
text: "河北省"
},
{
value: '140000',
text: "山西省"
},
{
value: '150000',
text: "内蒙古自治区"
},
{
value: '210000',
text: "辽宁省"
},
{
value: '220000',
text: "吉林省"
},
{
value: '230000',
text: "黑龙江省"
},
{
value: '310000',
text: "上海"
},
{
value: '320000',
text: "江苏省"
},
{
value: '330000',
text: "浙江省"
},
{
value: '340000',
text: "安徽省"
},
{
value: '350000',
text: "福建省"
},
{
value: '360000',
text: "江西省"
},
{
value: '370000',
text: "山东省"
},
{
value: '410000',
text: "河南省"
},
{
value: '420000',
text: "湖北省"
},
{
value: '430000',
text: "湖南省"
},
{
value: '440000',
text: "广东省"
},
{
value: '450000',
text: "广西壮族自治区"
},
{
value: '460000',
text: "海南省"
},
{
value: '500000',
text: "重庆"
},
{
value: '510000',
text: "四川省"
},
{
value: '520000',
text: "贵州省"
},
{
value: '530000',
text: "云南省"
},
{
value: '540000',
text: "西藏自治区"
},
{
value: '610000',
text: "陕西省"
},
{
value: '620000',
text: "甘肃省"
},
{
value: '630000',
text: "青海省"
},
{
value: '640000',
text: "宁夏回族自治区"
},
{
value: '650000',
text: "新疆维吾尔自治区"
},
{
value: '710000',
text: "台湾省"
},
{
value: '810000',
text: "香港特别行政区"
},
{
value: '820000',
text: "澳门特别行政区"
},
{
value: '990000',
text: "海外"
},
],
listCarP: [{
value: '京',
text: "京"
},
{
value: '津',
text: "津"
},
{
value: '冀',
text: "冀"
},
{
value: '晋',
text: "晋"
},
{
value: '蒙',
text: "蒙"
},
{
value: '辽',
text: "辽"
},
{
value: '220000',
text: "吉林省"
},
{
value: '230000',
text: "黑龙江省"
},
{
value: '310000',
text: "上海"
},
{
value: '320000',
text: "江苏省"
},
{
value: '330000',
text: "浙江省"
},
{
value: '340000',
text: "安徽省"
},
{
value: '350000',
text: "福建省"
},
{
value: '360000',
text: "江西省"
},
{
value: '370000',
text: "山东省"
},
{
value: '410000',
text: "河南省"
},
{
value: '420000',
text: "湖北省"
},
{
value: '430000',
text: "湖南省"
},
{
value: '440000',
text: "广东省"
},
{
value: '450000',
text: "广西壮族自治区"
},
{
value: '460000',
text: "海南省"
},
{
value: '500000',
text: "重庆"
},
{
value: '510000',
text: "四川省"
},
{
value: '520000',
text: "贵州省"
},
{
value: '530000',
text: "云南省"
},
{
value: '540000',
text: "西藏自治区"
},
{
value: '610000',
text: "陕西省"
},
{
value: '620000',
text: "甘肃省"
},
{
value: '630000',
text: "青海省"
},
{
value: '640000',
text: "宁夏回族自治区"
},
{
value: '650000',
text: "新疆维吾尔自治区"
},
{
value: '710000',
text: "台湾省"
},
{
value: '810000',
text: "香港特别行政区"
},
{
value: '820000',
text: "澳门特别行政区"
},
{
value: '990000',
text: "海外"
},
],
}

160
common/util.js Normal file
View File

@ -0,0 +1,160 @@
import permission from "./permission"
function formatTime(time) {
if (typeof time !== 'number' || time < 0) {
return time
}
var hour = parseInt(time / 3600)
time = time % 3600
var minute = parseInt(time / 60)
time = time % 60
var second = time
return ([hour, minute, second]).map(function(n) {
n = n.toString()
return n[1] ? n : '0' + n
}).join(':')
}
function formatLocation(longitude, latitude) {
if (typeof longitude === 'string' && typeof latitude === 'string') {
longitude = parseFloat(longitude)
latitude = parseFloat(latitude)
}
longitude = longitude.toFixed(2)
latitude = latitude.toFixed(2)
return {
longitude: longitude.toString().split('.'),
latitude: latitude.toString().split('.')
}
}
var dateUtils = {
UNITS: {
'年': 31557600000,
'月': 2629800000,
'天': 86400000,
'小时': 3600000,
'分钟': 60000,
'秒': 1000
},
humanize: function(milliseconds) {
var humanize = '';
for (var key in this.UNITS) {
if (milliseconds >= this.UNITS[key]) {
humanize = Math.floor(milliseconds / this.UNITS[key]) + key + '前';
break;
}
}
return humanize || '刚刚';
},
format: function(dateStr) {
var date = this.parse(dateStr)
var diff = Date.now() - date.getTime();
if (diff < this.UNITS['天']) {
return this.humanize(diff);
}
var _format = function(number) {
return (number < 10 ? ('0' + number) : number);
};
return date.getFullYear() + '/' + _format(date.getMonth() + 1) + '/' + _format(date.getDate()) + '-' +
_format(date.getHours()) + ':' + _format(date.getMinutes());
},
parse: function(str) { //将"yyyy-mm-dd HH:MM:ss"格式的字符串转化为一个Date对象
var a = str.split(/[^0-9]/);
return new Date(a[0], a[1] - 1, a[2], a[3], a[4], a[5]);
}
};
// 验证并返回手机号或null
function isPhone(phone) {
var pattern = /^(?:(?:\+|00)86)?1(?:3\d|4[5-79]|5[0-35-9]|6[5-7]|7[0-8]|8\d|9[189])\d{8}$/;
var regex = new RegExp(pattern);
var res = regex.exec(phone);
if (res) {
return res[0];
}
return false;
}
function tel(phone) {
permission.requestAndroid('contact').then(
(res) => {
if (res !== 1) {
uni.showModal({
title: '权限申请',
content: '拨打电话需要您的授权',
success: function(res) {
if (res.confirm) {
permission.gotoAppSetting();
} else if (res.cancel) {
// console.log('用户点击取消');
}
}
})
} else {
uni.makePhoneCall({
phoneNumber: phone
})
}
}
);
}
const captcha = {
ls: 'LocalCaptcha',
get: function(scence = 'vcode', useLetter = 'false') {
let digits = '0123456789';
let upperCaseLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let code = '',
charType = digits;
for (let i = 0; i < 4; i++) {
// 随机选择生成数字还是大写字母
if (useLetter === true) charType = Math.random() < 0.5 ? digits : upperCaseLetters;
code += charType[Math.floor(Math.random() * charType.length)];
}
var codes = uni.getStorageSync(this.ls) || {};
codes[scence] = code;
uni.getStorageSync(this.ls, codes);
return code;
},
check: function(scence = 'vcode', code) {
var codes = uni.getStorageSync(this.ls) || {};
if (codes[scence] === code) {
return true;
}
return false;
},
pop: function(scence = 'vcode', useLetter = 'false') {
var code = this.get(scence, useLetter);
uni.showModal({
title: '请输入数字 ' + code + ' 验证',
editable: true,
success: function(res) {
if (res.confirm) {
// console.log('数字码', res.content)
if (res.content === code) return true;
return false;
} else if (res.cancel) {
// console.log('用户点击取消');
return false;
}
}
})
}
};
export default {
formatTime,
formatLocation,
dateUtils,
tel,
captcha,
isPhone
}