初始化代码
This commit is contained in:
1
uniapp/uni-app/utils/bmap-wx.min.js
vendored
Normal file
1
uniapp/uni-app/utils/bmap-wx.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";function _classCallCheck(t,a){if(!(t instanceof a))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function t(t,a){for(var e=0;e<a.length;e++){var i=a[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(a,e,i){return e&&t(a.prototype,e),i&&t(a,i),a}}(),BMapWX=function(){function t(a){_classCallCheck(this,t),this.ak=a.ak}return _createClass(t,[{key:"getWXLocation",value:function(t,a,e,i){t=t||"gcj02",a=a||function(){},e=e||function(){},i=i||function(){},wx.getLocation({type:t,success:a,fail:e,complete:i})}},{key:"search",value:function(t){var a=this;t=t||{};var e={query:t.query||"生活服务$美食&酒店",scope:t.scope||1,filter:t.filter||"",coord_type:t.coord_type||2,page_size:t.page_size||10,page_num:t.page_num||0,output:t.output||"json",ak:a.ak,sn:t.sn||"",timestamp:t.timestamp||"",radius:t.radius||2e3,ret_coordtype:"gcj02ll"},i={iconPath:t.iconPath,iconTapPath:t.iconTapPath,width:t.width,height:t.height,alpha:t.alpha||1,success:t.success||function(){},fail:t.fail||function(){}},n="gcj02",o=function(t){e.location=t.latitude+","+t.longitude,wx.request({url:"https://api.map.baidu.com/place/v2/search",data:e,header:{"content-type":"application/json"},method:"GET",success:function(t){var a=t.data;if(0===a.status){var e=a.results,n={};n.originalData=a,n.wxMarkerData=[];for(var o=0;o<e.length;o++)n.wxMarkerData[o]={id:o,latitude:e[o].location.lat,longitude:e[o].location.lng,title:e[o].name,iconPath:i.iconPath,iconTapPath:i.iconTapPath,address:e[o].address,telephone:e[o].telephone,alpha:i.alpha,width:i.width,height:i.height};i.success(n)}else i.fail({errMsg:a.message,statusCode:a.status})},fail:function(t){i.fail(t)}})},s=function(t){i.fail(t)},c=function(){};if(t.location){var u=t.location.split(",")[1],r=t.location.split(",")[0],l="input location",p={errMsg:l,latitude:r,longitude:u};o(p)}else a.getWXLocation(n,o,s,c)}},{key:"suggestion",value:function(t){var a=this;t=t||{};var e={query:t.query||"",region:t.region||"全国",city_limit:t.city_limit||!1,output:t.output||"json",ak:a.ak,sn:t.sn||"",timestamp:t.timestamp||"",ret_coordtype:"gcj02ll"},i={success:t.success||function(){},fail:t.fail||function(){}};wx.request({url:"https://api.map.baidu.com/place/v2/suggestion",data:e,header:{"content-type":"application/json"},method:"GET",success:function(t){var a=t.data;0===a.status?i.success(a):i.fail({errMsg:a.message,statusCode:a.status})},fail:function(t){i.fail(t)}})}},{key:"regeocoding",value:function(t){var a=this;t=t||{};var e={coordtype:t.coordtype||"gcj02ll",pois:t.pois||0,output:t.output||"json",ak:a.ak,sn:t.sn||"",timestamp:t.timestamp||"",ret_coordtype:"gcj02ll"},i={iconPath:t.iconPath,iconTapPath:t.iconTapPath,width:t.width,height:t.height,alpha:t.alpha||1,success:t.success||function(){},fail:t.fail||function(){}},n="gcj02",o=function(t){e.location=t.latitude+","+t.longitude,wx.request({url:"https://api.map.baidu.com/geocoder/v2/",data:e,header:{"content-type":"application/json"},method:"GET",success:function(a){var e=a.data;if(0===e.status){var n=e.result,o={};o.originalData=e,o.wxMarkerData=[],o.wxMarkerData[0]={id:0,latitude:t.latitude,longitude:t.longitude,address:n.formatted_address,iconPath:i.iconPath,iconTapPath:i.iconTapPath,desc:n.sematic_description,business:n.business,alpha:i.alpha,width:i.width,height:i.height},i.success(o)}else i.fail({errMsg:e.message,statusCode:e.status})},fail:function(t){i.fail(t)}})},s=function(t){i.fail(t)},c=function(){};if(t.location){var u=t.location.split(",")[1],r=t.location.split(",")[0],l="input location",p={errMsg:l,latitude:r,longitude:u};o(p)}else a.getWXLocation(n,o,s,c)}},{key:"weather",value:function(t){var a=this;t=t||{};var e={coord_type:t.coord_type||"gcj02",output:t.output||"json",ak:a.ak,sn:t.sn||"",timestamp:t.timestamp||""},i={success:t.success||function(){},fail:t.fail||function(){}},n="gcj02",o=function(t){e.location=t.longitude+","+t.latitude,wx.request({url:"https://api.map.baidu.com/telematics/v3/weather",data:e,header:{"content-type":"application/json"},method:"GET",success:function(t){var a=t.data;if(0===a.error&&"success"===a.status){var e=a.results,n={};n.originalData=a,n.currentWeather=[],n.currentWeather[0]={currentCity:e[0].currentCity,pm25:e[0].pm25,date:e[0].weather_data[0].date,temperature:e[0].weather_data[0].temperature,weatherDesc:e[0].weather_data[0].weather,wind:e[0].weather_data[0].wind},i.success(n)}else i.fail({errMsg:a.message,statusCode:a.status})},fail:function(t){i.fail(t)}})},s=function(t){i.fail(t)},c=function(){};if(t.location){var u=t.location.split(",")[0],r=t.location.split(",")[1],l="input location",p={errMsg:l,latitude:r,longitude:u};o(p)}else a.getWXLocation(n,o,s,c)}}]),t}();module.exports.BMapWX=BMapWX;
|
||||
85
uniapp/uni-app/utils/error.js
Normal file
85
uniapp/uni-app/utils/error.js
Normal file
@@ -0,0 +1,85 @@
|
||||
//网络错误
|
||||
import $store from "@/store/index.js"
|
||||
const networkError = function({
|
||||
code = 0,
|
||||
msg = '网络异常'
|
||||
} = {}) {
|
||||
if (code !== 0) return;
|
||||
uni.showToast({
|
||||
title: msg,
|
||||
icon: 'none',
|
||||
duration: 4000
|
||||
})
|
||||
}
|
||||
//服务器错误处理
|
||||
const serverError = function({
|
||||
code = -1,
|
||||
msg = '服务器错误'
|
||||
} = {}) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: msg,
|
||||
showCancel: false
|
||||
})
|
||||
}
|
||||
//错误信息
|
||||
const msgError = function({
|
||||
msg = '错误'
|
||||
} = {}) {
|
||||
uni.showToast({
|
||||
title: msg,
|
||||
icon: 'none',
|
||||
duration: 4000
|
||||
})
|
||||
}
|
||||
// 没有购买权限
|
||||
const authError = async function({
|
||||
msg = '没有购买权限,请前去认证',
|
||||
showCancel = true,
|
||||
} = {}) {
|
||||
let [, {
|
||||
confirm
|
||||
}] = await uni.showModal({
|
||||
title: '温馨提示',
|
||||
content: msg,
|
||||
confirmText: '前往认证',
|
||||
cancelText: '暂不认证',
|
||||
showCancel,
|
||||
})
|
||||
if (!confirm) return;
|
||||
let {
|
||||
driver_status
|
||||
} = $store.state.user.userInfo
|
||||
let page = driver_status == -1 ? `apply` : `apply-result`
|
||||
let url = `/mine/pages/${page}`
|
||||
uni.navigateTo({
|
||||
url
|
||||
})
|
||||
}
|
||||
// 没有购买权限
|
||||
const vipError = async function({
|
||||
msg = '只有对应身份的用户才能领取,请前去升级',
|
||||
showCancel = true,
|
||||
} = {}) {
|
||||
let [, {
|
||||
confirm
|
||||
}] = await uni.showModal({
|
||||
title: '温馨提示',
|
||||
content: msg,
|
||||
confirmText: '前往升级',
|
||||
cancelText: '暂不升级',
|
||||
showCancel,
|
||||
})
|
||||
if (!confirm) return;
|
||||
let url = `/mine/pages/stored/list`
|
||||
uni.navigateTo({
|
||||
url
|
||||
})
|
||||
}
|
||||
export {
|
||||
networkError,
|
||||
serverError,
|
||||
msgError,
|
||||
authError,
|
||||
vipError
|
||||
}
|
||||
1187
uniapp/uni-app/utils/ezuikit.js
Normal file
1187
uniapp/uni-app/utils/ezuikit.js
Normal file
File diff suppressed because it is too large
Load Diff
816
uniapp/uni-app/utils/index.js
Normal file
816
uniapp/uni-app/utils/index.js
Normal file
@@ -0,0 +1,816 @@
|
||||
import Validate from './validate.js';
|
||||
import $store from "@/store/index.js"
|
||||
export default {
|
||||
Validate,
|
||||
log: console.log,
|
||||
// log: () => {},
|
||||
//格式化时间
|
||||
formatTime(date, format) {
|
||||
let newFormat = format || 'YY-M-D h:m:s';
|
||||
let formatNumber = this.formatNumber;
|
||||
let newDate = date || new Date();
|
||||
if (Object.prototype.toString.call(newDate).slice(8, -1) !== "Date") {
|
||||
newDate = new Date(date);
|
||||
}
|
||||
let week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', '日', '一', '二', '三',
|
||||
'四',
|
||||
'五', '六'
|
||||
];
|
||||
return newFormat.replace(/YY|Y|M|D|h|m|s|week|星期|周/g, function(a) {
|
||||
switch (a) {
|
||||
case 'YY':
|
||||
return newDate.getFullYear();
|
||||
case 'Y':
|
||||
return (newDate.getFullYear() + '').slice(2);
|
||||
case 'M':
|
||||
return formatNumber(newDate.getMonth() + 1);
|
||||
case 'D':
|
||||
return formatNumber(newDate.getDate());
|
||||
case 'h':
|
||||
return formatNumber(newDate.getHours());
|
||||
case 'm':
|
||||
return formatNumber(newDate.getMinutes());
|
||||
case 's':
|
||||
return formatNumber(newDate.getSeconds());
|
||||
case '星期':
|
||||
return "星期" + week[newDate.getDay() + 7];
|
||||
case '周':
|
||||
return "周" + week[newDate.getDay() + 7];
|
||||
case 'week':
|
||||
return week[newDate.getDay()];
|
||||
}
|
||||
})
|
||||
},
|
||||
// 日期转时间戳
|
||||
DateToUnix: function(string) {
|
||||
var f = string.split(' ', 2);
|
||||
var d = (f[0] ? f[0] : '').split('-', 3);
|
||||
var t = (f[1] ? f[1] : '').split(':', 3);
|
||||
return (new Date(
|
||||
parseInt(d[0], 10) || null,
|
||||
(parseInt(d[1], 10) || 1) - 1,
|
||||
parseInt(d[2], 10) || null,
|
||||
parseInt(t[0], 10) || null,
|
||||
parseInt(t[1], 10) || null,
|
||||
parseInt(t[2], 10) || null
|
||||
)).getTime() / 1000;
|
||||
},
|
||||
//格式化数字
|
||||
formatNumber(n) {
|
||||
n = n.toString();
|
||||
return n[1] ? n : '0' + n
|
||||
},
|
||||
// 保留小数 (不四舍五入)
|
||||
formatDecimal(num, decimal) {
|
||||
num = num.toString()
|
||||
let index = num.indexOf('.')
|
||||
if (index !== -1) {
|
||||
num = num.substring(0, decimal + index + 1)
|
||||
} else {
|
||||
num = num.substring(0)
|
||||
}
|
||||
return parseFloat(num).toFixed(decimal) * 1
|
||||
},
|
||||
// 实时检测输入金额
|
||||
formatMoney(val) {
|
||||
if (val.slice(0, 1) == "0" && val.slice(1, 2) > 0) {
|
||||
val = val.slice(1, 2);
|
||||
}
|
||||
if (val.slice(0, 1) == ".") {
|
||||
val = '0.';
|
||||
}
|
||||
if (val == "0.00") {
|
||||
val = '0.0';
|
||||
}
|
||||
return val.replace(/[^\d\.]|^\./g, '').replace(/\.{2}/g, '.').replace(
|
||||
/^([1-9]\d*|0)(\.\d{1,2})(\.|\d{1})?$/, '$1$2').replace(/^0\d{1}/g, '0')
|
||||
},
|
||||
toWeiXinString(date) {
|
||||
let str;
|
||||
let newDate = date || new Date();
|
||||
if (Object.prototype.toString.call(newDate).slice(8, -1) !== "Date") {
|
||||
newDate = new Date(date);
|
||||
}
|
||||
const now = newDate;
|
||||
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
||||
const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
|
||||
const beforeYesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 2);
|
||||
const monday = new Date(today);
|
||||
monday.setDate(today.getDate() - (today.getDay() ? today.getDay() - 1 : 6));
|
||||
//注意:date初始化默认是按本地时间初始的,但打印默认却是按GMT时间打印的,也就是说打印出的不是本地现在的时间
|
||||
//LocaleString的打印也有点问题,"0点"会被打印为"上午12点"
|
||||
if (now.getTime() > today.getTime()) {
|
||||
str = "";
|
||||
} else if (now.getTime() > yesterday.getTime()) {
|
||||
str = "昨天";
|
||||
} else if (now.getTime() > beforeYesterday.getTime()) {
|
||||
str = "前天";
|
||||
} else if (now.getTime() > monday.getTime()) {
|
||||
const week = {
|
||||
"0": "周日",
|
||||
"1": "周一",
|
||||
"2": "周二",
|
||||
"3": "周三",
|
||||
"4": "周四",
|
||||
"5": "周五",
|
||||
"6": "周六"
|
||||
};
|
||||
str = week[now.getDay() + ""];
|
||||
} else {
|
||||
const hour = ["凌晨", "早上", "下午", "晚上"];
|
||||
const h = now.getHours();
|
||||
if (h == 12) str = "中午";
|
||||
else str = hour[parseInt(h / 6)];
|
||||
str = now.format("MM月dd ") + str;
|
||||
}
|
||||
str += now.format("HH:ss");
|
||||
return str;
|
||||
},
|
||||
//返回类型
|
||||
typeOf(param) {
|
||||
return Object.prototype.toString.call(param).slice(8, -1)
|
||||
},
|
||||
//判断是否为空
|
||||
isEmpty(param) {
|
||||
//基本类型为空
|
||||
let condition1 = param === '' || param === null || param === undefined || param === "NaN";
|
||||
let condition2;
|
||||
let condition3
|
||||
//引用类型为空
|
||||
if (!condition1) {
|
||||
condition2 = this.typeOf(param) === "Object" && Object.keys(param).length < 1;
|
||||
condition3 = this.typeOf(param) === "Array" && param.length < 1;
|
||||
}
|
||||
return condition1 || condition2 || condition3;
|
||||
},
|
||||
showLoading({
|
||||
title = "加载中",
|
||||
mask = true
|
||||
} = {}) {
|
||||
uni.showLoading({
|
||||
title,
|
||||
mask
|
||||
});
|
||||
},
|
||||
showToast({
|
||||
title,
|
||||
icon = "none"
|
||||
} = {}) {
|
||||
uni.showToast({
|
||||
title,
|
||||
icon,
|
||||
duration: 2000
|
||||
});
|
||||
},
|
||||
hideAll() {
|
||||
uni.hideLoading();
|
||||
uni.stopPullDownRefresh();
|
||||
uni.hideNavigationBarLoading();
|
||||
},
|
||||
showModal({
|
||||
title = "提示",
|
||||
content = "没有返回值,检查服务器是否正常"
|
||||
}) {
|
||||
uni.showModal({
|
||||
title,
|
||||
content,
|
||||
showCancel: false
|
||||
});
|
||||
},
|
||||
setNavigationBarColor({
|
||||
color = '#ffffff',
|
||||
bg
|
||||
}) {
|
||||
uni.setNavigationBarColor({
|
||||
frontColor: color,
|
||||
backgroundColor: bg,
|
||||
animation: {
|
||||
duration: 400,
|
||||
timingFunc: 'easeIn'
|
||||
}
|
||||
})
|
||||
},
|
||||
getQueryString(name) {
|
||||
let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
|
||||
let r = window.location.search.substr(1).match(reg);
|
||||
if (r !== null) return unescape(r[2]);
|
||||
return null;
|
||||
},
|
||||
getHostname(url) {
|
||||
var reg = /^http(s)?:\/\/(.*?)\//
|
||||
// 必须是http开头或者https开头,结尾为'/'
|
||||
var ToReplace = 'Host/'
|
||||
url.replace(reg, ToReplace)
|
||||
url = reg.exec(url)[2];
|
||||
return url;
|
||||
},
|
||||
//获取标签上data
|
||||
getDataSet(e) {
|
||||
return e.currentTarget.dataset
|
||||
},
|
||||
//获表单控件值
|
||||
getValue(e) {
|
||||
return e.detail.value
|
||||
},
|
||||
async getNavBarHeight() {
|
||||
var {
|
||||
statusBarHeight,
|
||||
navigationBarHeight
|
||||
} = await uni.getSystemInfoSync()
|
||||
|
||||
let navBarHeight = statusBarHeight * 1 + 44
|
||||
// #ifdef MP-BAIDU
|
||||
navBarHeight = statusBarHeight * 1 + navigationBarHeight * 1
|
||||
// #endif
|
||||
return navBarHeight
|
||||
},
|
||||
pick(obj, arr) {
|
||||
return arr.reduce((acc, curr) => (curr in obj && (acc[curr] = obj[curr]), acc), {});
|
||||
},
|
||||
toCheckLogin(param) {
|
||||
let {
|
||||
loginType,
|
||||
userInfo
|
||||
} = $store.state.user
|
||||
let {
|
||||
phone = ''
|
||||
} = userInfo
|
||||
console.log(phone, $store.state.user.userInfo)
|
||||
if (loginType === 'weixin' && phone) {
|
||||
param.url = `/pages/login?type=1`
|
||||
delete param.openType
|
||||
let pages = getCurrentPages();
|
||||
let {
|
||||
route
|
||||
} = pages[pages.length - 1]
|
||||
$store.commit('updateUserItem', {
|
||||
key: 'loginPage',
|
||||
val: `/${route}`
|
||||
})
|
||||
}
|
||||
this.goUrl(param)
|
||||
},
|
||||
goUrl({
|
||||
url = "",
|
||||
openType = "navigateTo",
|
||||
path = "",
|
||||
query = ""
|
||||
} = {}) {
|
||||
let that = this;
|
||||
if (!url) return;
|
||||
if (this.typeOf(query) == 'Object') {
|
||||
let queryStr = Object.keys(query).map(k => `${k}=${query[k]}`).join('&');
|
||||
url = `${url}&${queryStr}`
|
||||
}
|
||||
let list = ["navigateTo", "redirectTo", "switchTab", "reLaunch"];
|
||||
if (list.includes(openType)) {
|
||||
if (openType == 'navigateTo' && getCurrentPages().length > 9) {
|
||||
uni.redirectTo({
|
||||
url
|
||||
})
|
||||
} else {
|
||||
uni[openType]({
|
||||
url
|
||||
})
|
||||
}
|
||||
}
|
||||
//返回
|
||||
openType == "navigateBack" && uni.navigateBack({
|
||||
delta: url
|
||||
})
|
||||
//跳转小程序
|
||||
openType == "miniProgram" && uni.navigateToMiniProgram({
|
||||
appId: url,
|
||||
path
|
||||
})
|
||||
//打电话
|
||||
openType == "call" && uni.makePhoneCall({
|
||||
phoneNumber: url
|
||||
})
|
||||
// 复制文本
|
||||
openType == 'copy' && uni.setClipboardData({
|
||||
data: url,
|
||||
success: function(res) {
|
||||
uni.getClipboardData({
|
||||
success: function(res) {
|
||||
// #ifdef MP-BAIDU
|
||||
that.showToast({
|
||||
title: '复制成功'
|
||||
})
|
||||
// #endif
|
||||
console.log('复制文本成功 ==>', res.data);
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
//跳转网页/播放视频
|
||||
if (openType == "web" || openType == "video") {
|
||||
let encode_url = encodeURIComponent(url)
|
||||
uni.navigateTo({
|
||||
url: `/mine/pages/common/${openType}?url=${encode_url}`
|
||||
})
|
||||
}
|
||||
},
|
||||
// 刷新上页数据
|
||||
back() {
|
||||
let pages = getCurrentPages(); //当前页面栈
|
||||
if (pages.length > 1) {
|
||||
var beforePage = pages[pages.length - 2]; //获取上一个页面实例对象
|
||||
//触发父页面中的方法change()
|
||||
beforePage.$vm.initRefresh()
|
||||
}
|
||||
},
|
||||
//获取页面对象,0时为当前页面
|
||||
getPage(index = 0) {
|
||||
let pages = getCurrentPages();
|
||||
let page = pages[pages.length - 1 + index]
|
||||
return page.$vm
|
||||
},
|
||||
// 预览图片
|
||||
previewImage(param) {
|
||||
let {
|
||||
current,
|
||||
urls
|
||||
} = param;
|
||||
uni.previewImage({
|
||||
current,
|
||||
urls,
|
||||
})
|
||||
},
|
||||
// 根据type获取数据字符串
|
||||
getItems(o, type = 'id', sign = ',') {
|
||||
let items = [];
|
||||
o = o || [];
|
||||
o.forEach((item) => {
|
||||
items.push(item[type])
|
||||
})
|
||||
return items.join(sign);
|
||||
},
|
||||
// 检查授权
|
||||
async checkAuth({
|
||||
type = "userLocation",
|
||||
tip = ""
|
||||
} = {}) {
|
||||
// #ifdef MP-WEIXIN
|
||||
let contentList = {
|
||||
phone: "授权获取手机号",
|
||||
userLocation: "你的地理位置",
|
||||
address: "你的通讯地址",
|
||||
invoiceTitle: "发票抬头",
|
||||
invoice: "获取发票",
|
||||
werun: "微信运动步数",
|
||||
record: "你的录音功能",
|
||||
writePhotosAlbum: "你的保存到相册功能",
|
||||
camera: "摄像头"
|
||||
}
|
||||
tip = tip || `您暂未开启${contentList[type]}的授权,是否开启?`
|
||||
// 声明
|
||||
let err, result;
|
||||
[err, result] = await uni.getSetting();
|
||||
//获取配置失败
|
||||
if (err) {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
//如果已授权
|
||||
if (result.authSetting[`scope.${type}`]) {
|
||||
return true
|
||||
}
|
||||
// 调用获取权限
|
||||
[err, result] = await uni.authorize({
|
||||
scope: `scope.${type}`
|
||||
})
|
||||
//获取成功
|
||||
if (!err) {
|
||||
return true
|
||||
}
|
||||
uni.hideLoading()
|
||||
//提示去设置
|
||||
return new Promise((resove, reject) => {
|
||||
uni.showModal({
|
||||
content: tip,
|
||||
success(res) {
|
||||
if (res.confirm) {
|
||||
uni.openSetting({
|
||||
success(result) {
|
||||
if (result.authSetting[`scope.${type}`]) {
|
||||
resove(true)
|
||||
} else {
|
||||
reject()
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
reject()
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
// #endif
|
||||
|
||||
// #ifdef H5
|
||||
// H5环境下直接返回true,因为H5环境不需要小程序授权
|
||||
// 特殊处理地理位置权限
|
||||
if (type === 'userLocation') {
|
||||
// 检查是否已经缓存了位置信息
|
||||
let cachedLocation = uni.getStorageSync('cached_location');
|
||||
let cacheTime = uni.getStorageSync('location_cache_time');
|
||||
let now = new Date().getTime();
|
||||
|
||||
// 如果有缓存且缓存时间不超过30分钟,直接返回true
|
||||
if (cachedLocation && cacheTime && (now - cacheTime) < 30 * 60 * 1000) {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
// 检查浏览器是否支持地理位置API
|
||||
if (!navigator.geolocation) {
|
||||
this.showToast({
|
||||
title: '您的浏览器不支持地理位置功能'
|
||||
});
|
||||
reject(new Error('Geolocation not supported'));
|
||||
return;
|
||||
}
|
||||
|
||||
// 尝试获取当前位置
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
() => resolve(true),
|
||||
(error) => {
|
||||
// 只在用户明确需要位置信息时才提示错误
|
||||
console.log('获取位置失败:', error);
|
||||
// 不再强制弹出提示,让用户自行决定是否需要位置信息
|
||||
reject(error);
|
||||
},
|
||||
{
|
||||
timeout: 5000, // 5秒超时
|
||||
maximumAge: 30 * 60 * 1000 // 30分钟的缓存
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// 其他类型的权限在H5环境下直接返回true
|
||||
return Promise.resolve(true);
|
||||
// #endif
|
||||
},
|
||||
//深拷贝
|
||||
deepCopy(o) {
|
||||
let that = this;
|
||||
if (o instanceof Array) {
|
||||
var n = [];
|
||||
for (var i = 0; i < o.length; ++i) {
|
||||
n[i] = that.deepCopy(o[i]);
|
||||
}
|
||||
return n;
|
||||
} else if (o instanceof Function) {
|
||||
var n = new Function("return " + o.toString())();
|
||||
return n
|
||||
} else if (o instanceof Object) {
|
||||
var n = {}
|
||||
for (var i in o) {
|
||||
n[i] = that.deepCopy(o[i]);
|
||||
}
|
||||
return n;
|
||||
} else {
|
||||
return o;
|
||||
}
|
||||
},
|
||||
getOptions(options, comminOptions = {}) {
|
||||
return Object.assign({}, comminOptions, this.formatOptions(options))
|
||||
},
|
||||
//获取用户端公共参数
|
||||
getCommonOptions(options) {
|
||||
return this.pick(options, ["staff_id"])
|
||||
},
|
||||
// 微信支付
|
||||
async pay(pay_list) {
|
||||
let that = this;
|
||||
|
||||
console.log("=====pay_list==========>>>>", pay_list)
|
||||
|
||||
// #ifdef H5
|
||||
if (typeof WeixinJSBridge != "undefined") {
|
||||
return new Promise((resove, reject) => {
|
||||
WeixinJSBridge.invoke(
|
||||
'getBrandWCPayRequest', {
|
||||
"appId": pay_list.appId, //公众号ID,由商户传入
|
||||
"timeStamp": pay_list.timeStamp, //时间戳,自1970年以来的秒数
|
||||
"nonceStr": pay_list.nonceStr, //随机串
|
||||
"package": pay_list.package,
|
||||
"signType": pay_list.signType, //微信签名方式:
|
||||
"paySign": pay_list.paySign //微信签名
|
||||
},
|
||||
function(res) {
|
||||
if (res.err_msg == "get_brand_wcpay_request:ok") {
|
||||
setTimeout(() => {
|
||||
resove(true)
|
||||
}, 1000)
|
||||
} else {
|
||||
that.showToast({
|
||||
title: `支付失败`
|
||||
})
|
||||
setTimeout(() => {
|
||||
reject("支付失败")
|
||||
}, 1000)
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
// #endif
|
||||
|
||||
|
||||
let {
|
||||
provider = 'wxpay',
|
||||
orderInfo = ''
|
||||
} = pay_list
|
||||
|
||||
let param = {}
|
||||
// #ifdef MP-WEIXIN
|
||||
param = that.pick(pay_list, ['nonceStr', 'package', 'signType', 'paySign', 'timeStamp'])
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
if (provider == 'wxpay') {
|
||||
orderInfo = that.pick(pay_list, ['appid', 'noncestr', 'package', 'partnerid', 'prepayid', 'timestamp'])
|
||||
orderInfo.sign = pay_list.paySign
|
||||
orderInfo = JSON.stringify(orderInfo)
|
||||
}
|
||||
param = {
|
||||
provider,
|
||||
orderInfo
|
||||
}
|
||||
// #endif
|
||||
// #ifndef H5
|
||||
console.log("==========paramparamparamparamparam------pay", param)
|
||||
let [err, res] = await uni.requestPayment(param)
|
||||
if (err) {
|
||||
console.log("=======pay err", err)
|
||||
that.showToast({
|
||||
title: `支付失败`
|
||||
})
|
||||
await Promise.reject("支付失败")
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
// #endif
|
||||
},
|
||||
//小程序自带获取定位
|
||||
getLocation() {
|
||||
let that = this;
|
||||
return new Promise((resove, reject) => {
|
||||
uni.getLocation({
|
||||
success: function(res) {
|
||||
resove(res)
|
||||
},
|
||||
fail: function(e) {
|
||||
console.log(e)
|
||||
reject(e)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
//百度地图获取定位
|
||||
getBmapLocation: function(ak = 'GoI7BxLpfvBEyf1TcMXCloi99Vov7flZ') {
|
||||
// #ifdef H5
|
||||
// H5环境下使用腾讯地图API
|
||||
return this.getTencentLocation();
|
||||
// #endif
|
||||
|
||||
// #ifndef H5
|
||||
// 非H5环境使用百度地图API
|
||||
//定位
|
||||
let that = this;
|
||||
let bmap = require('./bmap-wx.min.js');
|
||||
let BMap = new bmap.BMapWX({
|
||||
ak
|
||||
});
|
||||
return new Promise((resove, reject) => {
|
||||
BMap.regeocoding({
|
||||
success: function(data) {
|
||||
let addressInfo = data.originalData.result;
|
||||
let {
|
||||
lat,
|
||||
lng
|
||||
} = addressInfo.location;
|
||||
let {
|
||||
formatted_address: address,
|
||||
addressComponent
|
||||
} = addressInfo;
|
||||
let {
|
||||
province,
|
||||
city,
|
||||
district
|
||||
} = addressComponent
|
||||
//只返回需要的数据
|
||||
let locationInfo = {
|
||||
lat,
|
||||
lng,
|
||||
address,
|
||||
province,
|
||||
city,
|
||||
district,
|
||||
}
|
||||
// console.log(locationInfo, "====util locationInfo");
|
||||
//成功回调
|
||||
resove(locationInfo)
|
||||
},
|
||||
fail: function(res) {
|
||||
//失败返回默认的数据
|
||||
let locationInfo = {
|
||||
name: '',
|
||||
latitude: 0,
|
||||
longitude: 0,
|
||||
address: '',
|
||||
city: ''
|
||||
}
|
||||
resove(locationInfo)
|
||||
that.hideAll()
|
||||
//失败后的提示
|
||||
let errMsg = res.errMsg;
|
||||
if (errMsg.includes("domain")) {
|
||||
uni.showModal({
|
||||
title: "获取定位失败",
|
||||
content: `请在小程序公众平台添加百度域名api.map.baidu.com`,
|
||||
showCancel: false
|
||||
})
|
||||
return;
|
||||
}
|
||||
if (errMsg.includes("Referer")) {
|
||||
uni.showModal({
|
||||
title: "获取定位失败",
|
||||
content: `登录百度开放平台给ak添加白名单`,
|
||||
showCancel: false
|
||||
})
|
||||
return;
|
||||
}
|
||||
// uni.showModal({
|
||||
// title: "获取定位失败",
|
||||
// content: "请检查手机是否开启定位功能",
|
||||
// showCancel: false
|
||||
// })
|
||||
|
||||
uni.showModal({
|
||||
title: "地理位置授权",
|
||||
content: "为了更好的为您服务,请开启您手机中的定位授权",
|
||||
confirmText: "去授权",
|
||||
success(res) {
|
||||
if (res.confirm) {
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.openSetting({
|
||||
success(result) {
|
||||
if (result.authSetting[
|
||||
`scope.userLocation`]) {
|
||||
resove(true)
|
||||
} else {
|
||||
reject()
|
||||
}
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
// H5环境下提示用户手动在浏览器设置中开启位置权限
|
||||
that.showToast({
|
||||
title: '请在浏览器设置中手动开启位置权限'
|
||||
});
|
||||
reject(new Error('Location permission denied'));
|
||||
// #endif
|
||||
} else {
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "您取消了授权,是否重新设置【位置信息】权限",
|
||||
confirmText: "去授权",
|
||||
success(res) {
|
||||
if (!res.confirm) return
|
||||
uni.openSetting({
|
||||
success(result) {
|
||||
if (result.authSetting[
|
||||
`scope.userLocation`
|
||||
]) {
|
||||
resove(true)
|
||||
} else {
|
||||
reject()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
// H5环境下提示用户手动在浏览器设置中开启位置权限
|
||||
that.showToast({
|
||||
title: '请在浏览器设置中手动开启位置权限'
|
||||
});
|
||||
reject(new Error('Location permission denied'));
|
||||
// #endif
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
// #endif
|
||||
},
|
||||
// H5环境下使用腾讯地图API获取位置
|
||||
getTencentLocation: function() {
|
||||
let that = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
// 检查是否已经缓存了位置信息
|
||||
let cachedLocation = uni.getStorageSync('cached_location');
|
||||
let cacheTime = uni.getStorageSync('location_cache_time');
|
||||
let now = new Date().getTime();
|
||||
|
||||
// 如果有缓存且缓存时间不超过30分钟,直接返回缓存的位置
|
||||
if (cachedLocation && cacheTime && (now - cacheTime) < 30 * 60 * 1000) {
|
||||
resolve(cachedLocation);
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查浏览器是否支持地理位置API
|
||||
if (!navigator.geolocation) {
|
||||
that.showToast({
|
||||
title: '您的浏览器不支持地理位置功能'
|
||||
});
|
||||
reject(new Error('Geolocation not supported'));
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用浏览器原生API获取位置
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
async (position) => {
|
||||
try {
|
||||
// 获取到经纬度后,使用腾讯地图API进行逆地理编码
|
||||
const { latitude, longitude } = position.coords;
|
||||
|
||||
// 使用腾讯地图API获取详细地址信息
|
||||
const response = await that.fetchAddressFromTencent(latitude, longitude);
|
||||
|
||||
let locationInfo = {
|
||||
lat: latitude,
|
||||
lng: longitude,
|
||||
address: response.address || '',
|
||||
province: response.province || '',
|
||||
city: response.city || '',
|
||||
district: response.district || ''
|
||||
};
|
||||
|
||||
// 缓存位置信息
|
||||
uni.setStorageSync('cached_location', locationInfo);
|
||||
uni.setStorageSync('location_cache_time', now);
|
||||
|
||||
resolve(locationInfo);
|
||||
} catch (error) {
|
||||
console.error('获取地址信息失败:', error);
|
||||
that.showToast({
|
||||
title: '获取地址信息失败'
|
||||
});
|
||||
reject(error);
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
console.error('获取位置失败:', error);
|
||||
that.showToast({
|
||||
title: '获取位置失败,请检查浏览器位置权限设置'
|
||||
});
|
||||
reject(error);
|
||||
},
|
||||
{
|
||||
enableHighAccuracy: true,
|
||||
timeout: 10000,
|
||||
maximumAge: 30 * 60 * 1000 // 30分钟的缓存
|
||||
}
|
||||
);
|
||||
});
|
||||
},
|
||||
// 使用腾讯地图API获取详细地址信息
|
||||
fetchAddressFromTencent: function(lat, lng) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 从manifest.json中获取腾讯地图API key
|
||||
const key = 'TPGBZ-VDUK3-ILX35-REJQK-5NBI2-UBF75';
|
||||
|
||||
// 使用腾讯地图逆地理编码API
|
||||
uni.request({
|
||||
url: `https://apis.map.qq.com/ws/geocoder/v1/`,
|
||||
data: {
|
||||
location: `${lat},${lng}`,
|
||||
key: key,
|
||||
get_poi: 1
|
||||
},
|
||||
success: (res) => {
|
||||
if (res.data.status === 0 && res.data.result) {
|
||||
const { address_component, formatted_address } = res.data.result;
|
||||
resolve({
|
||||
province: address_component.province,
|
||||
city: address_component.city,
|
||||
district: address_component.district,
|
||||
address: formatted_address
|
||||
});
|
||||
} else {
|
||||
reject(new Error('腾讯地图API返回错误'));
|
||||
}
|
||||
},
|
||||
fail: (error) => {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
273
uniapp/uni-app/utils/jpush.js
Normal file
273
uniapp/uni-app/utils/jpush.js
Normal file
@@ -0,0 +1,273 @@
|
||||
// 引用方式
|
||||
var jpushModule = uni.requireNativePlugin("JG-JPush");
|
||||
// console.log('【sk】【引用方式】【jpushModule】【requireNativePlugin】', jpushModule)
|
||||
|
||||
// 开启 debug 模式,默认是关闭
|
||||
function openDebug() {
|
||||
jpushModule.setLoggerEnable(true);
|
||||
}
|
||||
|
||||
// 关闭 debug 模式,默认是关闭
|
||||
function closeDebug() {
|
||||
jpushModule.setLoggerEnable(false);
|
||||
}
|
||||
|
||||
// 获取 RegistrationID,只有当应用程序成功注册到 JPush 的服务器时才返回对应的值,否则返回空字符串
|
||||
function getRegistrationID(skBack) {
|
||||
jpushModule.getRegistrationID(result=>{
|
||||
// code number 状态码 0 - 成功, 1011 - iOS模拟器调用会报此错误
|
||||
// registerID string 返回的 registrationID
|
||||
console.log('【sk】获取 RegistrationID=>',result)
|
||||
skBack(result.registerID)
|
||||
})
|
||||
}
|
||||
|
||||
// 跳转至系统设置页面,0 - 成功 1 - 失败
|
||||
function openSettingsForNotification() {
|
||||
jpushModule.openSettingsForNotification((result)=>{
|
||||
// code number 0 - 成功 1 - 失败
|
||||
console.log('【sk】跳转至系统设置页面result=>',result.code)
|
||||
})
|
||||
}
|
||||
|
||||
// 初始化SDK iOS 说明:如果在mainfest.json里 将JPUSH_DEFAULTINITJPUSH_IOS值配置为"true",插件内部将默认初始化JPush,用户则不需要调用该初始化方法。
|
||||
function initJPushService() {
|
||||
console.log(jpushModule,"========initJPushService jpushModule")
|
||||
jpushModule.initJPushService()
|
||||
}
|
||||
|
||||
// 连接状态回调,true - 已连接, false - 未连接
|
||||
function addConnectEventListener(skBack) {
|
||||
jpushModule.addConnectEventListener(result=>{
|
||||
// connectEnable boolean true - 已连接, false - 未连接
|
||||
console.log('【sk】连接状态回调=>',result.connectEnable)
|
||||
skBack(result.connectEnable);
|
||||
})
|
||||
}
|
||||
|
||||
// 通知事件回调
|
||||
function addNotificationListener(skBack) {
|
||||
jpushModule.addNotificationListener(result=>{
|
||||
// messageID string 唯一标识通知消息的 ID
|
||||
// title string 对应 Portal 推送通知界面上的“通知标题”字段
|
||||
// content string 对应 Portal 推送通知界面上的“通知内容”字段
|
||||
// badge string 对应 Portal 推送通知界面上的可选设置里面的“badge”字段 (ios only)
|
||||
// ring string 推送通知界面上的可选设置里面的“sound”字段 (ios only)
|
||||
// extras dictionary 对应 Portal 推送消息界面上的“可选设置”里的附加字段
|
||||
// iOS dictionary 对应原生返回的通知内容,如需要更多字段请查看该字段内容
|
||||
// android dictionary 对应原生返回的通知内容,如需要更多字段请查看该字段内容
|
||||
// notificationEventType string 分为notificationArrived和notificationOpened两种
|
||||
console.log('【sk】通知事件回调result=>',result)
|
||||
skBack(result);
|
||||
})
|
||||
}
|
||||
|
||||
// 自定义消息事件回调
|
||||
function addCustomMessageListener(skBack) {
|
||||
jpushModule.addCustomMessageListener(result=>{
|
||||
// messageID string 唯一标识通知消息的 ID
|
||||
// content string 对应 Portal 推送通知界面上的“通知内容”字段
|
||||
// extras dictionary 对应 Portal 推送消息界面上的“可选设置”里的附加字段
|
||||
console.log('【sk】自定义消息事件回调result=>',result)
|
||||
skBack(result);
|
||||
})
|
||||
}
|
||||
|
||||
// 应用内消息回调
|
||||
function addInMessageListener(skBack) {
|
||||
jpushModule.addInMessageListener(result=>{
|
||||
// eventType string show - 应用内消息展示 disappear - 应用内消息已消失 click - 应用内消息点击
|
||||
// messageType string 消息类型, eventType 不为 disappear时返回, inMessageNoti - 通知类型的inMessage
|
||||
// content dictionary 应用内消息内容, eventType 不为 disappear 时返回
|
||||
console.log('【sk】应用内消息回调result=>',result)
|
||||
skBack(result);
|
||||
})
|
||||
}
|
||||
|
||||
// 本地通知事件回调
|
||||
function addLocalNotificationListener(skBack) {
|
||||
jpushModule.addLocalNotificationListener(result=>{
|
||||
// messageID string 唯一标识通知消息的ID
|
||||
// title string 对应“通知标题”字段
|
||||
// content string 对应“通知内容”字段
|
||||
// extras dictionary 对应“附加内容”字段
|
||||
console.log('【sk】本地通知事件回调result=>',result)
|
||||
skBack(result);
|
||||
})
|
||||
}
|
||||
|
||||
// 添加一个本地通知
|
||||
function addLocalNotification(e) {
|
||||
jpushModule.addLocalNotification({
|
||||
messageID: e.messageID ? e.messageID : '', // 唯一标识通知消息的ID
|
||||
title: e.title ? e.title : '', // 对应“通知标题”字段
|
||||
content: e.content ? e.content : '', // 对应“通知内容”字段
|
||||
extras: e.extras ? e.extras : {name: '', age: ''} // 对应“附加内容”字段
|
||||
})
|
||||
}
|
||||
|
||||
// 移除指定的本地通知
|
||||
function removeLocalNotification(e) {
|
||||
jpushModule.removeLocalNotification({
|
||||
messageID: e.messageID ? e.messageID : '' // 唯一标识通知消息的ID
|
||||
})
|
||||
}
|
||||
|
||||
// 移除所有的本地通知
|
||||
function clearLocalNotifications() {
|
||||
jpushModule.clearLocalNotifications()
|
||||
}
|
||||
|
||||
// 标签别名事件回调
|
||||
function addTagAliasListener(skBack) {
|
||||
jpushModule.addTagAliasListener(result=>{
|
||||
// code number 请求状态码 0 - 成功
|
||||
// sequence number 请求时传入的序列号,会在回调时原样返回
|
||||
// tags StringArray 执行tag数组操作时返回
|
||||
// tag string 执行查询指定tag(queryTag)操作时会返回
|
||||
// tagEnable boolean 执行查询指定tag(queryTag)操作时会返回是否可用
|
||||
// alias string 对alias进行操作时返回
|
||||
console.log('【sk】标签别名事件回调result=>',result)
|
||||
skBack(result);
|
||||
})
|
||||
}
|
||||
|
||||
// 新增标签
|
||||
function addTags(e) {
|
||||
jpushModule.addTags({
|
||||
'tags': e.tags ? e.tags : [], // StringArray string类型的数组
|
||||
'sequence': e.sequence ? e.sequence : 1 // number 请求时传入的序列号,会在回调时原样返回
|
||||
})
|
||||
}
|
||||
|
||||
// 覆盖标签
|
||||
function updateTags(e) {
|
||||
jpushModule.updateTags({
|
||||
'tags': e.tags ? e.tags : [], // StringArray string类型的数组
|
||||
'sequence': e.sequence ? e.sequence : 1 // number 请求时传入的序列号,会在回调时原样返回
|
||||
})
|
||||
}
|
||||
|
||||
// 删除指定标签
|
||||
function deleteTags(e) {
|
||||
jpushModule.deleteTags({
|
||||
'tags': e.tags ? e.tags : [], // StringArray string类型的数组
|
||||
'sequence': e.sequence ? e.sequence : 1 // number 请求时传入的序列号,会在回调时原样返回
|
||||
})
|
||||
}
|
||||
|
||||
// 清除所有标签
|
||||
function cleanTags(e) {
|
||||
jpushModule.cleanTags({
|
||||
'sequence': e.sequence ? e.sequence : 1 // number 请求时传入的序列号,会在回调时原样返回
|
||||
})
|
||||
}
|
||||
|
||||
// 查询指定 tag 与当前用户绑定的状态
|
||||
function queryTag(e) {
|
||||
jpushModule.queryTag({
|
||||
'tag': e.tag ? e.tag : '', // string 需要查询的标签
|
||||
'sequence': e.sequence ? sequence : 1 // number 请求时传入的序列号,会在回调时原样返回
|
||||
})
|
||||
}
|
||||
|
||||
// 查询所有标签
|
||||
function getAllTags(e) {
|
||||
jpushModule.getAllTags({
|
||||
'sequence': e.sequence ? e.sequence : 1 // number 请求时传入的序列号,会在回调时原样返回
|
||||
})
|
||||
}
|
||||
|
||||
// 设置别名
|
||||
function setAlias(e) {
|
||||
console.log('设置别名',e)
|
||||
jpushModule.setAlias({
|
||||
'alias': e.alias ? e.alias : '', // string 有效的别名组成:字母(区分大小写)、数字、下划线、汉字、特殊字符@!#$&*+=.|
|
||||
'sequence': e.sequence ? e.sequence : 1 // number 请求时传入的序列号,会在回调时原样返回
|
||||
})
|
||||
}
|
||||
|
||||
// 删除别名
|
||||
function deleteAlias(e) {
|
||||
jpushModule.deleteAlias({
|
||||
'sequence': e.sequence ? e.sequence : 1 // number 请求时传入的序列号,会在回调时原样返回
|
||||
})
|
||||
}
|
||||
|
||||
// 查询别名
|
||||
function queryAlias(e) {
|
||||
jpushModule.queryAlias({
|
||||
'sequence': e.sequence ? e.sequence : 1 // number 请求时传入的序列号,会在回调时原样返回
|
||||
})
|
||||
}
|
||||
|
||||
// 开启 CrashLog 上报
|
||||
function initCrashHandler() {
|
||||
jpushModule.initCrashHandler()
|
||||
}
|
||||
|
||||
// 设置地理围栏的最大个数
|
||||
function setMaxGeofenceNumber(e) {
|
||||
jpushModule.setMaxGeofenceNumber(e.geofenceNumber ? e.geofenceNumber : 10) // 默认值为 10 ,iOS系统默认地理围栏最大个数为20
|
||||
}
|
||||
|
||||
// 删除指定id的地理围栏
|
||||
function deleteGeofence(e) {
|
||||
jpushModule.deleteGeofence(e.geofence ? e.geofence : '') // 删除指定id的地理围栏
|
||||
}
|
||||
|
||||
// 设置 Badge
|
||||
function setBadge(e) {
|
||||
jpushModule.setBadge(e.badge ? e.badge : 0) // number
|
||||
}
|
||||
|
||||
// 设置手机号码
|
||||
function setMobileNumber(e) {
|
||||
jpushModule.setMobileNumber({
|
||||
sequence: e.sequence ? e.sequence : 1, // number 请求时传入的序列号,会在回调时原样返回
|
||||
mobileNumber: e.mobileNumber ? e.mobileNumber : '' // string 手机号码 会与用户信息一一对应。可为空,为空则清除号码。
|
||||
})
|
||||
}
|
||||
|
||||
// 设置手机号码回调
|
||||
function addMobileNumberListener(skBack) {
|
||||
jpushModule.addMobileNumberListener(result=>{
|
||||
// code number 状态码 0 - 成功
|
||||
// sequence number 请求时传入的序列号,会在回调时原样返回
|
||||
console.log('【sk】设置手机号码回调result=>',result)
|
||||
skBack(result);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
openDebug: openDebug,
|
||||
closeDebug: closeDebug,
|
||||
getRegistrationID: getRegistrationID,
|
||||
openSettingsForNotification: openSettingsForNotification,
|
||||
initJPushService: initJPushService,
|
||||
addConnectEventListener: addConnectEventListener,
|
||||
addNotificationListener: addNotificationListener,
|
||||
addCustomMessageListener: addCustomMessageListener,
|
||||
addInMessageListener: addInMessageListener,
|
||||
addLocalNotificationListener: addLocalNotificationListener,
|
||||
addLocalNotification: addLocalNotification,
|
||||
removeLocalNotification: removeLocalNotification,
|
||||
clearLocalNotifications: clearLocalNotifications,
|
||||
addTagAliasListener: addTagAliasListener,
|
||||
addTags: addTags,
|
||||
updateTags: updateTags,
|
||||
deleteTags: deleteTags,
|
||||
cleanTags: cleanTags,
|
||||
queryTag: queryTag,
|
||||
getAllTags: getAllTags,
|
||||
setAlias: setAlias,
|
||||
deleteAlias: deleteAlias,
|
||||
queryAlias: queryAlias,
|
||||
initCrashHandler: initCrashHandler,
|
||||
setMaxGeofenceNumber: setMaxGeofenceNumber,
|
||||
deleteGeofence: deleteGeofence,
|
||||
setBadge: setBadge,
|
||||
setMobileNumber: setMobileNumber,
|
||||
addMobileNumberListener: addMobileNumberListener
|
||||
}
|
||||
278
uniapp/uni-app/utils/req.js
Normal file
278
uniapp/uni-app/utils/req.js
Normal file
@@ -0,0 +1,278 @@
|
||||
// 接口返回值code说明
|
||||
// 200=>正常;
|
||||
// 400=>报错;
|
||||
// 401=>需要登陆;
|
||||
// 50001=>没有购买权限,错误并且弹出报错,报错内容为 error(小程序跳转到个人中心认证车手页面);
|
||||
|
||||
var Fly = require("./wx.js") //wx.js为您下载的源码文件
|
||||
var fly = new Fly; //创建fly实例
|
||||
var tokenFly = new Fly();
|
||||
import util from './index.js';
|
||||
import siteInfo from '../siteinfo.js';
|
||||
import $store from "@/store/index.js"
|
||||
|
||||
// 打印站点信息siteInfo
|
||||
let allSiteInfo = Object.assign({}, {
|
||||
time: "2022年09月129日 19:50",
|
||||
remark: "(test)~ update:apple_login~",
|
||||
}, siteInfo)
|
||||
console.log(allSiteInfo);
|
||||
|
||||
import {
|
||||
networkError,
|
||||
serverError,
|
||||
msgError,
|
||||
authError,
|
||||
vipError
|
||||
} from './error.js';
|
||||
//添加finally方法,用于指定不管 Promise 对象最后状态如何,都会执行的操作
|
||||
Promise.prototype.finally = function(callback) {
|
||||
let P = this.constructor;
|
||||
return this.then(
|
||||
value => P.resolve(callback()).then(() => value),
|
||||
reason => P.resolve(callback()).then(() => {
|
||||
throw reason
|
||||
})
|
||||
);
|
||||
};
|
||||
const isW7 = false
|
||||
const formatUrl = function(url) {
|
||||
let model_name = "farm";
|
||||
let baseUrl = isW7 ?
|
||||
`${siteInfo.siteroot}?i=${siteInfo.uniacid}&t=${siteInfo.multiid}&v=${siteInfo.version}&from=wxapp&c=entry&a=wxapp&do=api&core=core2&m=${model_name}&s=${url}` :
|
||||
`${siteInfo.siteroot}?i=${siteInfo.uniacid}&m=${model_name}&s=${url}`
|
||||
return baseUrl;
|
||||
}
|
||||
//阿里云地址转为本地域名的
|
||||
const formatImageUrl = function(url) {
|
||||
return url.includes(siteInfo.siteroot) ? url :
|
||||
`${formatUrl("card/getImage")}&path=${encodeURIComponent(url)}`
|
||||
}
|
||||
|
||||
//微信小程序登录
|
||||
const wxLogin = async function() {
|
||||
let {
|
||||
query
|
||||
} = await uni.getLaunchOptionsSync();
|
||||
console.log('query', query)
|
||||
let url = formatUrl("index/login")
|
||||
try {
|
||||
uni.showLoading({
|
||||
title: "登录中..."
|
||||
})
|
||||
let [providerErr, providerData] = await uni.getProvider({
|
||||
service: 'oauth',
|
||||
});
|
||||
let [loginErr, loginData] = await uni.login({
|
||||
provider: providerData.provider[0]
|
||||
});
|
||||
|
||||
let login_param = {
|
||||
code: loginData.code,
|
||||
pid: query.pid
|
||||
}
|
||||
|
||||
console.log("login_param==>", login_param);
|
||||
|
||||
let d = await tokenFly.post(url, login_param);
|
||||
let {
|
||||
code,
|
||||
data,
|
||||
error
|
||||
} = d.data
|
||||
|
||||
if (code !== 200) {
|
||||
uni.hideLoading()
|
||||
serverError({
|
||||
code,
|
||||
msg: error
|
||||
});
|
||||
throw d;
|
||||
}
|
||||
//登录成功
|
||||
uni.hideLoading()
|
||||
$store.commit('updateUserItem', {
|
||||
key: 'autograph',
|
||||
val: data.autograph
|
||||
})
|
||||
$store.commit('updateUserItem', {
|
||||
key: 'userInfo',
|
||||
val: data.data
|
||||
})
|
||||
return data;
|
||||
} catch (e) {
|
||||
uni.hideLoading()
|
||||
let {
|
||||
code,
|
||||
error
|
||||
} = e.response.data
|
||||
if (code !== 200) {
|
||||
serverError({
|
||||
code,
|
||||
msg: error
|
||||
});
|
||||
}
|
||||
return await Promise.reject(e);
|
||||
}
|
||||
}
|
||||
//设置超时
|
||||
fly.config.timeout = 15000;
|
||||
|
||||
//设置请求基地址
|
||||
|
||||
//给所有请求添加自定义header
|
||||
fly.config.headers = tokenFly.config.headers = {
|
||||
"content-type": "application/json"
|
||||
}
|
||||
|
||||
//添加请求拦截器
|
||||
fly.interceptors.request.use(
|
||||
async (request) => {
|
||||
//添加验证token
|
||||
request.headers['autograph'] = $store.state.user.autograph || '';
|
||||
// #ifdef APP-PLUS
|
||||
request.headers['isapp'] = 1;
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
request.headers['isapp'] = 2;
|
||||
// #endif
|
||||
return request;
|
||||
})
|
||||
|
||||
//添加响应拦截器,响应拦截器会在then/catch处理之前执行
|
||||
fly.interceptors.response.use(
|
||||
async (response) => {
|
||||
//token过期验证
|
||||
if (response.data.code != 401) return response;
|
||||
fly.lock()
|
||||
|
||||
//#ifdef MP-WEIXIN
|
||||
console.log("==> MP-WEIXIN 401")
|
||||
await wxLogin();
|
||||
//#endif
|
||||
|
||||
response.request.headers["autograph"] = $store.state.user.autograph || ''
|
||||
fly.unlock();
|
||||
return fly.request(response.request);
|
||||
},
|
||||
async (err) => {
|
||||
console.log(err, "=======fly.interceptors.response.use err");
|
||||
let {
|
||||
status = 0,
|
||||
} = err
|
||||
|
||||
util.hideAll()
|
||||
networkError({
|
||||
code: status,
|
||||
})
|
||||
//网络错误
|
||||
return await Promise.reject(err);
|
||||
}
|
||||
)
|
||||
|
||||
//统一处理请求,satus=200网络正常code=200服务器正常
|
||||
const httpType = ["post", "get"]
|
||||
const formatReq = function() {
|
||||
let req = {};
|
||||
httpType.forEach((type) => {
|
||||
req[type] = async function(url, param) {
|
||||
//构造请求地址
|
||||
url = formatUrl(url);
|
||||
let res = await fly[type](url, param)
|
||||
// console.log("=========res=======",res)
|
||||
// #ifdef MP-BAIDU
|
||||
res.data = typeof(res.data) == "string" ? JSON.parse(res.data) : res.data;
|
||||
// #endif
|
||||
let {
|
||||
code,
|
||||
error,
|
||||
data
|
||||
} = res.data
|
||||
code = code * 1
|
||||
if (code === 200) return data;
|
||||
//code!=200抛出错误
|
||||
util.hideAll();
|
||||
if (code == 50001) {
|
||||
authError({
|
||||
msg: error
|
||||
})
|
||||
} else if (code == -407) {
|
||||
let url = `/shop/pages/choose-store`
|
||||
util.goUrl({
|
||||
url
|
||||
})
|
||||
} else if (code == 50002) {
|
||||
vipError({
|
||||
msg: error
|
||||
})
|
||||
} else if (code == 400 && error) {
|
||||
console.log(code, error, "code != 200");
|
||||
msgError({
|
||||
msg: error
|
||||
})
|
||||
}
|
||||
return await Promise.reject(res.data);
|
||||
}
|
||||
})
|
||||
return req;
|
||||
}
|
||||
const req = formatReq();
|
||||
|
||||
|
||||
// 定义上传,picture--代表图片 audio--音频 video--视频,默认picture
|
||||
const uploadFile = async (url, {
|
||||
name = "file",
|
||||
filePath,
|
||||
header = {
|
||||
autograph: $store.state.user.autograph || '',
|
||||
// #ifdef APP-PLUS
|
||||
isapp: 1,
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
isapp: 2,
|
||||
// #endif
|
||||
},
|
||||
formData = {
|
||||
type: "picture",
|
||||
}
|
||||
} = {}) => {
|
||||
url = formatUrl(url);
|
||||
let [, res] = await uni.uploadFile({
|
||||
url,
|
||||
filePath,
|
||||
name,
|
||||
formData,
|
||||
header,
|
||||
})
|
||||
|
||||
if (res.statusCode != 200) {
|
||||
util.hideAll()
|
||||
networkError();
|
||||
return await Promise.reject(res);
|
||||
}
|
||||
let parseData = JSON.parse(res.data)
|
||||
//服务器错误
|
||||
let {
|
||||
code,
|
||||
msg,
|
||||
data
|
||||
} = parseData;
|
||||
if (code != 200) {
|
||||
util.hideAll()
|
||||
serverError({
|
||||
code,
|
||||
msg
|
||||
});
|
||||
return await Promise.reject(res);
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
export {
|
||||
fly,
|
||||
req,
|
||||
uploadFile,
|
||||
formatImageUrl,
|
||||
formatUrl,
|
||||
}
|
||||
205
uniapp/uni-app/utils/validate.js
Normal file
205
uniapp/uni-app/utils/validate.js
Normal file
@@ -0,0 +1,205 @@
|
||||
const strategies = {
|
||||
// errorMsg参数,提升了适用性
|
||||
isNotNull: function(value, errorMsg, regType) { //去空字符,不为空
|
||||
// regType 2去除所有空格
|
||||
if (regType == 2 && value) {
|
||||
value = value.replace(/(^\s*)|(\s*$)/g, "")
|
||||
}
|
||||
if (value === '' || value === undefined || value === false || JSON.stringify(value) === '[]' || JSON
|
||||
.stringify(value) === '{}') {
|
||||
// 返回字符串true 错误信息
|
||||
return errorMsg;
|
||||
}
|
||||
},
|
||||
minLength: function(value, errorMsg, length) { //限制最小长度
|
||||
if (value.length < length) {
|
||||
return errorMsg;
|
||||
}
|
||||
},
|
||||
maxLength: function(value, errorMsg, length) { //限制最大长度
|
||||
if (value == null || value.length < 1) {
|
||||
return errorMsg;
|
||||
} else if (value.length > length) {
|
||||
return `${errorMsg},最多¥${length}字`;
|
||||
}
|
||||
},
|
||||
isAllPhone: function(value, errorMsg, regType, regText) {
|
||||
regText = regText || '电话号码'
|
||||
let reg = /((^400)-([0-9]{7})$)|(^1[3-9]\d{9}$)|((^0\d{2,3})-(\d{7,8})$)/
|
||||
if (value == null || value.length < 1) {
|
||||
return errorMsg;
|
||||
} else if (!reg.test(value)) {
|
||||
return `${value} ${regText}无效`
|
||||
}
|
||||
},
|
||||
isMobile: function(value, errorMsg) {
|
||||
// if (!/^((\+?86)|(\(\+86\)))?(13[012356789][0-9]{8}|15[012356789][0-9]{8}|18[02356789][0-9]{8}|147[0-9]{8}|1349[0-9]{7}|([0-9]{3,4}-)?[0-9]{7,8})$/.test(value)) { //电话号码校验
|
||||
if (value == null || value.length < 1) {
|
||||
return errorMsg;
|
||||
}
|
||||
if (!/^(1[0-9]{10})$/.test(value)) { //电话号码校验
|
||||
return `${value} 手机号无效`;
|
||||
}
|
||||
},
|
||||
isZuoji: function(value, errorMsg) {
|
||||
if (!/0\d{2,3}-\d{7,8}|\(?0\d{2,3}[)-]?\d{7,8}|\(?0\d{2,3}[)-]*\d{7,8}$/.test(value)) { //座机号码校验
|
||||
return errorMsg;
|
||||
}
|
||||
},
|
||||
isNotText: function(value, errorMsg) {
|
||||
if (!/^[\u4e00-\u9fa5]+$/.test(value)) { //非中文校验
|
||||
} else {
|
||||
return errorMsg;
|
||||
}
|
||||
},
|
||||
isWechat: function(value, errorMsg) {
|
||||
if (!/^[a-zA-Z]{1}[-_a-zA-Z0-9]{5,29}$/.test(value)) { //微信号码校验
|
||||
return errorMsg;
|
||||
}
|
||||
},
|
||||
isEmail: function(value, errorMsg) {
|
||||
if (!/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(value)) { //邮箱校验
|
||||
return errorMsg;
|
||||
}
|
||||
},
|
||||
isMoney: function(value, errorMsg, regType) {
|
||||
// regType 1大于0;2可为0
|
||||
let regArr = {
|
||||
1: /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/,
|
||||
2: /^(([0-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/
|
||||
}
|
||||
let reg = regArr[regType]
|
||||
if (value == '') {
|
||||
return errorMsg;
|
||||
} else if (regType == 1 && value * 1 === 0) {
|
||||
return `${errorMsg},不可为0`;
|
||||
} else if (!reg.test(value)) {
|
||||
return `${errorMsg},最多2位小数`;
|
||||
}
|
||||
},
|
||||
isUrl: function(value, errorMsg) {
|
||||
if (value.indexOf('http') < 0) {
|
||||
return errorMsg;
|
||||
}
|
||||
},
|
||||
isNumber: function(value, errorMsg) {
|
||||
if (!/^[1-9]+[0-9]*]*$/.test(value)) {
|
||||
return errorMsg;
|
||||
}
|
||||
},
|
||||
isFloatNum: function(value, errorMsg, regType, dotLen) {
|
||||
// dotLen 保留几位小数
|
||||
// regType 1大于0;2可为0
|
||||
let regArr = {
|
||||
1: {
|
||||
1: /^(([1-9][0-9]*)|(([0]\.\d{1}|[1-9][0-9]*\.\d{1})))$/,
|
||||
2: /^(([0-9][0-9]*)|(([0]\.\d{1}|[1-9][0-9]*\.\d{1})))$/
|
||||
},
|
||||
2: {
|
||||
1: /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/,
|
||||
2: /^(([0-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/
|
||||
}
|
||||
}
|
||||
let reg = regArr[dotLen][regType]
|
||||
if (value == '') {
|
||||
return errorMsg;
|
||||
} else if (regType == 1 && value * 1 === 0) {
|
||||
return `${errorMsg},不可为0`;
|
||||
} else if (!reg.test(value)) {
|
||||
return `${errorMsg},最多${dotLen}位小数`;
|
||||
}
|
||||
},
|
||||
isIdCard: function(value, errorMsg) {
|
||||
var regIdCard =
|
||||
/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
|
||||
if (value == null || value.length < 1) {
|
||||
return errorMsg;
|
||||
}
|
||||
if (regIdCard.test(value)) {
|
||||
if (value.length == 18) {
|
||||
var idCardWi = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4,
|
||||
2); //将前17位加权因子保存在数组里
|
||||
var idCardY = new Array(1, 0, 10, 9, 8, 7, 6, 5, 4, 3,
|
||||
2); //这是除以11后,可能产生的11位余数、验证码,也保存成数组
|
||||
var idCardWiSum = 0; //用来保存前17位各自乖以加权因子后的总和
|
||||
for (var i = 0; i < 17; i++) {
|
||||
idCardWiSum += value.substring(i, i + 1) * idCardWi[i];
|
||||
}
|
||||
var idCardMod = idCardWiSum % 11; //计算出校验码所在数组的位置
|
||||
var idCardLast = value.substring(17); //得到最后一位身份证号码
|
||||
//如果等于2,则说明校验码是10,身份证号码最后一位应该是X
|
||||
if (idCardMod == 2) {
|
||||
if (idCardLast == "X" || idCardLast == "x") {} else {
|
||||
return `${value} 身份证号码最后一位应为X`;
|
||||
}
|
||||
} else {
|
||||
//用计算出的验证码与最后一位身份证号码匹配,如果一致,说明通过,否则是无效的身份证号码
|
||||
if (idCardLast == idCardY[idCardMod]) {} else {
|
||||
return `${value} 身份证号码无效`;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return `${value} 身份证号码无效`;
|
||||
}
|
||||
}
|
||||
};
|
||||
class Validate {
|
||||
constructor() {
|
||||
this.cache = []
|
||||
}
|
||||
}
|
||||
Validate.prototype.add = function(value, item = {}) {
|
||||
let {
|
||||
checkType,
|
||||
errorMsg,
|
||||
length,
|
||||
regType = 1,
|
||||
regText,
|
||||
dotLen = 2
|
||||
} = item
|
||||
this.cache.push(function() {
|
||||
// 规则
|
||||
let method, arr;
|
||||
//判断为已有的策略还是新增的
|
||||
if (typeof checkType === 'string') {
|
||||
arr = checkType.split(':');
|
||||
let strategy = arr.shift();
|
||||
method = strategies[strategy];
|
||||
} else {
|
||||
arr = [];
|
||||
method = checkType;
|
||||
}
|
||||
arr.unshift(value);
|
||||
arr.push(errorMsg);
|
||||
let lengthArr = ['minLength', 'maxLength']
|
||||
if (lengthArr.includes(checkType) && length) {
|
||||
arr.push(length);
|
||||
}
|
||||
let regTypeArr = ['isNotNull', 'isAllPhone', 'isMoney', 'isFloatNum']
|
||||
if (regTypeArr.includes(checkType)) {
|
||||
arr.push(regType);
|
||||
}
|
||||
let regTextArr = ['isAllPhone']
|
||||
if (regTextArr.includes(checkType)) {
|
||||
arr.push(regText);
|
||||
}
|
||||
let dotLenArr = ['isFloatNum']
|
||||
if (dotLenArr.includes(checkType)) {
|
||||
arr.push(dotLen);
|
||||
}
|
||||
// console.log(arr, "=============Validate arr")
|
||||
return method.apply(null, arr);
|
||||
});
|
||||
};
|
||||
|
||||
Validate.prototype.start = function() {
|
||||
for (let i = 0, validatorFunc; validatorFunc = this.cache[i++];) {
|
||||
let msg = validatorFunc();
|
||||
if (msg) {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default Validate
|
||||
776
uniapp/uni-app/utils/wx.js
Normal file
776
uniapp/uni-app/utils/wx.js
Normal file
@@ -0,0 +1,776 @@
|
||||
(function webpackUniversalModuleDefinition(root, factory) {
|
||||
if (typeof exports === 'object' && typeof module === 'object')
|
||||
module.exports = factory();
|
||||
else if (typeof define === 'function' && define.amd)
|
||||
define([], factory);
|
||||
else {
|
||||
var a = factory();
|
||||
for (var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
|
||||
}
|
||||
})(this, function () {
|
||||
return /******/ (function (modules) { // webpackBootstrap
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
/******/
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
/******/
|
||||
/******/ // Check if module is in cache
|
||||
/******/ if (installedModules[moduleId]) {
|
||||
/******/ return installedModules[moduleId].exports;
|
||||
/******/
|
||||
}
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = installedModules[moduleId] = {
|
||||
/******/ i: moduleId,
|
||||
/******/ l: false,
|
||||
/******/ exports: {}
|
||||
/******/
|
||||
};
|
||||
/******/
|
||||
/******/ // Execute the module function
|
||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||
/******/
|
||||
/******/ // Flag the module as loaded
|
||||
/******/ module.l = true;
|
||||
/******/
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/
|
||||
}
|
||||
/******/
|
||||
/******/
|
||||
/******/ // expose the modules object (__webpack_modules__)
|
||||
/******/ __webpack_require__.m = modules;
|
||||
/******/
|
||||
/******/ // expose the module cache
|
||||
/******/ __webpack_require__.c = installedModules;
|
||||
/******/
|
||||
/******/ // identity function for calling harmony imports with the correct context
|
||||
/******/ __webpack_require__.i = function (value) { return value; };
|
||||
/******/
|
||||
/******/ // define getter function for harmony exports
|
||||
/******/ __webpack_require__.d = function (exports, name, getter) {
|
||||
/******/ if (!__webpack_require__.o(exports, name)) {
|
||||
/******/ Object.defineProperty(exports, name, {
|
||||
/******/ configurable: false,
|
||||
/******/ enumerable: true,
|
||||
/******/ get: getter
|
||||
/******/
|
||||
});
|
||||
/******/
|
||||
}
|
||||
/******/
|
||||
};
|
||||
/******/
|
||||
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
||||
/******/ __webpack_require__.n = function (module) {
|
||||
/******/ var getter = module && module.__esModule ?
|
||||
/******/ function getDefault() { return module['default']; } :
|
||||
/******/ function getModuleExports() { return module; };
|
||||
/******/ __webpack_require__.d(getter, 'a', getter);
|
||||
/******/ return getter;
|
||||
/******/
|
||||
};
|
||||
/******/
|
||||
/******/ // Object.prototype.hasOwnProperty.call
|
||||
/******/ __webpack_require__.o = function (object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
||||
/******/
|
||||
/******/ // __webpack_public_path__
|
||||
/******/ __webpack_require__.p = "";
|
||||
/******/
|
||||
/******/ // Load entry module and return exports
|
||||
/******/
|
||||
return __webpack_require__(__webpack_require__.s = 11);
|
||||
/******/
|
||||
})
|
||||
/************************************************************************/
|
||||
/******/([
|
||||
/* 0 */
|
||||
/***/ (function (module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
module.exports = {
|
||||
type: function type(ob) {
|
||||
return Object.prototype.toString.call(ob).slice(8, -1).toLowerCase();
|
||||
},
|
||||
isObject: function isObject(ob, real) {
|
||||
if (real) {
|
||||
return this.type(ob) === "object";
|
||||
} else {
|
||||
return ob && (typeof ob === 'undefined' ? 'undefined' : _typeof(ob)) === 'object';
|
||||
}
|
||||
},
|
||||
isFormData: function isFormData(val) {
|
||||
return typeof FormData !== 'undefined' && val instanceof FormData;
|
||||
},
|
||||
trim: function trim(str) {
|
||||
return str.replace(/(^\s*)|(\s*$)/g, '');
|
||||
},
|
||||
encode: function encode(val) {
|
||||
return encodeURIComponent(val).replace(/%40/gi, '@').replace(/%3A/gi, ':').replace(/%24/g, '$').replace(/%2C/gi, ',').replace(/%20/g, '+').replace(/%5B/gi, '[').replace(/%5D/gi, ']');
|
||||
},
|
||||
formatParams: function formatParams(data) {
|
||||
var str = "";
|
||||
var first = true;
|
||||
var that = this;
|
||||
|
||||
function _encode(sub, path) {
|
||||
var encode = that.encode;
|
||||
var type = that.type(sub);
|
||||
if (type == "array") {
|
||||
sub.forEach(function (e, i) {
|
||||
_encode(e, path + "%5B%5D");
|
||||
});
|
||||
} else if (type == "object") {
|
||||
for (var key in sub) {
|
||||
if (path) {
|
||||
_encode(sub[key], path + "%5B" + encode(key) + "%5D");
|
||||
} else {
|
||||
_encode(sub[key], encode(key));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!first) {
|
||||
str += "&";
|
||||
}
|
||||
first = false;
|
||||
str += path + "=" + encode(sub);
|
||||
}
|
||||
}
|
||||
|
||||
_encode(data, "");
|
||||
return str;
|
||||
},
|
||||
|
||||
// Do not overwrite existing attributes
|
||||
merge: function merge(a, b) {
|
||||
for (var key in b) {
|
||||
if (!a.hasOwnProperty(key)) {
|
||||
a[key] = b[key];
|
||||
} else if (this.isObject(b[key], 1) && this.isObject(a[key], 1)) {
|
||||
this.merge(a[key], b[key]);
|
||||
}
|
||||
}
|
||||
return a;
|
||||
}
|
||||
};
|
||||
|
||||
/***/
|
||||
}),
|
||||
/* 1 */
|
||||
/***/ (function (module, exports, __webpack_require__) {
|
||||
|
||||
function KEEP(_, cb) { cb(); }
|
||||
"use strict";
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
/*
|
||||
* author: wendu
|
||||
* email: 824783146@qq.com
|
||||
**/
|
||||
|
||||
var util = __webpack_require__(0);
|
||||
var isBrowser = typeof document !== "undefined";
|
||||
|
||||
//EngineWrapper can help generating a http engine quickly through a adapter
|
||||
function EngineWrapper(adapter) {
|
||||
var AjaxEngine = function () {
|
||||
function AjaxEngine() {
|
||||
_classCallCheck(this, AjaxEngine);
|
||||
|
||||
this.requestHeaders = {};
|
||||
this.readyState = 0;
|
||||
this.timeout = 0; // 0 stands for no timeout
|
||||
this.responseURL = "";
|
||||
this.responseHeaders = {};
|
||||
}
|
||||
|
||||
_createClass(AjaxEngine, [{
|
||||
key: "_call",
|
||||
value: function _call(name) {
|
||||
this[name] && this[name].apply(this, [].splice.call(arguments, 1));
|
||||
}
|
||||
}, {
|
||||
key: "_changeReadyState",
|
||||
value: function _changeReadyState(state) {
|
||||
this.readyState = state;
|
||||
this._call("onreadystatechange");
|
||||
}
|
||||
}, {
|
||||
key: "open",
|
||||
value: function open(method, url) {
|
||||
this.method = method;
|
||||
if (!url) {
|
||||
url = location.href;
|
||||
} else {
|
||||
url = util.trim(url);
|
||||
if (url.indexOf("http") !== 0) {
|
||||
// Normalize the request url
|
||||
if (isBrowser) {
|
||||
var t = document.createElement("a");
|
||||
t.href = url;
|
||||
url = t.href;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.responseURL = url;
|
||||
this._changeReadyState(1);
|
||||
}
|
||||
}, {
|
||||
key: "send",
|
||||
value: function send(arg) {
|
||||
var _this = this;
|
||||
|
||||
arg = arg || null;
|
||||
// if (isBrowser) {
|
||||
// var cookie = document.cookie;
|
||||
// if (cookie) {
|
||||
// this.requestHeaders.cookie = cookie;
|
||||
// }
|
||||
// }
|
||||
var self = this;
|
||||
if (adapter) {
|
||||
var request = {
|
||||
method: self.method,
|
||||
url: self.responseURL,
|
||||
headers: self.requestHeaders || {},
|
||||
body: arg
|
||||
};
|
||||
util.merge(request, self._options || {});
|
||||
if (request.method === "GET") {
|
||||
request.body = null;
|
||||
}
|
||||
self._changeReadyState(3);
|
||||
var timer;
|
||||
self.timeout = self.timeout || 0;
|
||||
if (self.timeout > 0) {
|
||||
timer = setTimeout(function () {
|
||||
if (self.readyState === 3) {
|
||||
_this._call("onloadend");
|
||||
self._changeReadyState(0);
|
||||
self._call("ontimeout");
|
||||
}
|
||||
}, self.timeout);
|
||||
}
|
||||
request.timeout = self.timeout;
|
||||
adapter(request, function (response) {
|
||||
|
||||
function getAndDelete(key) {
|
||||
var t = response[key];
|
||||
delete response[key];
|
||||
return t;
|
||||
}
|
||||
|
||||
// If the request has already timeout, return
|
||||
if (self.readyState !== 3) return;
|
||||
clearTimeout(timer);
|
||||
|
||||
// Make sure the type of status is integer
|
||||
self.status = getAndDelete("statusCode") - 0;
|
||||
|
||||
var responseText = getAndDelete("responseText");
|
||||
var statusMessage = getAndDelete("statusMessage");
|
||||
|
||||
// Network error, set the status code 0
|
||||
if (!self.status) {
|
||||
self.statusText = responseText;
|
||||
self._call("onerror", { msg: statusMessage });
|
||||
} else {
|
||||
// Parsing the response headers to array in a object, because
|
||||
// there may be multiple values with the same header name
|
||||
var responseHeaders = getAndDelete("headers");
|
||||
var headers = {};
|
||||
for (var field in responseHeaders) {
|
||||
var value = responseHeaders[field];
|
||||
var key = field.toLowerCase();
|
||||
// Is array
|
||||
if ((typeof value === "undefined" ? "undefined" : _typeof(value)) === "object") {
|
||||
headers[key] = value;
|
||||
} else {
|
||||
headers[key] = headers[key] || [];
|
||||
headers[key].push(value);
|
||||
}
|
||||
}
|
||||
var cookies = headers["set-cookie"];
|
||||
if (isBrowser && cookies) {
|
||||
cookies.forEach(function (e) {
|
||||
// Remove the http-Only property of the cookie
|
||||
// so that JavaScript can operate it.
|
||||
document.cookie = e.replace(/;\s*httpOnly/ig, "");
|
||||
});
|
||||
}
|
||||
self.responseHeaders = headers;
|
||||
// Set the fields of engine from response
|
||||
self.statusText = statusMessage || "";
|
||||
self.response = self.responseText = responseText;
|
||||
self._response = response;
|
||||
self._changeReadyState(4);
|
||||
self._call("onload");
|
||||
}
|
||||
self._call("onloadend");
|
||||
});
|
||||
} else {
|
||||
console.error("Ajax require adapter");
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "setRequestHeader",
|
||||
value: function setRequestHeader(key, value) {
|
||||
this.requestHeaders[util.trim(key)] = value;
|
||||
}
|
||||
}, {
|
||||
key: "getResponseHeader",
|
||||
value: function getResponseHeader(key) {
|
||||
return (this.responseHeaders[key.toLowerCase()] || "").toString() || null;
|
||||
}
|
||||
}, {
|
||||
key: "getAllResponseHeaders",
|
||||
value: function getAllResponseHeaders() {
|
||||
var str = "";
|
||||
for (var key in this.responseHeaders) {
|
||||
str += key + ":" + this.getResponseHeader(key) + "\r\n";
|
||||
}
|
||||
return str || null;
|
||||
}
|
||||
}, {
|
||||
key: "abort",
|
||||
value: function abort(msg) {
|
||||
this._changeReadyState(0);
|
||||
this._call("onerror", { msg: msg });
|
||||
this._call("onloadend");
|
||||
}
|
||||
}], [{
|
||||
key: "setAdapter",
|
||||
value: function setAdapter(requestAdapter) {
|
||||
adapter = requestAdapter;
|
||||
}
|
||||
}]);
|
||||
|
||||
return AjaxEngine;
|
||||
}();
|
||||
|
||||
return AjaxEngine;
|
||||
}
|
||||
|
||||
// learn more about keep-loader: https://github.com/wendux/keep-loader
|
||||
;
|
||||
module.exports = EngineWrapper;
|
||||
|
||||
/***/
|
||||
}),
|
||||
/* 2 */
|
||||
/***/ (function (module, exports, __webpack_require__) {
|
||||
|
||||
function KEEP(_, cb) { cb(); }
|
||||
"use strict";
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var utils = __webpack_require__(0);
|
||||
var isBrowser = typeof document !== "undefined";
|
||||
|
||||
var Fly = function () {
|
||||
function Fly(engine) {
|
||||
_classCallCheck(this, Fly);
|
||||
|
||||
this.engine = engine || XMLHttpRequest;
|
||||
|
||||
this.default = this; //For typeScript
|
||||
|
||||
/**
|
||||
* Add lock/unlock API for interceptor.
|
||||
*
|
||||
* Once an request/response interceptor is locked, the incoming request/response
|
||||
* will be added to a queue before they enter the interceptor, they will not be
|
||||
* continued until the interceptor is unlocked.
|
||||
*
|
||||
* @param [interceptor] either is interceptors.request or interceptors.response
|
||||
*/
|
||||
function wrap(interceptor) {
|
||||
var completer;
|
||||
utils.merge(interceptor, {
|
||||
lock: function lock() {
|
||||
if (!completer) {
|
||||
interceptor.p = new Promise(function (resolve) {
|
||||
completer = resolve;
|
||||
});
|
||||
}
|
||||
},
|
||||
unlock: function unlock() {
|
||||
if (completer) {
|
||||
completer();
|
||||
interceptor.p = completer = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var interceptors = this.interceptors = {
|
||||
response: {
|
||||
use: function use(handler, onerror) {
|
||||
this.handler = handler;
|
||||
this.onerror = onerror;
|
||||
}
|
||||
},
|
||||
request: {
|
||||
use: function use(handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var irq = interceptors.request;
|
||||
var irp = interceptors.response;
|
||||
wrap(irp);
|
||||
wrap(irq);
|
||||
|
||||
this.config = {
|
||||
method: "GET",
|
||||
baseURL: "",
|
||||
headers: {},
|
||||
timeout: 0,
|
||||
parseJson: true, // Convert response data to JSON object automatically.
|
||||
withCredentials: false
|
||||
};
|
||||
}
|
||||
|
||||
_createClass(Fly, [{
|
||||
key: "request",
|
||||
value: function request(url, data, options) {
|
||||
var _this = this;
|
||||
|
||||
var engine = new this.engine();
|
||||
var contentType = "Content-Type";
|
||||
var contentTypeLowerCase = contentType.toLowerCase();
|
||||
var interceptors = this.interceptors;
|
||||
var requestInterceptor = interceptors.request;
|
||||
var responseInterceptor = interceptors.response;
|
||||
var requestInterceptorHandler = requestInterceptor.handler;
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
if (utils.isObject(url)) {
|
||||
options = url;
|
||||
url = options.url;
|
||||
}
|
||||
options = options || {};
|
||||
options.headers = options.headers || {};
|
||||
|
||||
function isPromise(p) {
|
||||
// some polyfill implementation of Promise may be not standard,
|
||||
// so, we test by duck-typing
|
||||
return p && p.then && p.catch;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the request/response interceptor has been locked,
|
||||
* the new request/response will enter a queue. otherwise, it will be performed directly.
|
||||
* @param [promise] if the promise exist, means the interceptor is locked.
|
||||
* @param [callback]
|
||||
*/
|
||||
function enqueueIfLocked(promise, callback) {
|
||||
if (promise) {
|
||||
promise.then(function () {
|
||||
callback();
|
||||
});
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
// make the http request
|
||||
function makeRequest(options) {
|
||||
data = options.body;
|
||||
// Normalize the request url
|
||||
url = utils.trim(options.url);
|
||||
var baseUrl = utils.trim(options.baseURL || "");
|
||||
if (!url && isBrowser && !baseUrl) url = location.href;
|
||||
if (url.indexOf("http") !== 0) {
|
||||
var isAbsolute = url[0] === "/";
|
||||
if (!baseUrl && isBrowser) {
|
||||
var arr = location.pathname.split("/");
|
||||
arr.pop();
|
||||
baseUrl = location.protocol + "//" + location.host + (isAbsolute ? "" : arr.join("/"));
|
||||
}
|
||||
if (baseUrl[baseUrl.length - 1] !== "/") {
|
||||
baseUrl += "/";
|
||||
}
|
||||
url = baseUrl + (isAbsolute ? url.substr(1) : url);
|
||||
if (isBrowser) {
|
||||
|
||||
// Normalize the url which contains the ".." or ".", such as
|
||||
// "http://xx.com/aa/bb/../../xx" to "http://xx.com/xx" .
|
||||
var t = document.createElement("a");
|
||||
t.href = url;
|
||||
url = t.href;
|
||||
}
|
||||
}
|
||||
|
||||
var responseType = utils.trim(options.responseType || "");
|
||||
engine.withCredentials = !!options.withCredentials;
|
||||
var isGet = options.method === "GET";
|
||||
if (isGet) {
|
||||
if (data) {
|
||||
if (utils.type(data) !== "string") {
|
||||
data = utils.formatParams(data);
|
||||
}
|
||||
url += (url.indexOf("?") === -1 ? "?" : "&") + data;
|
||||
}
|
||||
}
|
||||
engine.open(options.method, url);
|
||||
|
||||
// try catch for ie >=9
|
||||
try {
|
||||
engine.timeout = options.timeout || 0;
|
||||
if (responseType !== "stream") {
|
||||
engine.responseType = responseType;
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
if (!isGet) {
|
||||
// If the request data is json object, transforming it to json string,
|
||||
// and set request content-type to "json". In browser, the data will
|
||||
// be sent as RequestBody instead of FormData
|
||||
if (options.headers[contentType].toLowerCase() === "application/x-www-form-urlencoded") {
|
||||
data = utils.formatParams(data);
|
||||
} else if (!utils.isFormData(data) && ["object", "array"].indexOf(utils.type(data)) !== -1) {
|
||||
options.headers[contentType] = 'application/json;charset=utf-8';
|
||||
data = JSON.stringify(data);
|
||||
}
|
||||
}
|
||||
|
||||
for (var k in options.headers) {
|
||||
if (k === contentType && (utils.isFormData(data) || !data || isGet)) {
|
||||
// Delete the content-type, Let the browser set it
|
||||
delete options.headers[k];
|
||||
} else {
|
||||
try {
|
||||
// In browser environment, some header fields are readonly,
|
||||
// write will cause the exception .
|
||||
engine.setRequestHeader(k, options.headers[k]);
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onresult(handler, data, type) {
|
||||
enqueueIfLocked(responseInterceptor.p, function () {
|
||||
if (handler) {
|
||||
//如果失败,添加请求信息
|
||||
if (type) {
|
||||
data.request = options;
|
||||
}
|
||||
var ret = handler.call(responseInterceptor, data, Promise);
|
||||
data = ret === undefined ? data : ret;
|
||||
}
|
||||
if (!isPromise(data)) {
|
||||
data = Promise[type === 0 ? "resolve" : "reject"](data);
|
||||
}
|
||||
data.then(function (d) {
|
||||
resolve(d);
|
||||
}).catch(function (e) {
|
||||
reject(e);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function onerror(e) {
|
||||
e.engine = engine;
|
||||
onresult(responseInterceptor.onerror, e, -1);
|
||||
}
|
||||
|
||||
function Err(msg, status) {
|
||||
this.message = msg;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
engine.onload = function () {
|
||||
// The xhr of IE9 has not response filed
|
||||
var response = engine.response || engine.responseText;
|
||||
if (options.parseJson && (engine.getResponseHeader(contentType) || "").indexOf("json") !== -1
|
||||
// Some third engine implementation may transform the response text to json object automatically,
|
||||
// so we should test the type of response before transforming it
|
||||
&& !utils.isObject(response)) {
|
||||
response = JSON.parse(response);
|
||||
}
|
||||
var headers = {};
|
||||
var items = (engine.getAllResponseHeaders() || "").split("\r\n");
|
||||
items.pop();
|
||||
items.forEach(function (e) {
|
||||
var key = e.split(":")[0];
|
||||
headers[key] = engine.getResponseHeader(key);
|
||||
});
|
||||
var status = engine.status;
|
||||
var statusText = engine.statusText;
|
||||
var data = { data: response, headers: headers, status: status, statusText: statusText };
|
||||
// The _response filed of engine is set in adapter which be called in engine-wrapper.js
|
||||
utils.merge(data, engine._response);
|
||||
if (status >= 200 && status < 300 || status === 304) {
|
||||
data.engine = engine;
|
||||
data.request = options;
|
||||
onresult(responseInterceptor.handler, data, 0);
|
||||
} else {
|
||||
var e = new Err(statusText, status);
|
||||
e.response = data;
|
||||
onerror(e);
|
||||
}
|
||||
};
|
||||
|
||||
engine.onerror = function (e) {
|
||||
onerror(new Err(e.msg || "Network Error", 0));
|
||||
};
|
||||
|
||||
engine.ontimeout = function () {
|
||||
onerror(new Err("timeout [ " + engine.timeout + "ms ]", 1));
|
||||
};
|
||||
engine._options = options;
|
||||
setTimeout(function () {
|
||||
engine.send(isGet ? null : data);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
enqueueIfLocked(requestInterceptor.p, function () {
|
||||
utils.merge(options, _this.config);
|
||||
var headers = options.headers;
|
||||
headers[contentType] = headers[contentType] || headers[contentTypeLowerCase] || "";
|
||||
delete headers[contentTypeLowerCase];
|
||||
options.body = data || options.body;
|
||||
url = utils.trim(url || "");
|
||||
options.method = options.method.toUpperCase();
|
||||
options.url = url;
|
||||
var ret = options;
|
||||
if (requestInterceptorHandler) {
|
||||
ret = requestInterceptorHandler.call(requestInterceptor, options, Promise) || options;
|
||||
}
|
||||
if (!isPromise(ret)) {
|
||||
ret = Promise.resolve(ret);
|
||||
}
|
||||
ret.then(function (d) {
|
||||
//if options continue
|
||||
if (d === options) {
|
||||
makeRequest(d);
|
||||
} else {
|
||||
resolve(d);
|
||||
}
|
||||
}, function (err) {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
promise.engine = engine;
|
||||
return promise;
|
||||
}
|
||||
}, {
|
||||
key: "all",
|
||||
value: function all(promises) {
|
||||
return Promise.all(promises);
|
||||
}
|
||||
}, {
|
||||
key: "spread",
|
||||
value: function spread(callback) {
|
||||
return function (arr) {
|
||||
return callback.apply(null, arr);
|
||||
};
|
||||
}
|
||||
}, {
|
||||
key: "lock",
|
||||
value: function lock() {
|
||||
this.interceptors.request.lock();
|
||||
}
|
||||
}, {
|
||||
key: "unlock",
|
||||
value: function unlock() {
|
||||
this.interceptors.request.unlock();
|
||||
}
|
||||
}]);
|
||||
|
||||
return Fly;
|
||||
}();
|
||||
|
||||
//For typeScript
|
||||
|
||||
|
||||
Fly.default = Fly;
|
||||
|
||||
["get", "post", "put", "patch", "head", "delete"].forEach(function (e) {
|
||||
Fly.prototype[e] = function (url, data, option) {
|
||||
return this.request(url, data, utils.merge({ method: e }, option));
|
||||
};
|
||||
});
|
||||
// Learn more about keep-loader: https://github.com/wendux/keep-loader
|
||||
;
|
||||
module.exports = Fly;
|
||||
|
||||
/***/
|
||||
}),
|
||||
/* 3 */,
|
||||
/* 4 */,
|
||||
/* 5 */,
|
||||
/* 6 */
|
||||
/***/ (function (module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
//微信小程序适配器
|
||||
module.exports = function (request, responseCallback) {
|
||||
var con = {
|
||||
method: request.method,
|
||||
url: request.url,
|
||||
dataType: request.dataType || undefined,
|
||||
header: request.headers,
|
||||
data: request.body || {},
|
||||
success: function success(res) {
|
||||
responseCallback({
|
||||
statusCode: res.statusCode,
|
||||
responseText: res.data,
|
||||
headers: res.header,
|
||||
statusMessage: res.errMsg
|
||||
});
|
||||
},
|
||||
fail: function fail(res) {
|
||||
responseCallback({
|
||||
statusCode: res.statusCode || 0,
|
||||
statusMessage: res.errMsg
|
||||
});
|
||||
}
|
||||
};
|
||||
uni.request(con);
|
||||
};
|
||||
|
||||
/***/
|
||||
}),
|
||||
/* 7 */,
|
||||
/* 8 */,
|
||||
/* 9 */,
|
||||
/* 10 */,
|
||||
/* 11 */
|
||||
/***/ (function (module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
//微信小程序入口
|
||||
var Fly = __webpack_require__(2);
|
||||
var EngineWrapper = __webpack_require__(1);
|
||||
var adapter = __webpack_require__(6);
|
||||
var wxEngine = EngineWrapper(adapter);
|
||||
module.exports = function (engine) {
|
||||
return new Fly(engine || wxEngine);
|
||||
};
|
||||
|
||||
/***/
|
||||
})
|
||||
/******/]);
|
||||
});
|
||||
Reference in New Issue
Block a user