/**
* VUE 注册组件
*/
Vue.prototype.getVersion = function () {
var appVersion = api.appVersion;
return appVersion.match(/^[0-9]\d*\.\d*|0\.\d*[1-9]\d*$/)[0];
};
// Vue.prototype.Language=function(ludata,callback){
// var ludata="ZH"
// if (ludata=="ZH"){
// api.readFile({
// path: 'widget://res/zh.json'
// }, function(ret, err) {
// if (ret.status) {
// var a =ret.data;
// var ret=JSON.parse(a)
// callback(ret)
// } else {
// // alertJson(err)
// }
// });
// }else if(ludata="EN"){
// api.readFile({
// path: 'widget://res/en.json'
// }, function(ret, err) {
// if (ret.status) {
// // alertJson(ret)
// } else {
// // alertJson(err)
// }
// });
// }
// }
var template_shopCar = '
' + '
{{badge}}
' + '
订单
确认
' + '
';
Vue.component('shopcar', {
props: ["badge"],
template: template_shopCar,
methods: {
goToCar: function () {
// 跳转到购物车页面
this.goWin("orderCar_win", "../order/orderCar_win.html", "");
}
}
})
/**
* 弹出层
*/
Vue.component('zmqalert', {
props: ["info"],
template: '{{info.title}}
{{info.msg}}
',
methods: {
clickAlertBtn: function (type) {
this.info.show = false;
if (type == 0) {
this.$emit("donechoose", type);
}
// 0 点击确认 1 点击取消
}
}
})
/******************* 极光推送 *********************/
Vue.prototype.api = {
devices: 5,
}
/*
* 初始化极光
*/
Vue.prototype.initApush = function (userid) {
var ajpush = api.require('ajpush');
this.pushObject = ajpush;
var _this = this;
this.pushObject.init(function (ret, err) {
if (ret && ret.status) {
console.log("操作成功");
} else {
console.log("操作失败");
}
});
// 获取deviceToken,成功则继续走,否则gg
this.getTokenAndReid(this.pushObject, function (state) {
if (state == 'success') {
// 开始绑定别名和标签
_this.bindAliasAndTags(ajpush, userid);
// 注册监听接收时间
_this.configListen(ajpush);
}
})
}
/**
* 获取deviceToken和reid
*/
Vue.prototype.getTokenAndReid = function (ajpush, callback) {
var _this = this;
ajpush.getRegistrationId(function (ret) {
if (api.deviceToken == "" && _this.api.devices > 0) {
_this.api.devices -= 1;
_this.getTokenAndReid(ajpush, callback);
} else {
callback('success');
}
});
}
/**
* 绑定别名和标签
*/
Vue.prototype.bindAliasAndTags = function (ajpush, userid) {
var param = {
alias: userid.toString(),
tags: [userid.toString()]
};
//绑定别名
this.pushObject.bindAliasAndTags(param, function (ret) {
var statusCode = ret.statusCode;
});
}
/**
* 注册获取消息
*/
Vue.prototype.configListen = function (ajpush) {
var _this = this;
// // 添加消息接受事件
ajpush.setListener(function (ret) {
_this.sendEvent("checkRetailer");
});
api.addEventListener({
name: 'appintent'
}, function (ret, err) {
if (ret && ret.appParam.ajpush) {
if (ret.appParam.ajpush.extra.env == 4 || ret.appParam.ajpush.extra.env == '4') { // 消息中心
api.openWin({
name: 'msg',
url: '../luntai/msgDetails.html',
pageParam : {
sendUserId: ret.appParam.ajpush.extra.sendUserId
}
});
}
if (ret.appParam.ajpush.extra.env == 5 || ret.appParam.ajpush.extra.env == '5') { // 消息中心
api.openWin({
name: 'msg',
url: '../luntai/msgDetails.html',
});
}
}
})
}
/******************* 结束推送 *********************/
/**
* 多选控件
* h : 原先已经有的
* d : 需要渲染的数组
* t : 选择框标题
* n : 触发下拉框的id
*/
Vue.prototype.checkByDropdown = function (h, d, t, n, c) {
// document.body.style.position = 'fixed';
document.body.style.overflow = 'hidden';
new Dropdown({
dom: n, //点击触发下拉的选择框的id
type: 'multiple', //是单选还是多选 单选 single 多选 multiple
title: t, //选择框title
required: false, //是否必填
dataArr: d,
success: function (resp) { // 回调函数
// document.body.style.position = 'relative';
// var addList = new Array();
// alert(h.length)
// document.body.style.overflow = 'auto';
// resp.map(function(item,index){
// var has = false;
// h.map(function(ir,ids){
// alert(ir.id + ',' + item.id)
// if(item.id == ir.id){
// has = true;
// }
// })
// if(has == false){
// addList.push(item);
// }
// })
c(resp);
}
})
}
/**
* 将两个JSON对象拼接
*/
Vue.prototype.extend = function (a, b) {
for (var obj in b) {
a[obj] = b[obj];
}
return a;
}
// 判断手机号
Vue.prototype.phoneExg = function (phone) {
if (!(/^1[3456789]\d{9}$/.test(phone))) {
return false;
} else {
return true;
}
}
// 判断信息为空
Vue.prototype.checkInfo = function (content) {
if (content == '') {
api.toast({
msg: '必填项不能为空'
});
return false
} else {
return true
}
}
// 判断数组
Vue.prototype.checkArray = function (content) {
if (content.length == 0) {
api.toast({
msg: '必填项不能为空'
});
return false
} else {
return true
}
}
Vue.prototype.checkByDropdown1 = function (h, d, t, n, c) {
// document.body.style.position = 'fixed';
document.body.style.overflow = 'hidden';
new Dropdown({
dom: n, //点击触发下拉的选择框的id
type: 'multiple', //是单选还是多选 单选 single 多选 multiple
title: t, //选择框title
required: false, //是否必填
dataArr: d,
success: function (resp) { // 回调函数
// document.body.style.position = 'relative';
// var addList = new Array();
// alert(h.length)
// document.body.style.overflow = 'auto';
// resp.map(function(item,index){
// var has = false;
// h.map(function(ir,ids){
// alert(ir.id + ',' + item.id)
// if(item.id == ir.id){
// has = true;
// }
// })
// if(has == false){
// addList.push(item);
// }
// })
c(resp);
}
})
}
/**
* 将文字放到图片中生成img
*/
Vue.prototype.createImg = function (c) {
var canvas2 = document.createElement("canvas");
var _canvas = document.querySelector('div');
var w = parseInt(window.getComputedStyle(_canvas).width);
var h = parseInt(window.getComputedStyle(_canvas).height);
//将canvas画布放大若干倍,然后盛放在较小的容器内,就显得不模糊了
canvas2.width = w * 2;
canvas2.height = h * 2;
canvas2.style.width = w + "px";
canvas2.style.height = h + "px";
//可以按照自己的需求,对context的参数修改,translate指的是偏移量
// var context = canvas.getContext("2d");
// context.translate(0,0);
var context = canvas2.getContext("2d");
context.scale(2, 2);
html2canvas(document.querySelector('div'), {
canvas: canvas2
}).then(function (canvas) {
//document.body.appendChild(canvas);
//canvas转换成url,然后利用a标签的download属性,直接下载,绕过上传服务器再下载
c(canvas.toDataURL());
})
}
/**
* VUE 的扩展方法
*/
// 获取到的经销商信息
Vue.prototype.userInfo = function () {
this.info = "";
this.loginid = $api.getStorage('loginid');
this.retariler_id = $api.getStorage("retailerid");
this.storeName = $api.getStorage("storeName");
this.carNum = 0;
}
// 使用选择器的时候的数据封装
Vue.prototype.actionSelectorData = function (retlist, c) {
var list = new Array();
retlist.map(function (item, index) {
var option = {
name: eval("item." + c.name),
id: eval("item." + c.id),
}
list.push(option);
})
return list;
}
// 打开筛选页面
/**
* f - 打开页面名称
* s - 打开选择页面还是关闭
* e - 需要传到筛选页面的值
*/
var pageStatus = 'o';
Vue.prototype.configDownChoose = function (o, e) {
if (pageStatus == 'o') {
api.openFrame({
name: 'search',
url: '../search.html',
rect: {
x: 0,
y: e.value.h,
w: api.winWidth,
h: api.frameHeight
},
pageParam: {
e: JSON.stringify(e),
o: JSON.stringify(o),
},
bgColor: 'rgba(0,0,0,0)',
animatin: {
type: "movein", //动画类型(详见动画类型常量)
subType: "from_top", //动画子类型(详见动画子类型常量)
duration: 300 //动画过渡时间,默认300毫秒
}
});
pageStatus = 'c';
} else {
pageStatus = 'o';
api.closeFrame({
name: 'search',
});
}
}
// 使用motive配置下拉刷新
Vue.prototype.configHeaderRefush = function (callback) {
api.setCustomRefreshHeaderInfo({
bgColor: '#f2f8f9',
images: ['widget://image/refush1/ru0.png', 'widget://image/refush1/ru1.png', 'widget://image/refush1/ru2.png', 'widget://image/refush1/ru3.png', 'widget://image/refush1/ru4.png', 'widget://image/refush1/ru5.png', 'widget://image/refush1/ru6.png', 'widget://image/refush1/ru7.png'],
// images : ['widget://image/refush1/try.gif'],
tips: {
pull: '下拉刷新',
threshold: '松开立即刷新',
load: '正在刷新'
}
}, function () {
callback();
// //下拉刷新被触发,自动进入加载状态,使用 api.refreshHeaderLoadDone() 手动结束加载中状态
// //下拉刷新被触发,使用 api.refreshHeaderLoadDone() 结束加载中状态
// alert('开始加载刷新数据,摇一摇停止加载状态');
// api.addEventListener({
// name : 'shake'
// }, function(ret, err) {
// api.refreshHeaderLoadDone()
// });
});
}
// 配置下拉刷新
Vue.prototype.configHeadMotive = function (callback) {
api.setRefreshHeaderInfo({
visible: true,
bgColor: '#fff',
textColor: '#ccc',
textDown: '下拉刷新...',
textUp: '松开刷新...',
showTime: true
}, function (ret, err) {
if (ret) {
callback(ret);
}
});
}
// 配置下拉刷新
Vue.prototype.configBottomRefush = function (callback) {
new auiScroll({
listen: true,
distance: 0 //判断到达底部的距离,isToBottom为true
}, function (ret) {
if (ret.isToBottom) {
callback(true);
}
});
}
// 配置alert提示框
Vue.prototype.showAlert = function (m, c) {
api.alert({
title: '温馨提示',
msg: m,
buttons: ["确定"],
}, function (ret, err) {
//coding...
c();
});
}
// 延时关闭页面发送监听
Vue.prototype.doneSendEvent = function (n, t, e) {
var times = typeof t == 'undefined' ? 200 : t;
this.sendEvent(n, e);
setTimeout(function () {
api.closeWin({});
}, times);
}
// 提示信息
Vue.prototype.showToast = function (str) {
api.toast({
msg: str
});
}
// 扫码
Vue.prototype.scan = function (f, c) {
api.showProgress({
title: '请稍候',
text: '正在调起摄像头',
modal: false
});
f.open({
autorotation: true,
isDrawQRCodeRect: true,
}, function (ret, err) {
api.hideProgress();
if (ret) {
if (ret.eventType == 'success') {
c(ret.content);
}
} else {
api.toast({
msg: '扫码出错'
});
}
});
}
// 查看大图
Vue.prototype.lookBigImg = function (f, i) {
f.openImages({
imageUrls: i
});
}
// 扫码 -- 主要是条形码
Vue.prototype.scant = function (f, c) {
var param = {};
var resultCallback = function (ret, err) {
if (ret.eventType == 'success') {
c(ret.content);
}
};
f.openScanner(param, resultCallback);
}
// 输入框类型
Vue.prototype.showPromt = function (title, msg, buttons, callback) {
api.prompt({
title: title,
msg: msg,
buttons: buttons
}, function (ret, err) {
//coding...
callback(ret);
});
}
// 注册监听
Vue.prototype.addEvent = function (eventName, callback) {
api.addEventListener({
name: eventName,
}, function (ret, err) {
//coding...
callback(ret);
});
}
// 提示信息
Vue.prototype.showModal = function (title, msg, buttons, callback) {
api.confirm({
title: title,
msg: msg,
buttons: buttons.reverse(),
}, function (ret, err) {
//coding...
callback(ret.buttonIndex == 2 ? 1 : 2);
});
}
// 过滤掉数组中的对象
Vue.prototype.filterArrNotNull = function (s, a) {
return s.filter(a == null)
}
// 发送监听
Vue.prototype.sendEvent = function (eventName, params) {
api.sendEvent({
name: eventName,
extra: params
});
}
// 跳转页面
Vue.prototype.goWin = function (winName, winUrl, params) {
setTimeout(function () {
api.openWin({
name: winName,
url: winUrl,
pageParam: params,
bounces: false,
animation: {
type: "push", //动画类型(详见动画类型常量)
subType: "from_right", //动画子类型(详见动画子类型常量)
duration: 300 //动画过渡时间,默认300毫秒
}
});
}, 200);
}
// 点击查看大图
Vue.prototype.lookBigImage = function (a, srcs) {
a.openImages({
imageUrls: srcs
});
}
// 选择图片
Vue.prototype.chooseImage_onlycamer = function (c) {
var _this = this;
// 判断是相机还是图片库
api.actionSheet({
title: '选择附件',
cancelTitle: '这里是取消按钮',
buttons: ['相机']
}, function (ret, err) {
if (ret.buttonIndex == 2) {
return;
}
var imageT = ["", "camera"][ret.buttonIndex];
_this.startChooseImage(imageT, function (path) {
c(path);
});
});
}
// 选择图片
Vue.prototype.chooseImage = function (c) {
var _this = this;
// 判断是相机还是图片库
api.actionSheet({
title: '选择附件',
cancelTitle: '这里是取消按钮',
buttons: ['相机', '相册']
}, function (ret, err) {
if (ret.buttonIndex == 3) {
return;
}
var imageT = ["", "camera", "album"][ret.buttonIndex];
_this.startChooseImage(imageT, function (path) {
c(path);
});
});
}
// 开始选择图片
Vue.prototype.startChooseImage = function (imageT, callback) {
var _this = this;
api.getPicture({
sourceType: imageT,
encodingType: 'png',
mediaValue: 'pic',
destinationType: 'base64',
allowEdit: true,
quality: 50,
// targetWidth : 1000,
saveToPhotoAlbum: false
}, function (ret, err) {
if (ret) {
if (ret.data != "") {
_this.compreseImg(ret.data, function (img) {
callback(img)
});
_this.localImage = ret.data
}
} else {
// alert(JSON.stringify(err));
}
});
}
// 压缩图片
Vue.prototype.compreseImg = function (src, c) {
var _this = this;
auiCompress(src, {
width: 1080,
quantity: 50,
// 压缩成功
success: function (retimg) {
_this.getBlobBy64(retimg.base64, c);
}
})
}
// base64 To blob
Vue.prototype.getBlobBy64 = function (dataurl, c) {
var filename = 'file';
var arr = dataurl.split(',')
var mime = arr[0].match(/:(.*?);/)[1]
var suffix = mime.split('/')[1]
var bstr = atob(arr[1])
var n = bstr.length
var u8arr = new Uint8Array(n)
while (n--) {
u8arr[n] = bstr.charCodeAt(n)
}
c(new File([u8arr], `${filename}.${suffix}`, {
type: mime
}))
}
// 关闭页面
Vue.prototype.closeWin = function () {
setTimeout(function () {
api.closeWin({});
}, 200);
}
// 点击选择省市区
Vue.prototype.chooseRegion = function (UIActionSelector, col, datasUrl, callback) {
UIActionSelector.open({
datas: datasUrl,
layout: {
row: 5,
col: col,
height: 30,
size: 12,
sizeActive: 14,
rowSpacing: 5,
colSpacing: 10,
maskBg: 'rgba(0,0,0,0.2)',
bg: '#fff',
color: '#ddd',
colorActive: '#f00',
colorSelected: '#000'
},
animation: true,
cancel: {
text: '取消',
size: 12,
w: 90,
h: 35,
bg: '#fff',
bgActive: '#ccc',
color: '#888',
colorActive: '#fff'
},
ok: {
text: '确定',
size: 12,
w: 90,
h: 35,
bg: '#fff',
bgActive: '#ccc',
color: '#888',
colorActive: '#fff'
},
title: {
text: '请选择',
size: 12,
h: 44,
bg: '#eee',
color: '#888',
},
fixedOn: api.frameName
}, function (ret, err) {
if (ret) {
if (ret.eventType == 'ok') {
callback(ret);
}
} else {
api.toast({
msg: '事件错误'
});
}
});
}
// 显示加载框
Vue.prototype.showProcess = function () {
api.showProgress({
title: '请稍候...',
text: '加载中...'
});
}
// 隐藏加载框
Vue.prototype.hideProcess = function () {
api.hideProgress();
}
// 获取用户信息
Vue.prototype.getUserInfo = function (callback) {
return;
var url = "getUserInfoUrl",
loginid = $api.getStorage('loginid'),
_this = this;
var data = {
loginId: loginid,
url: 'json',
type: 'body',
};
this.$post(url, data, function (ret) {
if (typeof callback != 'undefined' && callback != "undefined" && callback != "") {
callback(ret);
}
if (ret.retailerDto != null) {
// 将retariler_id和username保存起来
$api.setStorage('retailerid', ret.retailerDto.id);
$api.setStorage('storeName', ret.retailerDto.storeName);
}
});
}
// 获取购物车数量
Vue.prototype.getCarNum = function (id, callback) {
var data = {
retailer_id: id,
},
url = "shopCarListUrl",
_this = this;
this.$post(url, data, function (ret) {
if (ret.code == 0) {
_this.userInfo.carNum = ret.list.length;
callback(ret.list);
}
})
}
// 获取新版本,然后下载安装
Vue.prototype.getNewVersionUrl = function (c) {
var data = '',
_this = this;
if(api.systemType == 'ios'){
var url = "ioscheckVersionU"
}else{
var url = "checkVersionU"
}
this.$get(url, data, function(ret) {
if (ret.code == 0 || ret.code == '0') {
if (ret.version != _this.getVersion()) {
if (api.systemType == 'ios') {
api.alert({
title: '新版本提示',
msg: '检测到有新版本,请及时到APP Store 更新\n'+ret.plus_msg.replace(/\\n/g, "\n"),
buttons:'我知道了!'
}, function(ret, err) {
if(ret){
$api.clearStorage();
_this.goWin("login ", "login.html", "");
}
});
} else {
api.alert({
title: '新版本提示',
msg:ret.plus_msg.replace(/\\n/g, "\n"),
buttons:'立即更新'
}, function(res) {
if(res){
_this.downLoadApp(ret.url, c);
}
});
}
} else {
api.toast({
msg: '已是最新版本'
})
}
}
})
}
// 下载版本
Vue.prototype.downLoadApp = function (url, callback) {
var _this = this;
api.showProgress({
title: "更新提示",
text: "正在更新",
modal: true
});
// if (app.uav_type == 'IOS') {
// api.installApp({
// appUri : app.uav_filepath
// });
// } else {
api.download({
url: url,
savePath: '',
report: true,
cache: true,
allowResume: true
}, function (ret, err) {
// if (ret.state == 1) {
// api.hideProgress();
// api.installApp({
// appUri: ret.savePath
// });
// } else if (ret.state == 2) {
// callback('fail')
// }
if (ret && 0 == ret.state) { /* 下载进度 */
api.showProgress({
title: '正在下载...',
text: ret.percent + "%",
modal: true
});
}
if (ret && 1 == ret.state) { /* 下载完成 */
var savePath = ret.savePath;
api.installApp({
appUri: savePath
});
_this.showModal('温馨提示', '请安装程序,否则程序无法正常使用', ["", "确定"], function (res) {
if (res == 2) {
_this.getNewVersionUrl()
}
})
}
})
//}
}
// 获取
/******** ajax请求 ********/
Vue.prototype.$webIp = {
ip: new $http().ip
}
Vue.prototype.$post = function (url, data, callback, other) {
var http = new $http();
http.$post(url, data, function (ret) {
if (ret.code == 0 || ret.code == '0') {
callback(ret);
} else {
if (ret.records && ret.records.length > 0) {
callback({
code: 0,
data: ret
})
} else {
if (url == 'getLipeiInfoU') {
callback({
code: 500,
msg: ret.msg
})
} else {
api.toast({
msg: ret.msg
});
}
}
}
}, other)
}
Vue.prototype.$postuser = function (url, data, callback, other) {
var http = new $http();
http.$postuser(url, data, function (ret) {
callback(ret);
}, other)
}
Vue.prototype.$get = function (url, data, callback, other) {
var http = new $http();
http.$get(url, data, function (ret) {
if (ret.code == 0) {
callback(ret);
} else {
api.toast({
msg: ret.msg
});
}
}, other)
}
Vue.prototype.$getadd = function (url, data, callback, other) {
var http = new $http();
http.$getadd(url, data, function (ret) {
if (ret.code == 0) {
callback(ret);
} else {
api.toast({
msg: ret.msg
});
}
}, other)
}
Vue.prototype.$getOption = function (url, data, callback) {
var http = new $http();
http.$getOption(url, data, function (ret) {
if (ret.code == 0) {
callback(ret);
} else {
api.toast({
msg: ret.msg
});
}
})
}
Vue.prototype.$uploadfile = function (url, data, callback) {
var http = new $http();
http.uploadfile(url, data, function (ret) {
if (ret.code == 0 || ret.code == '0') {
callback(ret);
} else {
api.toast({
msg: ret.msg
});
}
})
}
// 选择图片
Vue.prototype.addPhoto = function (c) {
var _this = this;
// 判断是相机还是图片库
api.actionSheet({
title: '选择附件',
cancelTitle: '这里是取消按钮',
buttons: ['相机', '相册']
}, function (ret, err) {
if (ret.buttonIndex == 3) {
return;
}
var imageT = ['album', 'camera'][ret.buttonIndex];
_this.startChooseImage(imageT, c);
});
}
// Vue.prototype.startChooseImage = function(imageT, c) {
// api.getPicture({
// sourceType: imageT,
// encodingType: 'png',
// mediaValue: 'pic',
// destinationType: 'url',
// allowEdit: true,
// quality: 100,
// saveToPhotoAlbum: false
// }, function(ret, err) {
// alertJson(ret);
// if (ret) {
// if (ret.data != "") {
// // 有选择的相片了
// c(ret.data, ret.base64Data);
// }
// } else {
// alert(JSON.stringify(err));
// }
// });
// }
Vue.prototype.getNowTime = function (type) {
var myDate = new Date();
//获取系统当前时间
var YY = myDate.getFullYear();
// 获取年月日
var MM = myDate.getMonth() > 8 ? (myDate.getMonth() + 1) : ('0' + (myDate.getMonth() + 1));
var DD = myDate.getDate() > 9 ? myDate.getDate() : '0' + myDate.getDate();
var T = myDate.getHours() > 9 ? myDate.getHours() : '0' + myDate.getHours();
var M = myDate.getMinutes() > 9 ? myDate.getMinutes() : '0' + myDate.getMinutes();
var S = myDate.getSeconds() > 9 ? myDate.getSeconds() : '0' + myDate.getSeconds();
if (type == 'data') {
return YY + '-' + MM + '-' + DD;
} else {
return YY + ' - ' + MM + ' - ' + DD + ' ' + T + ':' + M + ':' + S;
}
}
// 选择时间
Vue.prototype.getTime = function (c) {
var date = this.getNowTime('date');
api.openPicker({
type: 'date',
date: date,
title: '请选择日期'
}, function (ret, err) {
if (ret) {
var ct = ret.year + '-' + (ret.month < 10 ? '0' + ret.month : ret.month) + '-' + (ret.day < 10 ? '0' + ret.day : ret.day);
c(ct);
}
});
}
// // 月份的最后一天
Vue.prototype.formatMonthLastDay = function (v) {
// 计算二月份的最后一天
var dateStr = v + "-1"; //需要获取此月最后一天的日期
var dateObj = new Date(dateStr);
var nextMonth = dateObj.getMonth() + 1; //0-11,下一个月
//设置当前日期为下个月的1号
dateObj.setMonth(nextMonth);
dateObj.setDate(1); //1-31
var nextMonthFirstDayTime = dateObj.getTime(); //下个月一号对应毫秒
var theMonthLastDayTime = nextMonthFirstDayTime - 24 * 60 * 60 * 1000; //下个月一号减去一天,正好是这个月最后一天
var theMonthDay = (new Date(theMonthLastDayTime)).getDate();
var val = theMonthDay;
return val;
}
// 配置上拉加载和下拉刷新
Vue.prototype.configDownAndPull = function (id, pullDown, down, useUp) {
var mescroll = new MeScroll(id, {
down: {
auto: false, //是否在初始化完毕之后自动执行下拉回调callback; 默认true
callback: function () {
pullDown(mescroll);
}, //下拉刷新的回调
},
up: {
use: useUp == false ? false : true, // 是否开启上拉加载
auto: false, //初始化完毕,是否自动触发上拉加载的回调
isBoth: true, //上拉加载时,如果滑动到列表顶部是否可以同时触发下拉刷新;默认false,两者不可同时触发; 这里为了演示改为true,不必等列表加载完毕才可下拉;
isBounce: false, //此处禁止ios回弹,解析(务必认真阅读,特别是最后一点): http://www.mescroll.com/qa.html#q10
htmlNodata: '',
callback: function () {
down(mescroll);
}, //上拉加载的回调
}
});
}
// 判断是否有权限
Vue.prototype.ifHasPrme = function (perm, c) {
var has = this.hasPermission(perm),
_this = this;
if (!has || !has[0] || !has[0].granted) {
api.confirm({
title: '温馨提示',
msg: '需要您同意才能获取到' + perm + " 权限\n是否同意前往设置?",
buttons: ['不同意', '同意']
}, function (ret, err) {
if (2 == ret.buttonIndex) {
_this.reqPermission(perm, function () {
c(true);
});
} else if (1 == ret.buttonIndex) {
c(false);
}
});
} else {
c(true);
}
}
Vue.prototype.hasPermission = function (perm) {
var perms = new Array();
perms.push(perm);
var rets = api.hasPermission({
list: perms
});
return rets;
}
Vue.prototype.reqPermission = function (perm, callback) {
var perms = new Array();
perms.push(perm);
api.requestPermission({
list: perms,
}, function (ret, err) {
if (ret && ret.list.length > 0) {
callback(ret);
}
});
}