初始化万家商超用户端仓库
This commit is contained in:
849
common/utils/area-code.js
Normal file
849
common/utils/area-code.js
Normal file
@ -0,0 +1,849 @@
|
||||
export default [{
|
||||
"city": "中国大陆",
|
||||
"code": "+86"
|
||||
},
|
||||
{
|
||||
"city": "中国香港",
|
||||
"code": "+852"
|
||||
},
|
||||
{
|
||||
"city": "中国澳门",
|
||||
"code": "+853"
|
||||
},
|
||||
{
|
||||
"city": "中国台湾",
|
||||
"code": "+886"
|
||||
},
|
||||
{
|
||||
"city": "新加坡",
|
||||
"code": "+65"
|
||||
},
|
||||
{
|
||||
"city": "阿富汗",
|
||||
"code": "+93"
|
||||
},
|
||||
{
|
||||
"city": "阿尔巴尼亚",
|
||||
"code": "+355"
|
||||
},
|
||||
{
|
||||
"city": "阿尔格拉",
|
||||
"code": "+213"
|
||||
},
|
||||
{
|
||||
"city": "安道尔",
|
||||
"code": "+376"
|
||||
},
|
||||
{
|
||||
"city": "安哥拉",
|
||||
"code": "+244"
|
||||
},
|
||||
{
|
||||
"city": "安圭拉",
|
||||
"code": "+1264"
|
||||
},
|
||||
{
|
||||
"city": "阿森松岛",
|
||||
"code": "+247"
|
||||
},
|
||||
{
|
||||
"city": "安提瓜和巴布达",
|
||||
"code": "+1268"
|
||||
},
|
||||
{
|
||||
"city": "阿根廷",
|
||||
"code": "+54"
|
||||
},
|
||||
{
|
||||
"city": "亚美尼亚",
|
||||
"code": "+374"
|
||||
},
|
||||
{
|
||||
"city": "阿鲁巴",
|
||||
"code": "+297"
|
||||
},
|
||||
{
|
||||
"city": "澳大利亚",
|
||||
"code": "+61"
|
||||
},
|
||||
{
|
||||
"city": "奥地利",
|
||||
"code": "+43"
|
||||
},
|
||||
{
|
||||
"city": "阿塞拜疆",
|
||||
"code": "+994"
|
||||
},
|
||||
{
|
||||
"city": "巴哈马",
|
||||
"code": "+1242"
|
||||
},
|
||||
{
|
||||
"city": "巴林",
|
||||
"code": "+973"
|
||||
},
|
||||
{
|
||||
"city": "孟加拉国",
|
||||
"code": "+880"
|
||||
},
|
||||
{
|
||||
"city": "巴巴多斯",
|
||||
"code": "+1246"
|
||||
},
|
||||
{
|
||||
"city": "白俄罗斯",
|
||||
"code": "+375"
|
||||
},
|
||||
{
|
||||
"city": "比利时",
|
||||
"code": "+32"
|
||||
},
|
||||
{
|
||||
"city": "伯利兹",
|
||||
"code": "+501"
|
||||
},
|
||||
{
|
||||
"city": "贝宁",
|
||||
"code": "+229"
|
||||
},
|
||||
{
|
||||
"city": "百慕大",
|
||||
"code": "+1441"
|
||||
},
|
||||
{
|
||||
"city": "不丹",
|
||||
"code": "+975"
|
||||
},
|
||||
{
|
||||
"city": "玻利维亚",
|
||||
"code": "+591"
|
||||
},
|
||||
{
|
||||
"city": "波斯尼亚和黑塞哥维那",
|
||||
"code": "+387"
|
||||
},
|
||||
{
|
||||
"city": "博茨瓦纳",
|
||||
"code": "+267"
|
||||
},
|
||||
{
|
||||
"city": "巴西",
|
||||
"code": "+55"
|
||||
},
|
||||
{
|
||||
"city": "文莱",
|
||||
"code": "+673"
|
||||
},
|
||||
{
|
||||
"city": "保加利亚",
|
||||
"code": "+359"
|
||||
},
|
||||
{
|
||||
"city": "布基纳法索",
|
||||
"code": "+226"
|
||||
},
|
||||
{
|
||||
"city": "布隆迪",
|
||||
"code": "+257"
|
||||
},
|
||||
{
|
||||
"city": "柬埔寨",
|
||||
"code": "+855"
|
||||
},
|
||||
{
|
||||
"city": "喀麦隆",
|
||||
"code": "+237"
|
||||
},
|
||||
{
|
||||
"city": "加拿大",
|
||||
"code": "+1"
|
||||
},
|
||||
{
|
||||
"city": "佛得角",
|
||||
"code": "+238"
|
||||
},
|
||||
{
|
||||
"city": "开曼群岛",
|
||||
"code": "+1345"
|
||||
},
|
||||
{
|
||||
"city": "中非共和国",
|
||||
"code": "+236"
|
||||
},
|
||||
{
|
||||
"city": "乍得",
|
||||
"code": "+235"
|
||||
},
|
||||
{
|
||||
"city": "智利",
|
||||
"code": "+56"
|
||||
},
|
||||
{
|
||||
"city": "哥伦比亚",
|
||||
"code": "+57"
|
||||
},
|
||||
{
|
||||
"city": "科摩罗",
|
||||
"code": "+269"
|
||||
},
|
||||
{
|
||||
"city": "刚果共和国",
|
||||
"code": "+242"
|
||||
},
|
||||
{
|
||||
"city": "刚果民主共和国",
|
||||
"code": "+243"
|
||||
},
|
||||
{
|
||||
"city": "库克群岛",
|
||||
"code": "+682"
|
||||
},
|
||||
{
|
||||
"city": "哥斯达黎加",
|
||||
"code": "+506"
|
||||
},
|
||||
{
|
||||
"city": "科特迪沃",
|
||||
"code": "+225"
|
||||
},
|
||||
{
|
||||
"city": "克罗地亚",
|
||||
"code": "+385"
|
||||
},
|
||||
{
|
||||
"city": "古巴",
|
||||
"code": "+53"
|
||||
},
|
||||
{
|
||||
"city": "塞浦路斯",
|
||||
"code": "+357"
|
||||
},
|
||||
{
|
||||
"city": "+捷克共和国",
|
||||
"code": "+420"
|
||||
},
|
||||
{
|
||||
"city": "丹麦",
|
||||
"code": "+45"
|
||||
},
|
||||
{
|
||||
"city": "吉布提",
|
||||
"code": "+253"
|
||||
},
|
||||
{
|
||||
"city": "多米尼加",
|
||||
"code": "+1767"
|
||||
},
|
||||
{
|
||||
"city": "多米尼加共和国",
|
||||
"code": "+1809"
|
||||
},
|
||||
{
|
||||
"city": "厄瓜多尔",
|
||||
"code": "+593"
|
||||
},
|
||||
{
|
||||
"city": "埃及",
|
||||
"code": "+20"
|
||||
},
|
||||
{
|
||||
"city": "艾萨尔瓦多",
|
||||
"code": "+503"
|
||||
},
|
||||
{
|
||||
"city": "爱沙尼亚",
|
||||
"code": "+372"
|
||||
},
|
||||
{
|
||||
"city": "埃塞俄比亚",
|
||||
"code": "+251"
|
||||
},
|
||||
{
|
||||
"city": "法罗群岛",
|
||||
"code": "+298"
|
||||
},
|
||||
{
|
||||
"city": "斐济",
|
||||
"code": "+679"
|
||||
},
|
||||
{
|
||||
"city": "芬兰",
|
||||
"code": "+358"
|
||||
},
|
||||
{
|
||||
"city": "法国",
|
||||
"code": "+33"
|
||||
},
|
||||
{
|
||||
"city": "法属圭亚那",
|
||||
"code": "+594"
|
||||
},
|
||||
{
|
||||
"city": "法属波利尼西亚",
|
||||
"code": "+689"
|
||||
},
|
||||
{
|
||||
"city": "加蓬",
|
||||
"code": "+241"
|
||||
},
|
||||
{
|
||||
"city": "冈比亚",
|
||||
"code": "+220"
|
||||
},
|
||||
{
|
||||
"city": "格鲁吉亚",
|
||||
"code": "+995"
|
||||
},
|
||||
{
|
||||
"city": "德国",
|
||||
"code": "+94"
|
||||
},
|
||||
{
|
||||
"city": "加纳",
|
||||
"code": "+233"
|
||||
},
|
||||
{
|
||||
"city": "直布罗陀",
|
||||
"code": "+350"
|
||||
},
|
||||
{
|
||||
"city": "希腊",
|
||||
"code": "+30"
|
||||
},
|
||||
{
|
||||
"city": "格陵兰",
|
||||
"code": "+299"
|
||||
},
|
||||
{
|
||||
"city": "格林纳达",
|
||||
"code": "+1473"
|
||||
},
|
||||
{
|
||||
"city": "瓜德罗普",
|
||||
"code": "+590"
|
||||
},
|
||||
{
|
||||
"city": "关岛",
|
||||
"code": "+1671"
|
||||
},
|
||||
{
|
||||
"city": "危地马拉",
|
||||
"code": "+502"
|
||||
},
|
||||
{
|
||||
"city": "几内亚",
|
||||
"code": "+240"
|
||||
},
|
||||
{
|
||||
"city": "根西",
|
||||
"code": "+44"
|
||||
},
|
||||
{
|
||||
"city": "几内亚",
|
||||
"code": "+224"
|
||||
},
|
||||
{
|
||||
"city": "圭亚那",
|
||||
"code": "+592"
|
||||
},
|
||||
{
|
||||
"city": "海地",
|
||||
"code": "+509"
|
||||
},
|
||||
{
|
||||
"city": "洪都拉斯",
|
||||
"code": "+504"
|
||||
},
|
||||
{
|
||||
"city": "缅甸",
|
||||
"code": "+95"
|
||||
},
|
||||
{
|
||||
"city": "匈牙利",
|
||||
"code": "+36"
|
||||
},
|
||||
{
|
||||
"city": "冰岛",
|
||||
"code": "+354"
|
||||
},
|
||||
{
|
||||
"city": "印度",
|
||||
"code": "+91"
|
||||
},
|
||||
{
|
||||
"city": "印度尼西亚",
|
||||
"code": "+62"
|
||||
},
|
||||
{
|
||||
"city": "伊朗",
|
||||
"code": "+98"
|
||||
},
|
||||
{
|
||||
"city": "伊拉克",
|
||||
"code": "+964"
|
||||
},
|
||||
{
|
||||
"city": "爱尔兰",
|
||||
"code": "+353"
|
||||
},
|
||||
{
|
||||
"city": "马恩岛",
|
||||
"code": "+44"
|
||||
},
|
||||
{
|
||||
"city": "以色列",
|
||||
"code": "+972"
|
||||
},
|
||||
{
|
||||
"city": "意大利",
|
||||
"code": "+93"
|
||||
},
|
||||
{
|
||||
"city": "牙买加",
|
||||
"code": "+1876"
|
||||
},
|
||||
{
|
||||
"city": "日本",
|
||||
"code": "+81"
|
||||
},
|
||||
{
|
||||
"city": "泽西岛",
|
||||
"code": "+44"
|
||||
},
|
||||
{
|
||||
"city": "约旦",
|
||||
"code": "+962"
|
||||
},
|
||||
{
|
||||
"city": "哈萨克斯坦",
|
||||
"code": "+7"
|
||||
},
|
||||
{
|
||||
"city": "肯尼亚",
|
||||
"code": "+254"
|
||||
},
|
||||
{
|
||||
"city": "科索沃",
|
||||
"code": "+383"
|
||||
},
|
||||
{
|
||||
"city": "科威特",
|
||||
"code": "+965"
|
||||
},
|
||||
{
|
||||
"city": "吉尔吉斯斯坦",
|
||||
"code": "+996"
|
||||
},
|
||||
{
|
||||
"city": "老挝",
|
||||
"code": "+856"
|
||||
},
|
||||
{
|
||||
"city": "拉脱维亚",
|
||||
"code": "+371"
|
||||
},
|
||||
{
|
||||
"city": "黎巴嫩",
|
||||
"code": "+961"
|
||||
},
|
||||
{
|
||||
"city": "莱索托",
|
||||
"code": "+266"
|
||||
},
|
||||
{
|
||||
"city": "利比里亚",
|
||||
"code": "+231"
|
||||
},
|
||||
{
|
||||
"city": "利比亚",
|
||||
"code": "+218"
|
||||
},
|
||||
{
|
||||
"city": "列支敦士登",
|
||||
"code": "+423"
|
||||
},
|
||||
{
|
||||
"city": "立陶宛",
|
||||
"code": "+370"
|
||||
},
|
||||
{
|
||||
"city": "卢森堡",
|
||||
"code": "+352"
|
||||
},
|
||||
{
|
||||
"city": "马其顿",
|
||||
"code": "+389"
|
||||
},
|
||||
{
|
||||
"city": "马达加斯加",
|
||||
"code": "+261"
|
||||
},
|
||||
{
|
||||
"city": "马拉维",
|
||||
"code": "+265"
|
||||
},
|
||||
{
|
||||
"city": "马来西亚",
|
||||
"code": "+60"
|
||||
},
|
||||
{
|
||||
"city": "马尔代夫",
|
||||
"code": "+960"
|
||||
},
|
||||
{
|
||||
"city": "马里",
|
||||
"code": "+223"
|
||||
},
|
||||
{
|
||||
"city": "马耳他",
|
||||
"code": "+356"
|
||||
},
|
||||
{
|
||||
"city": "马提尼克",
|
||||
"code": "+596"
|
||||
},
|
||||
{
|
||||
"city": "毛里塔尼亚",
|
||||
"code": "+222"
|
||||
},
|
||||
{
|
||||
"city": "毛里求斯",
|
||||
"code": "+230"
|
||||
},
|
||||
{
|
||||
"city": "马约特",
|
||||
"code": "+262"
|
||||
},
|
||||
{
|
||||
"city": "墨西哥",
|
||||
"code": "+52"
|
||||
},
|
||||
{
|
||||
"city": "摩尔多瓦",
|
||||
"code": "+373"
|
||||
},
|
||||
{
|
||||
"city": "摩纳哥",
|
||||
"code": "+377"
|
||||
},
|
||||
{
|
||||
"city": "蒙古",
|
||||
"code": "+976"
|
||||
},
|
||||
{
|
||||
"city": "黑山",
|
||||
"code": "+382"
|
||||
},
|
||||
{
|
||||
"city": "蒙特塞拉特",
|
||||
"code": "+1664"
|
||||
},
|
||||
{
|
||||
"city": "摩洛哥",
|
||||
"code": "+212"
|
||||
},
|
||||
{
|
||||
"city": "莫桑比克",
|
||||
"code": "+258"
|
||||
},
|
||||
{
|
||||
"city": "纳米比亚",
|
||||
"code": "+264"
|
||||
},
|
||||
{
|
||||
"city": "尼泊尔",
|
||||
"code": "+977"
|
||||
},
|
||||
{
|
||||
"city": "荷兰",
|
||||
"code": "+31"
|
||||
},
|
||||
{
|
||||
"city": "荷属安的列斯",
|
||||
"code": "+599"
|
||||
},
|
||||
{
|
||||
"city": "新喀里多尼亚",
|
||||
"code": "+687"
|
||||
},
|
||||
{
|
||||
"city": "新西兰",
|
||||
"code": "+64"
|
||||
},
|
||||
{
|
||||
"city": "尼加拉瓜",
|
||||
"code": "+505"
|
||||
},
|
||||
{
|
||||
"city": "尼日尔",
|
||||
"code": "+227"
|
||||
},
|
||||
{
|
||||
"city": "尼日利亚",
|
||||
"code": "+234"
|
||||
},
|
||||
{
|
||||
"city": "挪威",
|
||||
"code": "+47"
|
||||
},
|
||||
{
|
||||
"city": "阿曼",
|
||||
"code": "+968"
|
||||
},
|
||||
{
|
||||
"city": "巴基斯坦",
|
||||
"code": "+92"
|
||||
},
|
||||
{
|
||||
"city": "巴勒斯坦",
|
||||
"code": "+970"
|
||||
},
|
||||
{
|
||||
"city": "巴拿马",
|
||||
"code": "+507"
|
||||
},
|
||||
{
|
||||
"city": "巴布亚新几内亚",
|
||||
"code": "+675"
|
||||
},
|
||||
{
|
||||
"city": "巴拉圭",
|
||||
"code": "+595"
|
||||
},
|
||||
{
|
||||
"city": "秘鲁",
|
||||
"code": "+51"
|
||||
},
|
||||
{
|
||||
"city": "菲律宾",
|
||||
"code": "+63"
|
||||
},
|
||||
{
|
||||
"city": "波兰",
|
||||
"code": "+48"
|
||||
},
|
||||
{
|
||||
"city": "葡萄牙",
|
||||
"code": "+351"
|
||||
},
|
||||
{
|
||||
"city": "波多黎各",
|
||||
"code": "+1"
|
||||
},
|
||||
{
|
||||
"city": "库塔",
|
||||
"code": "+974"
|
||||
},
|
||||
{
|
||||
"city": "留尼汪",
|
||||
"code": "+262"
|
||||
},
|
||||
{
|
||||
"city": "罗马尼亚",
|
||||
"code": "+40"
|
||||
},
|
||||
{
|
||||
"city": "俄罗斯",
|
||||
"code": "+7"
|
||||
},
|
||||
{
|
||||
"city": "卢旺达",
|
||||
"code": "+250"
|
||||
},
|
||||
{
|
||||
"city": "萨摩亚东部",
|
||||
"code": "+684"
|
||||
},
|
||||
{
|
||||
"city": "萨摩亚西部",
|
||||
"code": "+685"
|
||||
},
|
||||
{
|
||||
"city": "圣马力诺",
|
||||
"code": "+378"
|
||||
},
|
||||
{
|
||||
"city": "圣多美和普林西比",
|
||||
"code": "+239"
|
||||
},
|
||||
{
|
||||
"city": "沙特阿拉伯",
|
||||
"code": "+966"
|
||||
},
|
||||
{
|
||||
"city": "塞内加尔",
|
||||
"code": "+221"
|
||||
},
|
||||
{
|
||||
"city": "塞尔维亚",
|
||||
"code": "+381"
|
||||
},
|
||||
{
|
||||
"city": "塞舌尔",
|
||||
"code": "+248"
|
||||
},
|
||||
{
|
||||
"city": "塞拉利昂",
|
||||
"code": "+232"
|
||||
},
|
||||
{
|
||||
"city": "斯洛伐克",
|
||||
"code": "+421"
|
||||
},
|
||||
{
|
||||
"city": "斯洛文尼亚",
|
||||
"code": "+386"
|
||||
},
|
||||
{
|
||||
"city": "南非",
|
||||
"code": "+27"
|
||||
},
|
||||
{
|
||||
"city": "韩国",
|
||||
"code": "+82"
|
||||
},
|
||||
{
|
||||
"city": "西班牙",
|
||||
"code": "+34"
|
||||
},
|
||||
{
|
||||
"city": "斯里兰卡",
|
||||
"code": "+94"
|
||||
},
|
||||
{
|
||||
"city": "圣基茨和尼维斯",
|
||||
"code": "+1869"
|
||||
},
|
||||
{
|
||||
"city": "圣卢西亚",
|
||||
"code": "+1758"
|
||||
},
|
||||
{
|
||||
"city": "圣文森特",
|
||||
"code": "+1784"
|
||||
},
|
||||
{
|
||||
"city": "苏丹",
|
||||
"code": "+249"
|
||||
},
|
||||
{
|
||||
"city": "苏里南",
|
||||
"code": "+597"
|
||||
},
|
||||
{
|
||||
"city": "斯威士兰",
|
||||
"code": "+268"
|
||||
},
|
||||
{
|
||||
"city": "瑞典",
|
||||
"code": "+46"
|
||||
},
|
||||
{
|
||||
"city": "瑞士",
|
||||
"code": "+41"
|
||||
},
|
||||
{
|
||||
"city": "叙利亚",
|
||||
"code": "+963"
|
||||
},
|
||||
{
|
||||
"city": "塔吉克斯坦",
|
||||
"code": "+992"
|
||||
},
|
||||
{
|
||||
"city": "坦桑尼亚",
|
||||
"code": "+255"
|
||||
},
|
||||
{
|
||||
"city": "泰国",
|
||||
"code": "+66"
|
||||
},
|
||||
{
|
||||
"city": "东帝汶",
|
||||
"code": "+670"
|
||||
},
|
||||
{
|
||||
"city": "多哥",
|
||||
"code": "+228"
|
||||
},
|
||||
{
|
||||
"city": "汤加",
|
||||
"code": "+676"
|
||||
},
|
||||
{
|
||||
"city": "特立尼达和多巴哥",
|
||||
"code": "+1868"
|
||||
},
|
||||
{
|
||||
"city": "突尼斯",
|
||||
"code": "+216"
|
||||
},
|
||||
{
|
||||
"city": "土耳其",
|
||||
"code": "+90"
|
||||
},
|
||||
{
|
||||
"city": "土库曼斯坦",
|
||||
"code": "+993"
|
||||
},
|
||||
{
|
||||
"city": "特克斯和凯科斯群岛",
|
||||
"code": "+1649"
|
||||
},
|
||||
{
|
||||
"city": "乌干达",
|
||||
"code": "+256"
|
||||
},
|
||||
{
|
||||
"city": "乌克兰",
|
||||
"code": "+380"
|
||||
},
|
||||
{
|
||||
"city": "阿拉伯联合酋长国",
|
||||
"code": "+971"
|
||||
},
|
||||
{
|
||||
"city": "英国",
|
||||
"code": "+44"
|
||||
},
|
||||
{
|
||||
"city": "美国",
|
||||
"code": "+1"
|
||||
},
|
||||
{
|
||||
"city": "乌拉圭",
|
||||
"code": "+598"
|
||||
},
|
||||
{
|
||||
"city": "乌兹别克斯坦",
|
||||
"code": "+998"
|
||||
},
|
||||
{
|
||||
"city": "瓦努阿图",
|
||||
"code": "+678"
|
||||
},
|
||||
{
|
||||
"city": "委内瑞拉",
|
||||
"code": "+58"
|
||||
},
|
||||
{
|
||||
"city": "越南",
|
||||
"code": "+84"
|
||||
},
|
||||
{
|
||||
"city": "维尔京群岛",
|
||||
"code": "+1340"
|
||||
},
|
||||
{
|
||||
"city": "也门",
|
||||
"code": "+967"
|
||||
},
|
||||
{
|
||||
"city": "赞比亚",
|
||||
"code": "+260"
|
||||
},
|
||||
{
|
||||
"city": "津巴布韦",
|
||||
"code": "+263"
|
||||
}
|
||||
]
|
||||
54
common/utils/fs.js
Normal file
54
common/utils/fs.js
Normal file
@ -0,0 +1,54 @@
|
||||
// #ifdef APP-PLUS
|
||||
// 获取文件内容
|
||||
async function getFileContext(path, dirEntry) {
|
||||
let deffered;
|
||||
let fileReader = new plus.io.FileReader();
|
||||
fileReader.onloadend = function(evt) {
|
||||
deffered(evt.target.result);
|
||||
}
|
||||
let file = await getFile(path, dirEntry);
|
||||
fileReader.readAsText(file, 'utf-8');
|
||||
return new Promise((resolve) => {
|
||||
deffered = resolve;
|
||||
});
|
||||
}
|
||||
// 获取文件
|
||||
async function getFile(fileName, dirEntry) {
|
||||
return new Promise(async (resolve) => {
|
||||
let fileEntry = await getFileEntry(fileName, dirEntry);
|
||||
fileEntry.file(function(file) {
|
||||
resolve(file);
|
||||
});
|
||||
})
|
||||
}
|
||||
// 获取文件
|
||||
async function getFileEntry(fileName, dirEntry) {
|
||||
return new Promise((resolve) => {
|
||||
plus.io.requestFileSystem(plus.io.PRIVATE_DOC, function(fs) {
|
||||
let entry = dirEntry || fs.root;
|
||||
entry.getFile(fileName, {
|
||||
create: true
|
||||
}, function(fileEntry) {
|
||||
resolve(fileEntry);
|
||||
});
|
||||
});
|
||||
})
|
||||
}
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN
|
||||
async function getFileContext(path, dirEntry) {
|
||||
let FileSystemManager = wx.getFileSystemManager();
|
||||
let content = FileSystemManager.readFileSync(path,'utf-8');
|
||||
return content;
|
||||
}
|
||||
// #endif
|
||||
|
||||
function initI18n(){
|
||||
return Promise.resolve();
|
||||
|
||||
}
|
||||
|
||||
export default {
|
||||
getFileContext,
|
||||
initI18n,
|
||||
}
|
||||
17
common/utils/index.js
Normal file
17
common/utils/index.js
Normal file
@ -0,0 +1,17 @@
|
||||
import Router from './router.js'
|
||||
import UploadImage from './upload-image.js'
|
||||
import UploadFileToQINIU from './upload-file-to-qiniu.js'
|
||||
import UploadFileToOSS from './upload-file-to-oss.js'
|
||||
import { message } from './message.js'
|
||||
import { validate } from './validate.js'
|
||||
|
||||
|
||||
export {
|
||||
message,
|
||||
validate,
|
||||
UploadImage,
|
||||
UploadFileToQINIU,
|
||||
UploadFileToOSS,
|
||||
Router
|
||||
}
|
||||
|
||||
60
common/utils/message.js
Normal file
60
common/utils/message.js
Normal file
@ -0,0 +1,60 @@
|
||||
const message = {
|
||||
|
||||
success(params) {
|
||||
if (typeof params !== 'object') params = {
|
||||
content: params + ''
|
||||
};
|
||||
uni.showToast({
|
||||
title: params.content || '',
|
||||
icon: 'success',
|
||||
duration: params.duration || 1500,
|
||||
success: params.resolve
|
||||
})
|
||||
return true
|
||||
},
|
||||
|
||||
error(params) {
|
||||
if (typeof params !== 'object') params = {
|
||||
content: params + ''
|
||||
};
|
||||
uni.showToast({
|
||||
title: params.content,
|
||||
icon: 'error',
|
||||
duration: params.duration || 1500,
|
||||
success: params.resolve
|
||||
})
|
||||
return true
|
||||
},
|
||||
|
||||
info(params) {
|
||||
if (typeof params !== 'object') params = {
|
||||
content: params + ''
|
||||
};
|
||||
uni.showToast({
|
||||
title: params.content || '',
|
||||
icon: 'none',
|
||||
// position: 'bottom',
|
||||
duration: params.duration || 1500,
|
||||
success: params.resolve
|
||||
})
|
||||
return true
|
||||
},
|
||||
|
||||
tips(params) {
|
||||
if (typeof params !== 'object') params = {
|
||||
content: params + ''
|
||||
};
|
||||
uni.showToast({
|
||||
title: params.content || '',
|
||||
icon: 'none',
|
||||
// position: 'bottom',
|
||||
duration: params.duration || 1500,
|
||||
success: params.resolve
|
||||
})
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
message
|
||||
};
|
||||
92
common/utils/permissionTips.js
Normal file
92
common/utils/permissionTips.js
Normal file
@ -0,0 +1,92 @@
|
||||
function showView(permissions) {
|
||||
// #ifdef APP-PLUS
|
||||
const permissionTipsArr = [{
|
||||
"keyName": "android.permission.INTERNET",
|
||||
"title": '使用网络权限',
|
||||
"content": '与服务器进行数据交换,如同步用户数据、获取最新信息等'
|
||||
}, {
|
||||
"keyName": "android.permission.READ_EXTERNAL_STORAGE",
|
||||
"title": '读写SD卡权限',
|
||||
"content": '访问用户的媒体库,如照片相册等'
|
||||
}, {
|
||||
"keyName": "android.permission.WRITE_EXTERNAL_STORAGE",
|
||||
"title": '读写SD卡权限',
|
||||
"content": '访问用户的媒体库,如照片相册等'
|
||||
}, {
|
||||
"keyName": "android.permission.READ_PHONE_STATE",
|
||||
"title": '读取设备标识权限',
|
||||
"content": '根据设备特征提供定制化的用户体验'
|
||||
}, {
|
||||
"keyName": "android.permission.CAMERA",
|
||||
"title": '拍照权限',
|
||||
"content": '请求相机权限,使用相机,用于扫描二维码或者上传图片'
|
||||
}, {
|
||||
"keyName": "android.permission.ACCESS_COARSE_LOCATION",
|
||||
"title": '定位权限',
|
||||
"content": '根据用户位置提供附近的商家、餐厅等信息'
|
||||
}, {
|
||||
"keyName": "android.permission.ACCESS_FINE_LOCATION",
|
||||
"title": '定位权限',
|
||||
"content": '根据用户位置提供附近的商家、餐厅等信息'
|
||||
},{
|
||||
"keyName": "android.permission.CALL_PHONE",
|
||||
"title": '拨打电话权限',
|
||||
"content": '请求拨打电话权限,用于联系商家或者平台'
|
||||
}]
|
||||
const permissionTips = Array.isArray(permissionTipsArr) ? permissionTipsArr.reduce((accumulator, {
|
||||
keyName,
|
||||
title,
|
||||
content,
|
||||
}) => {
|
||||
accumulator[keyName] =
|
||||
`<div class='tips-item'><div class='title'>${title}</div><div class='center'>${content}</div></div>`;
|
||||
return accumulator;
|
||||
}, {}) : {};
|
||||
let tips = ''
|
||||
permissions.map(key => {
|
||||
if (permissionTips[key]) {
|
||||
tips += permissionTips[key]
|
||||
} else {
|
||||
console.log(key + '未配置提示语');
|
||||
}
|
||||
})
|
||||
if (!tips) return null
|
||||
const systemInfo = uni.getSystemInfoSync()
|
||||
let wvPath = '/static/permissionTips.html'
|
||||
let wv = new plus.webview.create(
|
||||
wvPath, 'permissionTips', {
|
||||
'uni-app': 'none',
|
||||
top: systemInfo.statusBarHeight,
|
||||
left: 0,
|
||||
width: systemInfo.screenWidth,
|
||||
height: systemInfo.screenHeight - systemInfo.statusBarHeight,
|
||||
background: 'transparent',
|
||||
}, {
|
||||
tips,
|
||||
}
|
||||
)
|
||||
wv.show()
|
||||
return wv
|
||||
// #endif
|
||||
return null
|
||||
}
|
||||
export function permissionListener() {
|
||||
// showView(["android.permission.CAMERA", "android.permission.ACCESS_COARSE_LOCATION", "android.permission.READ_PHONE_STATE", "android.permission.READ_EXTERNAL_STORAGE"])
|
||||
let view = null
|
||||
let createRequestPermissionListener = uni.createRequestPermissionListener();
|
||||
createRequestPermissionListener.onRequest((e) => {
|
||||
console.log('onRequest', e);
|
||||
});
|
||||
createRequestPermissionListener.onConfirm((e) => {
|
||||
console.log('onConfirm', e);
|
||||
if (view && view.close) view.close()
|
||||
if (view && view.destroy) view.destroy()
|
||||
view = showView(e)
|
||||
});
|
||||
createRequestPermissionListener.onComplete((e) => {
|
||||
if (view && view.close) view.close()
|
||||
if (view && view.destroy) view.destroy()
|
||||
view = null
|
||||
console.log('onComplete', e);
|
||||
});
|
||||
}
|
||||
77
common/utils/richText.js
Normal file
77
common/utils/richText.js
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
graceUI rich-text 加强工具
|
||||
link : graceui.hcoder.net
|
||||
author : 5213606@qq.com 深海
|
||||
|
||||
版权声明 :
|
||||
GraceUI 的版权约束是不能转售或者将 GraceUI 直接发布到公开渠道!
|
||||
侵权必究,请遵守版权约定!
|
||||
*/
|
||||
|
||||
// 正则变量
|
||||
var graceRichTextReg;
|
||||
|
||||
// 批量替换的样式 [ 根据项目需求自行设置 ]
|
||||
var GRT = [
|
||||
// div 样式
|
||||
['div', "line-height:2em;width:auto;height:auto;"],
|
||||
// h1 样式
|
||||
['h1', "font-size:3em; line-height:1.5em;"],
|
||||
// h2 样式
|
||||
['h2', "font-size:2em; line-height:1.8em;"],
|
||||
// h3 样式
|
||||
['h3', "font-size:1.6em; line-height:2em;"],
|
||||
// h4 样式
|
||||
['h4', "font-size:1.2em; line-height:2em;"],
|
||||
// h5 样式
|
||||
['h5', "font-size:1em; line-height:2em;"],
|
||||
// h6 样式
|
||||
['h6', "font-size:0.9em; line-height:2em;"],
|
||||
// p 样式
|
||||
['p', "font-size:1em; line-height:2em;"],
|
||||
// b 样式
|
||||
['b', "font-size:1em; line-height:2em;"],
|
||||
// strong 样式
|
||||
['strong', "font-size:1em; line-height:2em;"],
|
||||
// code 样式
|
||||
['code', "font-size:1em; line-height:1.2em; background:#F6F7F8; padding:8px 2%; width:96%;"],
|
||||
// img 样式
|
||||
['img', "width:100%; display: block;"],
|
||||
// blockquote
|
||||
['blockquote', "font-size:1em; border-left:3px solid #D1D1D1; line-height:2em; border-radius:5px; background:#F6F7F8; padding:8px 2%;"],
|
||||
// li 样式
|
||||
['ul', "padding:5px 0; list-style:none; padding:0; margin:0;"],
|
||||
['li', "line-height:1.5em; padding:5px 0; list-style:none; padding:0; margin:0; margin-top:10px;"],
|
||||
// table
|
||||
['table', "width:100%; border-left:1px solid #F2F3F4; border-top:1px solid #F2F3F4;"],
|
||||
['th', "border-right:1px solid #F2F3F4; border-bottom:1px solid #F2F3F4;"],
|
||||
['td', "border-right:1px solid #F2F3F4; border-bottom:1px solid #F2F3F4; padding-left:5px;"]
|
||||
];
|
||||
|
||||
|
||||
export default {
|
||||
format: function (html) {
|
||||
html = html.replace(/<pre.*pre>?/gis, function (word) {
|
||||
word = word.replace(/[\n]/gi, '<br />');
|
||||
word = word.replace(/ /gi, '<span style="padding-left:2em;"></span>');
|
||||
return word.replace(/[\t]/gi, '<span style="padding-left:2em;"></span>');
|
||||
});
|
||||
html = html.replace(/<pre/gi, '<p style="font-size:1em; margin:12px 0; line-height:1.2em; background:#F6F7F8; border-radius:5px; padding:8px 4%; width:92%;"');
|
||||
html = html.replace(/<\/pre/gi, "</p");
|
||||
for (let i = 0; i < GRT.length; i++) {
|
||||
graceRichTextReg = new RegExp('<' + GRT[i][0] + '>|<' + GRT[i][0] + ' (.*?)>', 'gi');
|
||||
html = html.replace(graceRichTextReg, function (word) {
|
||||
// 分析 dom 上是否带有 style=""
|
||||
if (word.indexOf('style=') != -1) {
|
||||
var regIn = new RegExp('<' + GRT[i][0] + '(.*?)style="(.*?)"(.*?)(/?)>', 'gi');
|
||||
return word.replace(regIn, '<' + GRT[i][0] + '$1style="$2 ' + GRT[i][1] + '"$3$4>');
|
||||
} else {
|
||||
var regIn = new RegExp('<' + GRT[i][0] + '(.*?)(/?)>', 'gi');
|
||||
return word.replace(regIn, '<' + GRT[i][0] + '$1 style="' + GRT[i][1] + '$2">');
|
||||
}
|
||||
});
|
||||
}
|
||||
return html;
|
||||
}
|
||||
|
||||
}
|
||||
74
common/utils/router.js
Normal file
74
common/utils/router.js
Normal file
@ -0,0 +1,74 @@
|
||||
import { LOGIN_PAGE_URL } from '../config.js'
|
||||
export default class Router {
|
||||
|
||||
needLoginPages = []
|
||||
|
||||
constructor(options) {
|
||||
if (options) this.needLoginPages = options.needLoginPages || [];
|
||||
|
||||
}
|
||||
splicingUrl(res) {
|
||||
return typeof res === 'string' ? res : res.params ? res.url + '?' + Object.keys(res.params).map(item =>
|
||||
`${item}=${res.params[item]}`).join('&') : res.url;
|
||||
}
|
||||
|
||||
testingNeedLogin(url) {
|
||||
return this.needLoginPages.findIndex(item => item == url || url.startsWith(item)) != -1
|
||||
}
|
||||
|
||||
getNeedLoginPages() {
|
||||
return this.needLoginPages
|
||||
}
|
||||
switchTab(url) {
|
||||
url = this.splicingUrl(url)
|
||||
if (this.testingNeedLogin(url)) {
|
||||
if (global.token) {
|
||||
uni.switchTab({
|
||||
url
|
||||
});
|
||||
} else {
|
||||
uni.navigateTo({
|
||||
url: LOGIN_PAGE_URL
|
||||
})
|
||||
}
|
||||
return false;
|
||||
}
|
||||
uni.switchTab({
|
||||
url
|
||||
});
|
||||
}
|
||||
redirectTo(url) {
|
||||
url = this.splicingUrl(url)
|
||||
if (this.testingNeedLogin(url)) {
|
||||
uni.redirectTo({
|
||||
url: global.token ? url : LOGIN_PAGE_URL
|
||||
});
|
||||
return false;
|
||||
}
|
||||
uni.redirectTo({
|
||||
url
|
||||
});
|
||||
}
|
||||
|
||||
reLaunch(url) {
|
||||
uni.reLaunch({
|
||||
url
|
||||
});
|
||||
}
|
||||
navigateBack(num) {
|
||||
uni.navigateBack({ delta: num || 1 });
|
||||
}
|
||||
navigateTo(url) {
|
||||
url = this.splicingUrl(url)
|
||||
console.log(url)
|
||||
if (this.testingNeedLogin(url)) {
|
||||
uni.navigateTo({
|
||||
url: global.token ? url : LOGIN_PAGE_URL
|
||||
});
|
||||
return false;
|
||||
}
|
||||
uni.navigateTo({
|
||||
url
|
||||
});
|
||||
}
|
||||
}
|
||||
70
common/utils/upload-file-to-oss.js
Normal file
70
common/utils/upload-file-to-oss.js
Normal file
@ -0,0 +1,70 @@
|
||||
import { message } from './message.js'
|
||||
import { http } from '@/common/api/index.js';
|
||||
|
||||
export default class UploadFileToOSS {
|
||||
|
||||
/**
|
||||
* [constructor description]
|
||||
* @param {[Array]} files [chooseImg选中的tempFilePaths、chooseVideo选中的rempFilePath]
|
||||
* @param {[Object]} json [success每上传成功一张调用 complete全部上传完成调用]
|
||||
* @return {[void]} [description]
|
||||
*/
|
||||
|
||||
constructor(files, json) {
|
||||
if (!Array.isArray(files)) {
|
||||
throw new Error('Class UploadFileToOSS parameter must be an array');
|
||||
}
|
||||
this.data = [];
|
||||
this.fn = json.success;
|
||||
this.complete = json.complete;
|
||||
this.files = files;
|
||||
this.fileLen = this.files.length;
|
||||
this.curIndex = 0;
|
||||
uni.showLoading({
|
||||
title: global.i18n.t('上传中')
|
||||
});
|
||||
this.upload();
|
||||
}
|
||||
|
||||
upload() {
|
||||
http.get(global.apiUrls.queryAutograph).then(res => {
|
||||
if (res.data.code == 1) {
|
||||
let ossData = res.data.data;
|
||||
uni.uploadFile({
|
||||
url: ossData.host,
|
||||
filePath: this.files[this.curIndex],
|
||||
name: 'file',
|
||||
formData: {
|
||||
key: ossData.key, // 文件名
|
||||
policy: ossData.policy, // 后台获取超时时间
|
||||
OSSAccessKeyId: ossData.OSSAccessKeyId, // 后台获取临时ID
|
||||
success_action_status: ossData.success_action_status, // 让服务端返回200,不然,默认会返回204
|
||||
signature: ossData.signature // 后台获取签名
|
||||
},
|
||||
success: res => {
|
||||
console.log(res);
|
||||
if (res.statusCode == 200) {
|
||||
this.data.push({
|
||||
id: ossData.key,
|
||||
path: ossData.host + '/' + ossData.key
|
||||
});
|
||||
if (this.fn) this.fn(this.data);
|
||||
} else {
|
||||
message.info(global.i18n.t('上传失败,请重试'))
|
||||
}
|
||||
},
|
||||
complete: () => {
|
||||
this.curIndex++; // 当前文件执行完上传后,开始上传下一张
|
||||
if (this.curIndex == this.fileLen) { // 当文件传完时,停止调用
|
||||
this.complete(this.data);
|
||||
uni.hideLoading()
|
||||
} else { // 若文件还没有传完,则继续调用函数
|
||||
this.upload();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
70
common/utils/upload-file-to-qiniu.js
Normal file
70
common/utils/upload-file-to-qiniu.js
Normal file
@ -0,0 +1,70 @@
|
||||
import { message } from './message.js'
|
||||
import { http } from '@/common/api/index.js';
|
||||
|
||||
export default class UploadFileToQINIU {
|
||||
/**
|
||||
* [constructor description]
|
||||
* @param {[Array]} files [chooseImg选中的tempFilePaths、chooseVideo选中的rempFilePath]
|
||||
* @param {[Object]} json [success每上传成功一张调用 complete全部上传完成调用]
|
||||
* @return {[void]} [description]
|
||||
*/
|
||||
|
||||
constructor(files, json) {
|
||||
if (!Array.isArray(files)) {
|
||||
throw new Error('Class UploadFileToQINIU parameter must be an array');
|
||||
}
|
||||
this.data = [];
|
||||
this.fn = json.success;
|
||||
this.complete = json.complete;
|
||||
this.files = files;
|
||||
this.fileLen = this.files.length;
|
||||
this.curIndex = 0;
|
||||
uni.showLoading({
|
||||
title: global.i18n.t('上传中')
|
||||
});
|
||||
this.upload();
|
||||
}
|
||||
|
||||
upload() {
|
||||
http.post(global.apiUrls.postQINIUToken).then(res => {
|
||||
console.log(res)
|
||||
if (res.data.code == 1) {
|
||||
let ossData = res.data.data;
|
||||
uni.uploadFile({
|
||||
url: 'https://up-z2.qiniup.com', // 七牛云资源存储地区 默认华南地区
|
||||
filePath: this.files[this.curIndex],
|
||||
name: 'file',
|
||||
formData: {
|
||||
key: ossData.fileName, // 文件名
|
||||
token: ossData.token, // token
|
||||
},
|
||||
success: res => {
|
||||
console.log(res);
|
||||
if (res.statusCode == 200) {
|
||||
let videoInfo = JSON.parse(res.data)
|
||||
console.log(videoInfo)
|
||||
this.data.push({
|
||||
id: videoInfo.key,
|
||||
path: ossData.baseUrl + videoInfo.key,
|
||||
cover: ossData.baseUrl + videoInfo.key + '?vframe/jpg/offset/0'
|
||||
});
|
||||
if (this.fn) this.fn(this.data);
|
||||
} else {
|
||||
message.info(global.i18n.t('视频上传失败,请重试'))
|
||||
}
|
||||
},
|
||||
complete: () => {
|
||||
this.curIndex++; // 当前文件执行完上传后,开始上传下一张
|
||||
if (this.curIndex == this.fileLen) { // 当文件传完时,停止调用
|
||||
this.complete(this.data);
|
||||
uni.hideLoading()
|
||||
} else { // 若文件还没有传完,则继续调用函数
|
||||
this.upload();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
65
common/utils/upload-image-old.js
Normal file
65
common/utils/upload-image-old.js
Normal file
@ -0,0 +1,65 @@
|
||||
import { UPLOAD_IMAGE_URL,SERIAL } from '../config.js'
|
||||
import { message } from './message.js'
|
||||
|
||||
export default class UploadImg {
|
||||
/**
|
||||
* [constructor description]
|
||||
* @param {[Array]} files [chooseImg选中的tempFilePaths]
|
||||
* @param {[Object]} json [success每上传成功一张调用 complete全部上传完成调用]
|
||||
* @return {[void]} [description]
|
||||
*/
|
||||
constructor(files, json) {
|
||||
if (!Array.isArray(files)) {
|
||||
throw new Error('Class UploadImg parameter must be an array');
|
||||
}
|
||||
let _this = this;
|
||||
_this.data = [];
|
||||
_this.fn = json.success;
|
||||
_this.complete = json.complete;
|
||||
_this.files = files;
|
||||
_this.fileLen = _this.files.length;
|
||||
_this.curIndex = 0;
|
||||
uni.showLoading({
|
||||
title: global.i18n['上传中'],
|
||||
mask: true
|
||||
});
|
||||
_this.upload();
|
||||
}
|
||||
|
||||
upload() {
|
||||
let _this = this;
|
||||
uni.uploadFile({
|
||||
url: UPLOAD_IMAGE_URL,
|
||||
filePath: this.files[this.curIndex],
|
||||
name: 'file',
|
||||
header: {
|
||||
'user-token': global.token || '',
|
||||
'Accept-Language': global.locale,
|
||||
'Accept-Serial': SERIAL,
|
||||
},
|
||||
formData: {
|
||||
'module': '',
|
||||
'dir': ''
|
||||
},
|
||||
success: res => {
|
||||
let data = JSON.parse(res.data);
|
||||
if (data.code == 1) {
|
||||
console.log("返回结果",data);
|
||||
this.data.push(data.data[0]);
|
||||
if (this.fn) this.fn(this.data);
|
||||
} else {
|
||||
message.info(global.i18n['图片上传失败,请重试'])
|
||||
}
|
||||
},
|
||||
complete: () => {
|
||||
this.curIndex++; // 这个图片执行完上传后,开始上传下一张
|
||||
if (this.curIndex == this.fileLen) { // 当图片传完时,停止调用
|
||||
this.complete(this.data);
|
||||
uni.hideLoading()
|
||||
} else { // 若图片还没有传完,则继续调用函数
|
||||
this.upload();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
258
common/utils/upload-image.js
Normal file
258
common/utils/upload-image.js
Normal file
@ -0,0 +1,258 @@
|
||||
import {
|
||||
message
|
||||
} from './message.js'
|
||||
import { host, SERIAL, API_VERSION, SERVER_TYPE } from '../config.js'
|
||||
import {
|
||||
http
|
||||
} from '@/common/api/index.js';
|
||||
import dayjs from '@/libs/day.js'
|
||||
const getUUID = () => {
|
||||
const S4 = () => ((((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1))
|
||||
return (S4() + S4() + '' + S4() + '' + S4() + '' + S4() + '' + S4() + S4() + S4()) + new Date().getTime()
|
||||
}
|
||||
// 获取文件后缀名
|
||||
const getSuffix = (fileName) => {
|
||||
let pos = fileName.lastIndexOf('.')
|
||||
return pos != -1 ? fileName.substring(pos) : ''
|
||||
}
|
||||
/* 判断url路径处理 */
|
||||
function posUrl(url) {
|
||||
let newUrl = ''
|
||||
if (/(http|https):\/\/([\w.]+\/?)\S*/.test(url)) {
|
||||
newUrl = url
|
||||
} else {
|
||||
newUrl = `${host}/api/${url}`
|
||||
}
|
||||
return newUrl
|
||||
}
|
||||
// 赛诸葛上传
|
||||
class SaiZhuGeUploadFiles {
|
||||
/**
|
||||
* [constructor description]
|
||||
* @param {[Array]} files [chooseImg选中的tempFilePaths、chooseVideo选中的rempFilePath]
|
||||
* @param {[Object]} json [success每上传成功一张调用 complete全部上传完成调用]
|
||||
* @return {[void]} [description]
|
||||
*/
|
||||
constructor(files, json) {
|
||||
if (!Array.isArray(files)) {
|
||||
throw new Error('Class UploadFileToOSS parameter must be an array');
|
||||
}
|
||||
this.data = [];
|
||||
this.fn = json.success;
|
||||
this.complete = json.complete;
|
||||
this.files = files;
|
||||
this.fileLen = this.files.length;
|
||||
this.curIndex = 0;
|
||||
this.resData = false;
|
||||
uni.showLoading({
|
||||
title: '加载中',
|
||||
mask: true
|
||||
})
|
||||
if (!this.resData) this.getUploadConfig()
|
||||
}
|
||||
async getUploadConfig() {
|
||||
try {
|
||||
let { data: { code, msg, data } } = await http.post(global.apiUrls.queryAutograph, { member_id: API_VERSION.replace(/\D/g, "") })
|
||||
if (code != 1) {
|
||||
uni.hideLoading()
|
||||
message.info(msg)
|
||||
return
|
||||
}
|
||||
this.resData = data
|
||||
this.uploadFile()
|
||||
} catch (error) {
|
||||
uni.hideLoading()
|
||||
message.info(msg)
|
||||
}
|
||||
}
|
||||
uploadFile() {
|
||||
let resData = this.resData
|
||||
const fileInfo = this.files[this.curIndex]
|
||||
let allowUploadFile = this.uploadVerification(fileInfo, resData.is_public, +resData.size)
|
||||
if (allowUploadFile !== true) {
|
||||
uni.hideLoading()
|
||||
return message.info('文件超出大小限制')
|
||||
}
|
||||
// deploy 1 本地服务器上传 否则 上传至oss
|
||||
if (resData.deploy == 1) this.uploadFileToLocal(resData)
|
||||
else this.uploadFileToOSS(resData)
|
||||
}
|
||||
// oss 上传验证
|
||||
uploadVerification(file, isPublic = 1, size = 2048) {
|
||||
const fileName = file.name
|
||||
let isSizt = isPublic === 1 ? file.size / 1024 < size : true
|
||||
if (!isSizt) return false
|
||||
return true
|
||||
}
|
||||
// 本地上传
|
||||
uploadFileToLocal(resData) {
|
||||
let fileInfo = this.files[this.curIndex]
|
||||
uni.uploadFile({
|
||||
url: posUrl(global.apiUrls.UPLOAD_IMAGE_URL),
|
||||
filePath: fileInfo.path,
|
||||
name: 'file',
|
||||
// #ifdef MP-DINGTALK
|
||||
fileType: "image",
|
||||
// #endif
|
||||
header: {
|
||||
'user-token': global.token || '',
|
||||
'Accept-Language': global.locale,
|
||||
'Accept-Serial': SERIAL,
|
||||
},
|
||||
formData: {
|
||||
'module': '',
|
||||
'dir': resData.dir || ''
|
||||
},
|
||||
success: res => {
|
||||
let data = JSON.parse(res.data);
|
||||
if (data.code == 1) {
|
||||
this.data.push({ name: fileInfo.name, ...data.data[0] });
|
||||
if (this.fn) this.fn(this.data);
|
||||
} else {
|
||||
message.info('上传失败,请重试')
|
||||
}
|
||||
},
|
||||
complete: () => {
|
||||
this.curIndex++; // 这个图片执行完上传后,开始上传下一张
|
||||
if (this.curIndex >= this.fileLen) { // 当图片传完时,停止调用
|
||||
this.complete(this.data);
|
||||
uni.hideLoading()
|
||||
} else { // 若图片还没有传完,则继续调用函数
|
||||
this.uploadFile();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// oss上传
|
||||
uploadFileToOSS(ossData) {
|
||||
const fileInfo = this.files[this.curIndex]
|
||||
let joint = getUUID()
|
||||
let fileName = `${joint}${getSuffix(fileInfo.name ?? fileInfo.path)}`
|
||||
let filePath = `${ossData.dir}${dayjs(new Date()).format('YYYY-MM-DD')}/${fileName}`
|
||||
let fileNetworkPath = `${ossData.host}/${filePath}`
|
||||
uni.uploadFile({
|
||||
url: ossData.host,
|
||||
filePath: fileInfo.path,
|
||||
// #ifdef MP-DINGTALK
|
||||
fileType: "image",
|
||||
// #endif
|
||||
name: 'file',
|
||||
formData: {
|
||||
key: filePath, // 文件名
|
||||
policy: ossData.policy, // 后台获取超时时间
|
||||
OSSAccessKeyId: ossData.accessid, // 后台获取临时ID
|
||||
success_action_status: 200, // 让服务端返回200,不然,默认会返回204
|
||||
signature: ossData.signature // 后台获取签名
|
||||
},
|
||||
success: res => {
|
||||
console.log(res);
|
||||
if (res.statusCode == 200) {
|
||||
this.data.push({
|
||||
id: fileNetworkPath,
|
||||
name: fileInfo.name || fileName,
|
||||
path: fileNetworkPath,
|
||||
thumb: fileNetworkPath + '?x-oss-process=video/snapshot,t_1000,m_fast',
|
||||
})
|
||||
if (this.fn) this.fn(this.data);
|
||||
} else {
|
||||
message.info('上传失败,请重试')
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
console.log(err);
|
||||
},
|
||||
complete: () => {
|
||||
this.curIndex++; // 当前文件执行完上传后,开始上传下一张
|
||||
if (this.curIndex >= this.fileLen) { // 当文件传完时,停止调用
|
||||
this.complete(this.data);
|
||||
uni.hideLoading()
|
||||
} else { // 若文件还没有传完,则继续调用函数
|
||||
this.uploadFile();
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
// 普通上传
|
||||
class OrdinaryUploadFiles {
|
||||
/**
|
||||
* [constructor description]
|
||||
* @param {[Array]} files [chooseImg选中的tempFilePaths]
|
||||
* @param {[Object]} json [success每上传成功一张调用 complete全部上传完成调用]
|
||||
* @return {[void]} [description]
|
||||
*/
|
||||
constructor(files, json) {
|
||||
|
||||
if (!Array.isArray(files)) {
|
||||
throw new Error('Class UploadImg parameter must be an array');
|
||||
}
|
||||
let _this = this;
|
||||
_this.data = [];
|
||||
_this.fn = json.success;
|
||||
_this.url = json.url ? host + '/api' + json.url : host + '/api' + global.apiUrls.UPLOAD_IMAGE_URL;
|
||||
_this.complete = json.complete;
|
||||
_this.files = files;
|
||||
_this.formData = json.formData || {};
|
||||
_this.fileLen = _this.files.length;
|
||||
_this.curIndex = 0;
|
||||
uni.showLoading({
|
||||
// title: '上传中'
|
||||
title: global.i18n.t('上传中')
|
||||
});
|
||||
_this.upload();
|
||||
}
|
||||
upload() {
|
||||
uni.uploadFile({
|
||||
url: this.url,
|
||||
filePath: this.files[this.curIndex].path,
|
||||
name: 'file',
|
||||
header: {
|
||||
'user-token': global.token || '',
|
||||
'Accept-Language': global.locale,
|
||||
'Accept-Serial': SERIAL,
|
||||
},
|
||||
formData: {
|
||||
'module': '',
|
||||
'dir': '',
|
||||
...this.formData
|
||||
},
|
||||
success: res => {
|
||||
let data = JSON.parse(res.data);
|
||||
if (data.code == 1) {
|
||||
let file = Array.isArray(data.data) ? data.data[0] : data.data
|
||||
file.thumb = file.path + '?x-oss-process=video/snapshot,t_1000,m_fast'
|
||||
this.data.push(file);
|
||||
if (this.fn) this.fn(this.data);
|
||||
} else {
|
||||
message.info(global.i18n.t('上传失败,请重试'))
|
||||
}
|
||||
},
|
||||
complete: () => {
|
||||
this.curIndex++; // 这个图片执行完上传后,开始上传下一张
|
||||
if (this.curIndex >= this.fileLen) { // 当图片传完时,停止调用
|
||||
this.complete(this.data);
|
||||
uni.hideLoading()
|
||||
} else { // 若图片还没有传完,则继续调用函数
|
||||
this.upload();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let UploadFiles = null
|
||||
|
||||
switch (SERVER_TYPE) {
|
||||
case 0://赛诸葛
|
||||
UploadFiles = SaiZhuGeUploadFiles
|
||||
break;
|
||||
case 1://java
|
||||
UploadFiles = OrdinaryUploadFiles
|
||||
break;
|
||||
default:
|
||||
UploadFiles = OrdinaryUploadFiles
|
||||
break;
|
||||
}
|
||||
|
||||
export default UploadFiles
|
||||
|
||||
640
common/utils/utils.js
Normal file
640
common/utils/utils.js
Normal file
@ -0,0 +1,640 @@
|
||||
import { LOGIN_PAGE_URL, needLoginPages } from '../config.js';
|
||||
import { Router } from '@/common/utils/index.js';
|
||||
/**
|
||||
* 节流原理:在一定时间内,只能触发一次
|
||||
*
|
||||
* @param {Function} func 要执行的回调函数
|
||||
* @param {Number} wait 延时的时间
|
||||
* @param {Boolean} immediate 是否立即执行
|
||||
* @return null
|
||||
*/
|
||||
let throttleTimer, throttleFlag;
|
||||
export function throttle(func, wait = 500, immediate = true) {
|
||||
if (immediate) {
|
||||
if (!throttleFlag) {
|
||||
throttleFlag = true;
|
||||
// 如果是立即执行,则在wait毫秒内开始时执行
|
||||
typeof func === 'function' && func();
|
||||
throttleTimer = setTimeout(() => {
|
||||
throttleFlag = false;
|
||||
}, wait);
|
||||
}
|
||||
} else {
|
||||
if (!throttleFlag) {
|
||||
throttleFlag = true
|
||||
// 如果是非立即执行,则在wait毫秒内的结束处执行
|
||||
throttleTimer = setTimeout(() => {
|
||||
throttleFlag = false
|
||||
typeof func === 'function' && func();
|
||||
}, wait);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
/**
|
||||
* 时间戳转为多久之前
|
||||
* @param String timestamp 时间戳
|
||||
* @param String | Boolean format 如果为时间格式字符串,超出一定时间范围,返回固定的时间格式;
|
||||
* 如果为布尔值false,无论什么时间,都返回多久以前的格式
|
||||
*/
|
||||
export function timeFrom(timestamp = null, format = 'yyyy-mm-dd') {
|
||||
if (timestamp == null) timestamp = Number(new Date());
|
||||
timestamp = parseInt(timestamp);
|
||||
// 判断用户输入的时间戳是秒还是毫秒,一般前端js获取的时间戳是毫秒(13位),后端传过来的为秒(10位)
|
||||
if (timestamp.toString().length == 10) timestamp *= 1000;
|
||||
var timer = (new Date()).getTime() - timestamp;
|
||||
timer = parseInt(timer / 1000);
|
||||
// 如果小于5分钟,则返回"刚刚",其他以此类推
|
||||
let tips = '';
|
||||
switch (true) {
|
||||
case timer < 300:
|
||||
tips = global.i18n.t('刚刚');
|
||||
break;
|
||||
case timer >= 300 && timer < 3600:
|
||||
tips = parseInt(timer / 60) + global.i18n.t('分钟前');
|
||||
break;
|
||||
case timer >= 3600 && timer < 86400:
|
||||
tips = parseInt(timer / 3600) + global.i18n.t('小时前');
|
||||
break;
|
||||
case timer >= 86400 && timer < 2592000:
|
||||
tips = parseInt(timer / 86400) + global.i18n.t('天前');
|
||||
break;
|
||||
default:
|
||||
// 如果format为false,则无论什么时间戳,都显示xx之前
|
||||
if (format === false) {
|
||||
if (timer >= 2592000 && timer < 365 * 86400) {
|
||||
tips = parseInt(timer / (86400 * 30)) + global.i18n.t('个月前');
|
||||
} else {
|
||||
tips = parseInt(timer / (86400 * 365)) + global.i18n.t('年前');
|
||||
}
|
||||
} else {
|
||||
tips = timeFormat(timestamp, format);
|
||||
}
|
||||
}
|
||||
return tips;
|
||||
}
|
||||
// 判断arr是否为一个数组,返回一个bool值
|
||||
export function isArray(arr) {
|
||||
return Object.prototype.toString.call(arr) === '[object Array]';
|
||||
}
|
||||
// 深度克隆
|
||||
export function deepClone(obj) {
|
||||
// 对常见的“非”值,直接返回原来值
|
||||
if ([null, undefined, NaN, false].includes(obj)) return obj;
|
||||
if (typeof obj !== "object" && typeof obj !== 'function') {
|
||||
//原始类型直接返回
|
||||
return obj;
|
||||
}
|
||||
var o = isArray(obj) ? [] : {};
|
||||
for (let i in obj) {
|
||||
if (obj.hasOwnProperty(i)) {
|
||||
o[i] = typeof obj[i] === "object" ? deepClone(obj[i]) : obj[i];
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
export function timeFormat(timestamp = null, fmt = 'yyyy-mm-dd') {
|
||||
// padStart 的 polyfill,因为某些机型或情况,还无法支持es7的padStart,比如电脑版的微信小程序
|
||||
// 所以这里做一个兼容polyfill的兼容处理
|
||||
if (!String.prototype.padStart) {
|
||||
// 为了方便表示这里 fillString 用了ES6 的默认参数,不影响理解
|
||||
String.prototype.padStart = function (maxLength, fillString = ' ') {
|
||||
if (Object.prototype.toString.call(fillString) !== "[object String]") throw new TypeError(
|
||||
'fillString must be String')
|
||||
let str = this
|
||||
// 返回 String(str) 这里是为了使返回的值是字符串字面量,在控制台中更符合直觉
|
||||
if (str.length >= maxLength) return String(str)
|
||||
let fillLength = maxLength - str.length,
|
||||
times = Math.ceil(fillLength / fillString.length)
|
||||
while (times >>= 1) {
|
||||
fillString += fillString
|
||||
if (times === 1) {
|
||||
fillString += fillString
|
||||
}
|
||||
}
|
||||
return fillString.slice(0, fillLength) + str;
|
||||
}
|
||||
}
|
||||
// 其他更多是格式化有如下:
|
||||
// yyyy:mm:dd|yyyy:mm|yyyy年mm月dd日|yyyy年mm月dd日 hh时MM分等,可自定义组合
|
||||
timestamp = parseInt(timestamp);
|
||||
// 如果为null,则格式化当前时间
|
||||
if (!timestamp) timestamp = Number(new Date());
|
||||
// 判断用户输入的时间戳是秒还是毫秒,一般前端js获取的时间戳是毫秒(13位),后端传过来的为秒(10位)
|
||||
if (timestamp.toString().length == 10) timestamp *= 1000;
|
||||
console.log('timestamp', timestamp)
|
||||
let date = new Date(timestamp);
|
||||
console.log(date);
|
||||
let ret;
|
||||
let opt = {
|
||||
"y+": date.getFullYear().toString(), // 年
|
||||
"m+": (date.getMonth() + 1).toString(), // 月
|
||||
"d+": date.getDate().toString(), // 日
|
||||
"h+": date.getHours().toString(), // 时
|
||||
"M+": date.getMinutes().toString(), // 分
|
||||
"s+": date.getSeconds().toString() // 秒
|
||||
// 有其他格式化字符需求可以继续添加,必须转化成字符串
|
||||
};
|
||||
for (let k in opt) {
|
||||
ret = new RegExp("(" + k + ")").exec(fmt);
|
||||
if (ret) {
|
||||
fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
|
||||
};
|
||||
};
|
||||
return fmt;
|
||||
}
|
||||
/**
|
||||
* 防抖原理:一定时间内,只有最后一次操作,再过wait毫秒后才执行函数
|
||||
*
|
||||
* @param {Function} func 要执行的回调函数
|
||||
* @param {Number} wait 延时的时间
|
||||
* @param {Boolean} immediate 是否立即执行
|
||||
* @return null
|
||||
*/
|
||||
let timeout = null;
|
||||
export function debounce(func, wait = 500, immediate = false) {
|
||||
// 清除定时器
|
||||
if (timeout !== null) clearTimeout(timeout);
|
||||
// 立即执行,此类情况一般用不到
|
||||
if (immediate) {
|
||||
var callNow = !timeout;
|
||||
timeout = setTimeout(function () {
|
||||
timeout = null;
|
||||
}, wait);
|
||||
if (callNow) typeof func === 'function' && func();
|
||||
} else {
|
||||
// 设置定时器,当最后一次操作后,timeout不会再被清除,所以在延时wait毫秒后执行func回调方法
|
||||
timeout = setTimeout(function () {
|
||||
typeof func === 'function' && func();
|
||||
}, wait);
|
||||
}
|
||||
}
|
||||
//1都不支持 2安卓指纹 3 苹果指纹 4 苹果人脸 5 苹果人脸加指纹
|
||||
export function biometrics() {
|
||||
return new Promise((resolve) => {
|
||||
//#ifdef APP-PLUS || MP-WEIXIN
|
||||
uni.checkIsSupportSoterAuthentication({
|
||||
success(res) {
|
||||
// console.log('检测支持的认证方式', res);
|
||||
if (res.errMsg === 'checkIsSupportSoterAuthentication:ok') {
|
||||
let support = 1;
|
||||
let supportMode = res.supportMode;
|
||||
let platform = uni.getSystemInfoSync().platform;
|
||||
// "facial" 人脸 "fingerPrint" 指纹识别
|
||||
console.log('supportMode', supportMode);
|
||||
// 如果都不支持 隐藏该选项
|
||||
if (supportMode.length === 0) {
|
||||
support = 1;
|
||||
}
|
||||
// 如果是安卓机 只让用指纹识别
|
||||
if (platform === 'android' && supportMode.findIndex(item => item === 'fingerPrint') !== -1) {
|
||||
support = 2;
|
||||
}
|
||||
// 如果是苹果机 看是否是支持人脸还是指纹
|
||||
if (platform === 'ios') {
|
||||
// 指纹
|
||||
if (supportMode.findIndex(item => item === 'fingerPrint') !== -1) {
|
||||
support = 3;
|
||||
}
|
||||
// 人脸
|
||||
if (supportMode.findIndex(item => item === 'facial') !== -1) {
|
||||
support = 4;
|
||||
}
|
||||
// 指纹人脸同时存在
|
||||
if (supportMode.findIndex(item => item === 'facial') !== -1 && supportMode.findIndex(item => item === 'fingerPrint') !== -1) {
|
||||
support = 5;
|
||||
}
|
||||
}
|
||||
resolve(support);
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
console.log(err);
|
||||
resolve(1);
|
||||
},
|
||||
})
|
||||
// #endif
|
||||
//#ifndef APP-PLUS || MP-WEIXIN
|
||||
return 1;
|
||||
// #endif
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
const router = new Router({ needLoginPages });
|
||||
/**
|
||||
* @description showModal 弹窗封装
|
||||
* @param {Object} options = 参数同 uni-app 官方用法
|
||||
* */
|
||||
export function showModal(options) {
|
||||
// #ifndef APP-PLUS
|
||||
uni.showModal(options);
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
if (uni.getSystemInfoSync().platform === 'android') {
|
||||
global.$showModal(options)
|
||||
.then(res => {
|
||||
console.log('RES', res);
|
||||
//确认
|
||||
}).catch(err => {
|
||||
//取消
|
||||
console.log('ERR', err);
|
||||
})
|
||||
} else {
|
||||
uni.showModal(options);
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
/**
|
||||
* @description 验证登录权限,接受一个回调函数,登录则执行回调函数,非登录状态则跳转登录页
|
||||
* @param {Function} cb = 回调函数
|
||||
* */
|
||||
export function actionAuth(cb) {
|
||||
if (global.token) {
|
||||
cb && cb();
|
||||
} else {
|
||||
navigateToLogin();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 判断是app端还是小程序端登录
|
||||
* */
|
||||
let timer = null; // 登录页跳转防抖
|
||||
export function navigateToLogin() {
|
||||
if (timer) clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
const pages = getCurrentPages();
|
||||
if (pages.length != 0) {
|
||||
const lastPage = '/' + pages.pop().route;
|
||||
let url = LOGIN_PAGE_URL;
|
||||
if (lastPage == url) return;
|
||||
uni.navigateTo({
|
||||
url
|
||||
});
|
||||
} else {
|
||||
uni.switchTab({
|
||||
url: '/pages/tab/home/shopindex'
|
||||
})
|
||||
}
|
||||
}, 200)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 倒计时计算
|
||||
* */
|
||||
export function downTime(time) {
|
||||
var days = parseInt(time / (1000 * 60 * 60 * 24));
|
||||
var hours = parseInt(time / (1000 * 60 * 60) % 24);
|
||||
var minutes = parseInt(time / (1000 * 60) % 60);
|
||||
var seconds = parseInt(time / 1000 % 60);
|
||||
return {
|
||||
days,
|
||||
hours: hours < 10 ? '0' + hours : hours,
|
||||
minutes: minutes < 10 ? '0' + minutes : minutes,
|
||||
seconds: seconds < 10 ? '0' + seconds : seconds,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 参数序列化
|
||||
* */
|
||||
export function serialize(data) {
|
||||
let str = '';
|
||||
Object.keys(data).forEach(key => {
|
||||
str += key + '=' + data[key] + '&'
|
||||
})
|
||||
str = str.substr(0, str.length - 1);
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 设置状态栏颜色
|
||||
* @param {String} color dark or light
|
||||
* @example this.$util.setNavigationBarColor('dark');
|
||||
* */
|
||||
export function setNavigationBarColor(color) {
|
||||
if (color == 'dark') {
|
||||
// #ifdef APP-PLUS
|
||||
plus.navigator.setStatusBarStyle('dark');
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN
|
||||
wx.setNavigationBarColor({
|
||||
frontColor: '#000000',
|
||||
backgroundColor: '#FFFFFF'
|
||||
})
|
||||
// #endif
|
||||
} else if (color == 'light') {
|
||||
// #ifdef APP-PLUS
|
||||
plus.navigator.setStatusBarStyle('light');
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN
|
||||
wx.setNavigationBarColor({
|
||||
frontColor: '#FFFFFF',
|
||||
backgroundColor: '#000000'
|
||||
})
|
||||
// #endif
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* base64图片缓存到本地,返回本地路径
|
||||
* */
|
||||
export function base64ToPath(base64) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (typeof window === 'object' && 'document' in window) {
|
||||
base64 = base64.split(',')
|
||||
var type = base64[0].match(/:(.*?);/)[1]
|
||||
var str = atob(base64[1])
|
||||
var n = str.length
|
||||
var array = new Uint8Array(n)
|
||||
while (n--) {
|
||||
array[n] = str.charCodeAt(n)
|
||||
}
|
||||
return resolve((window.URL || window.webkitURL).createObjectURL(new Blob([array], {
|
||||
type: type
|
||||
})))
|
||||
}
|
||||
var extName = base64.match(/data\:\S+\/(\S+);/)
|
||||
if (extName) {
|
||||
extName = extName[1]
|
||||
} else {
|
||||
reject(new Error('base64 error'))
|
||||
}
|
||||
var fileName = Date.now() + '.' + extName
|
||||
if (typeof plus === 'object') {
|
||||
var bitmap = new plus.nativeObj.Bitmap('bitmap' + Date.now())
|
||||
bitmap.loadBase64Data(base64, function () {
|
||||
var filePath = '_doc/uniapp_temp/' + fileName
|
||||
bitmap.save(filePath, {}, function () {
|
||||
bitmap.clear()
|
||||
resolve(filePath)
|
||||
}, function (error) {
|
||||
bitmap.clear()
|
||||
reject(error)
|
||||
})
|
||||
}, function (error) {
|
||||
bitmap.clear()
|
||||
reject(error)
|
||||
})
|
||||
return
|
||||
}
|
||||
if (typeof wx === 'object' && wx.canIUse('getFileSystemManager')) {
|
||||
var filePath = wx.env.USER_DATA_PATH + '/' + fileName
|
||||
wx.getFileSystemManager().writeFile({
|
||||
filePath: filePath,
|
||||
data: base64.replace(/^data:\S+\/\S+;base64,/, ''),
|
||||
encoding: 'base64',
|
||||
success: function () {
|
||||
resolve(filePath)
|
||||
},
|
||||
fail: function (error) {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
reject(new Error('not support'))
|
||||
})
|
||||
}
|
||||
|
||||
export function postMsgToParent(message) {
|
||||
console.log('postMsgToParent', message);
|
||||
window.parent.postMessage(message, '*');
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {*} type 点击类型 navigateTo
|
||||
* @param {*} data
|
||||
*/
|
||||
|
||||
export function handleAllFn(type, data) {
|
||||
// 无点击事件
|
||||
if (type == 'niente') {
|
||||
return false
|
||||
}
|
||||
/**
|
||||
* 转页面类型
|
||||
* navigateTo
|
||||
* data结构
|
||||
* {
|
||||
* url: String 路径,
|
||||
* auth: Boolean (选填)是否验证登录状态true 验证
|
||||
* params: Object (选填) 携带的参数
|
||||
* }
|
||||
*/
|
||||
if (type == 'navigate') {
|
||||
router[data.type]('/' + data.url)
|
||||
return false
|
||||
}
|
||||
/**
|
||||
*
|
||||
* type: back
|
||||
* 返回
|
||||
* data(选填) 不填返回一页
|
||||
*/
|
||||
if (type == 'back') {
|
||||
uni.navigateBack({
|
||||
delta: data.delta || 1
|
||||
});
|
||||
}
|
||||
/**
|
||||
*
|
||||
* type: backReference
|
||||
* 返回页面携带参数
|
||||
* data{
|
||||
* name:String 目标页面接受参数名
|
||||
* params: 参数
|
||||
* }
|
||||
*/
|
||||
if (type == "backReference") {
|
||||
if (!data.name) {
|
||||
return false
|
||||
}
|
||||
let pages = getCurrentPages(); //获取当前页面js里面的pages里的所有信息。
|
||||
let prevPage = pages[pages.length - 2];
|
||||
//prevPage 是获取上一个页面的js里面的pages的所有信息。 -2 是上一个页面,-3是上上个页面以此类推。
|
||||
prevPage.backWithParams({
|
||||
[data.name]: data.params
|
||||
})
|
||||
uni.navigateBack({
|
||||
delta: 1 // 返回上一级页面。
|
||||
})
|
||||
return false
|
||||
}
|
||||
/**
|
||||
* type showModal 弹窗封装
|
||||
* data 参数同 uni-app 官方用法
|
||||
* */
|
||||
if (type == 'showModal') {
|
||||
// #ifndef APP-PLUS
|
||||
uni.showModal(data);
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
if (uni.getSystemInfoSync().platform === 'android') {
|
||||
global.$showModal(options)
|
||||
.then(res => {
|
||||
console.log('RES', res);
|
||||
//确认
|
||||
}).catch(err => {
|
||||
//取消
|
||||
console.log('ERR', err);
|
||||
})
|
||||
} else {
|
||||
uni.showModal(data);
|
||||
}
|
||||
// #endif
|
||||
return false
|
||||
}
|
||||
// 打开指定弹窗
|
||||
if (type == 'showModalDiy') {
|
||||
let pages = getCurrentPages(); //获取当前页面js里面的pages里的所有信息。
|
||||
let prevPage = pages[pages.length - 1];
|
||||
prevPage['popupShow' + data.showCancel] = true
|
||||
return false
|
||||
}
|
||||
/**
|
||||
*
|
||||
* type: downloadFile
|
||||
* 下载文件
|
||||
* data 下载路径
|
||||
* .then(res=>{}) 接收下载成功回调
|
||||
* .catch(res=>{}) 接收下载失败回调
|
||||
*/
|
||||
if (type == 'downloadFile') {
|
||||
return new Promise((resolve, reject) => {
|
||||
const downloadTask = uni.downloadFile({
|
||||
url: data.url,
|
||||
success: (res) => {
|
||||
uni.showToast({
|
||||
title: '下载成功',
|
||||
icon: 'success',
|
||||
mask: true
|
||||
})
|
||||
// resolve(res)
|
||||
uni.saveImageToPhotosAlbum({
|
||||
filePath: res.tempFilePath,
|
||||
success: function () {
|
||||
console.log('save success');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
fail: (err) => {
|
||||
uni.showToast({
|
||||
title: '下载失败',
|
||||
icon: 'fail',
|
||||
mask: true
|
||||
})
|
||||
reject(err)
|
||||
},
|
||||
complete: () => { }
|
||||
})
|
||||
// 中断下载
|
||||
// downloadTask.abort();
|
||||
// 监听下载进度
|
||||
// downloadTask.onProgressUpdate(res => {
|
||||
// console.log('下载进度' + res.progress);
|
||||
// console.log('已经下载的数据长度' + res.totalBytesWritten);
|
||||
// console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
|
||||
// })
|
||||
})
|
||||
}
|
||||
/**
|
||||
*
|
||||
* type: uploadFile
|
||||
* 上传文件
|
||||
* data{
|
||||
* url:String 上传路径
|
||||
* files: 仅app与h5支持该选项
|
||||
* ffileType: 仅支付宝小程序支持且必填 images/video/audio
|
||||
* filePath: 文件路径
|
||||
* name: 后台接收key
|
||||
* header: 选填
|
||||
* formData: 选填 携带参数
|
||||
* progressCallback: 选填 监听上传载进度
|
||||
* }
|
||||
*/
|
||||
|
||||
if (type == 'uploadFile') {
|
||||
return new Promise((resolve, reject) => {
|
||||
const uploadTask = uni.uploadFile({
|
||||
url: config.baseUrl + data.url,
|
||||
// #ifdef APP-PLUS || H5
|
||||
files: data.files || [],
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
fileType: data.fileType,
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
file: data.file || null,
|
||||
// #endif
|
||||
filePath: data.filePath,
|
||||
name: data.name,
|
||||
header: data.header ? data.header : {},
|
||||
formData: data.formData ? data.formData : {},
|
||||
complete: (response) => {
|
||||
if (response.statusCode == 200) {
|
||||
resolve(response)
|
||||
} else {
|
||||
reject(response)
|
||||
}
|
||||
}
|
||||
})
|
||||
if (data.progressCallback && typeof (data.progressCallback) == 'function') {
|
||||
uploadTask.onProgressUpdate(res => {
|
||||
data.progressCallback(res.progress + '%');
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* type: getLoaction
|
||||
* 获取定位
|
||||
*
|
||||
**/
|
||||
if (type == 'getLoaction') {
|
||||
console.log('我要获取定位');
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.getLocation({
|
||||
type: 'wgs84',
|
||||
success: function (res) {
|
||||
console.log('当前位置的经度:' + res.longitude);
|
||||
console.log('当前位置的纬度:' + res.latitude);
|
||||
uni.showToast({
|
||||
title: JSON.stringify(res),
|
||||
icon: "none"
|
||||
})
|
||||
resolve(res)
|
||||
},
|
||||
fail: function (err) {
|
||||
reject(err)
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
/**
|
||||
*
|
||||
* type: richiesta
|
||||
* 点赞 收藏
|
||||
* data{
|
||||
* url:String 上传路径
|
||||
* files: 仅app与h5支持该选项
|
||||
* ffileType: 仅支付宝小程序支持且必填 images/video/audio
|
||||
* filePath: 文件路径
|
||||
* name: 后台接收key
|
||||
* header: 选填
|
||||
* formData: 选填 携带参数
|
||||
* progressCallback: 选填 监听上传载进度
|
||||
* }
|
||||
*/
|
||||
if (type == 'richiesta') {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
109
common/utils/validate.js
Normal file
109
common/utils/validate.js
Normal file
@ -0,0 +1,109 @@
|
||||
const validate = (value, vtype,lgh) => {
|
||||
// 自定义正则校验
|
||||
if ('regular' === vtype) {
|
||||
return lgh.test(value);
|
||||
}
|
||||
//长度校验
|
||||
if(vtype === 'length'){
|
||||
let val = lgh.split(',')
|
||||
let len = value.length
|
||||
if (val.length == 1){
|
||||
return val == len
|
||||
} else {
|
||||
return len >= val[0] && len <= val[1]
|
||||
}
|
||||
}
|
||||
if ('require' === vtype) {
|
||||
return !!value;
|
||||
}
|
||||
if ('phone' === vtype) {
|
||||
return /^1[3-9]\d{9}$/.test(value);
|
||||
}
|
||||
// 验证码
|
||||
if ('captcha' === vtype) {
|
||||
return /^[0-9]{4,6}$/.test(value);
|
||||
}
|
||||
// 不知道干啥的
|
||||
if ('isnumber' === vtype) {
|
||||
return /^[0-9]{5,11}$/.test(value);
|
||||
}
|
||||
if ('isqq' === vtype) {
|
||||
return /^[1-9][0-9]{4,10}$/.test(value);
|
||||
}
|
||||
// 身份证号码验证不准确
|
||||
if ('idcard' === vtype) {
|
||||
return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(value);
|
||||
}
|
||||
if ('password' === vtype) {
|
||||
return /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9a-zA-Z]{6,12}$/.test(value);
|
||||
}
|
||||
// 邀请码验证
|
||||
if ('invitecode' === vtype) {
|
||||
return /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9a-zA-Z]$/.test(value);
|
||||
}
|
||||
// 判断不准确 比如123.
|
||||
if ('ismoney' === vtype) {
|
||||
return /^(([1-9]\d*)|\d)(\.\d{1,2})?$/.test(value);
|
||||
}
|
||||
if ('email' === vtype) {
|
||||
// return /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(value);
|
||||
return /^[0-9a-zA-Z_.-]+[@][0-9a-zA-Z_.-]+([.][a-zA-Z]+){1,2}$/.test(value);
|
||||
}
|
||||
if ('url' === vtype) {
|
||||
return /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(value);
|
||||
}
|
||||
if ('paragraph' === vtype) {
|
||||
return /^[A-Z0-9]{18}$/.test(value);
|
||||
}
|
||||
// 银行卡验证
|
||||
if ('card' === vtype) {
|
||||
let bankno = value;
|
||||
let lastNum = bankno.substr(bankno.length - 1, 1); //取出最后一位(与luhm进行比较)
|
||||
let first15Num = bankno.substr(0, bankno.length - 1); //前15或18位
|
||||
let newArr = [];
|
||||
|
||||
// 前15或18位倒序存进数组
|
||||
for (let i = first15Num.length - 1; i > -1; i--) newArr.push(first15Num.substr(i, 1));
|
||||
|
||||
let arrJiShu = []; // 奇数位*2的积 <9
|
||||
let arrJiShu2 = []; // 奇数位*2的积 >9
|
||||
let arrOuShu = []; // 偶数位数组
|
||||
for (let j = 0; j < newArr.length; j++) {
|
||||
if ((j + 1) % 2 == 1) { //奇数位
|
||||
if (parseInt(newArr[j]) * 2 < 9) arrJiShu.push(parseInt(newArr[j]) * 2);
|
||||
else arrJiShu2.push(parseInt(newArr[j]) * 2);
|
||||
} else arrOuShu.push(newArr[j]); // 偶数位
|
||||
}
|
||||
|
||||
let jishu_child1 = []; //奇数位*2 >9 的分割之后的数组个位数
|
||||
let jishu_child2 = []; //奇数位*2 >9 的分割之后的数组十位数
|
||||
for (let h = 0; h < arrJiShu2.length; h++) {
|
||||
jishu_child1.push(parseInt(arrJiShu2[h]) % 10);
|
||||
jishu_child2.push(parseInt(arrJiShu2[h]) / 10);
|
||||
}
|
||||
|
||||
let sumJiShu = 0; //奇数位*2 < 9 的数组之和
|
||||
let sumOuShu = 0; //偶数位数组之和
|
||||
let sumJiShuChild1 = 0; //奇数位*2 >9 的分割之后的数组个位数之和
|
||||
let sumJiShuChild2 = 0; //奇数位*2 >9 的分割之后的数组十位数之和
|
||||
let sumTotal = 0;
|
||||
|
||||
for (let m = 0; m < arrJiShu.length; m++) sumJiShu = sumJiShu + parseInt(arrJiShu[m]);
|
||||
for (let n = 0; n < arrOuShu.length; n++) sumOuShu = sumOuShu + parseInt(arrOuShu[n]);
|
||||
|
||||
for (let p = 0; p < jishu_child1.length; p++) {
|
||||
sumJiShuChild1 = sumJiShuChild1 + parseInt(jishu_child1[p]);
|
||||
sumJiShuChild2 = sumJiShuChild2 + parseInt(jishu_child2[p]);
|
||||
}
|
||||
//计算总和
|
||||
sumTotal = parseInt(sumJiShu) + parseInt(sumOuShu) + parseInt(sumJiShuChild1) + parseInt(sumJiShuChild2);
|
||||
//计算Luhm值
|
||||
let k = parseInt(sumTotal) % 10 == 0 ? 10 : parseInt(sumTotal) % 10;
|
||||
let luhm = 10 - k;
|
||||
return lastNum == luhm;
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
validate
|
||||
};
|
||||
Reference in New Issue
Block a user