初始化万家商超用户端仓库
This commit is contained in:
185
common/mixin/biological.js
Normal file
185
common/mixin/biological.js
Normal file
@ -0,0 +1,185 @@
|
||||
export default {
|
||||
name: 'verifyAgain',
|
||||
onShow() {
|
||||
console.log('开始二次验证', '用户token==>', this.$store.state.userInfo.user_token, '是否需要==>', this.$store.state.gestureAgain)
|
||||
// 获取当前页面的URL
|
||||
this.currentURL = this.$mp.page.route;
|
||||
// 只有再用户登录 且 需要二次验证 的情况下判断才有意义
|
||||
if (this.$store.state.userInfo.user_token && this.$store.state.gestureAgain) {
|
||||
console.log('开始判断设备...==>', uni.getSystemInfoSync().platform)
|
||||
if (uni.getSystemInfoSync().platform == "ios") {
|
||||
this.appleORan == 1;
|
||||
this.getingSupport(1);
|
||||
console.log('设备为ios')
|
||||
} else if (uni.getSystemInfoSync().platform === "android") {
|
||||
this.appleORan == 0;
|
||||
this.getingSupport(0);
|
||||
console.log('设备为安卓')
|
||||
} else {
|
||||
this.appleORan == 0;
|
||||
this.getingSupport(0);
|
||||
console.log('设备未知,默认为安卓')
|
||||
}
|
||||
}
|
||||
},
|
||||
destroyed() {
|
||||
// this.$store.commit('setGestureAgain',true);
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
appleORan: null, // 判断是苹果还是安卓(苹果:1;安卓:0;)
|
||||
currentURL: null, // 获取当前页面的URL
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 获取支持的生物监测
|
||||
getingSupport(type) {
|
||||
console.log('appleORan==3')
|
||||
let that = this;
|
||||
// #ifdef H5
|
||||
that.goingHandPassward();
|
||||
// #endif
|
||||
// #ifndef H5
|
||||
uni.checkIsSupportSoterAuthentication({
|
||||
success(res) {
|
||||
// console.log("获取支持的生物监测成功==>", res.supportMode.indexOf("facial") != -1,that.appleORan == 1);
|
||||
// 如果支持人脸识别,就优先人脸识别,否则就去指纹识别(人脸识别还需要判断是否是ios设备,如果不是,直接指纹。)
|
||||
if (res.supportMode.indexOf("facial") != -1 && type == 1) {
|
||||
console.log('进入人脸识别')
|
||||
that.examineFaceID();
|
||||
} else if (res.supportMode.indexOf("fingerPrint") != -1) {
|
||||
console.log('进入指纹识别')
|
||||
that.examineFingetprint();
|
||||
} else {
|
||||
that.goingHandPassward();
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
console.log("获取支持的生物监测失败==>", err);
|
||||
that.goingHandPassward();
|
||||
},
|
||||
});
|
||||
// #endif
|
||||
},
|
||||
// 手势密码入口
|
||||
goingHandPassward() {
|
||||
// 如果保存的有密码那就是解锁模式,如果没有那就是设置模式
|
||||
if (this.$store.state.userInfo.hand_password == '') {
|
||||
console.log('跳转到设置手势密码')
|
||||
uni.showToast({
|
||||
title: this.$t('请先设置你的密码'),
|
||||
duration: 500,
|
||||
icon: 'none'
|
||||
});
|
||||
this.$urouter.redirectTo({
|
||||
url: '/pages/index/setting/gesturePassword',
|
||||
params: {
|
||||
"type": 2,
|
||||
}
|
||||
})
|
||||
} else {
|
||||
console.log('跳转到手势密码')
|
||||
// 跳转到手势密码的页面时也到带上当前的页面路径
|
||||
this.$urouter.redirectTo({
|
||||
url: '/pages/index/setting/gesturePassword',
|
||||
params: {
|
||||
"type": 1,
|
||||
"currentURL": this.currentURL
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
// 检查是否录入指纹
|
||||
examineFingetprint() {
|
||||
let that = this;
|
||||
uni.checkIsSoterEnrolledInDevice({
|
||||
checkAuthMode: "fingerPrint",
|
||||
success(res) {
|
||||
console.log("检查是否录入指纹==>", res);
|
||||
// 如果没有录入指纹就跳转到设备的设置页面(不过应该用不到)
|
||||
if (res.isEnrolled) {
|
||||
that.startFingerprint();
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
console.log(err);
|
||||
},
|
||||
});
|
||||
},
|
||||
// 检查是否录入faceID
|
||||
examineFaceID() {
|
||||
let that = this;
|
||||
uni.checkIsSoterEnrolledInDevice({
|
||||
checkAuthMode: "facial",
|
||||
success(res) {
|
||||
console.log("检查是否录入faceID", res);
|
||||
// 检查是否录入人脸
|
||||
if (res.isEnrolled) {
|
||||
that.startFaceID();
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
console.log(err);
|
||||
},
|
||||
});
|
||||
},
|
||||
// 开始指纹识别
|
||||
startFingerprint() {
|
||||
let that = this;
|
||||
uni.startSoterAuthentication({
|
||||
requestAuthModes: ["fingerPrint"],
|
||||
challenge: this.$t("要携带的参数"),
|
||||
authContent: this.$t("请用指纹解锁"),
|
||||
success(res) {
|
||||
that.$store.commit('setGestureAgain', false);
|
||||
console.log("指纹识别成功==>", res);
|
||||
// 如果识别成功就
|
||||
uni.showToast({
|
||||
title: this.$t("识别成功"),
|
||||
duration: 500,
|
||||
});
|
||||
},
|
||||
fail(err) {
|
||||
console.log(err);
|
||||
uni.showToast({
|
||||
title: this.$t('验证失败'),
|
||||
duration: 1000,
|
||||
icon: 'none'
|
||||
});
|
||||
setTimeout(() => {
|
||||
that.$urouter.navigateBack()
|
||||
}, 1000)
|
||||
},
|
||||
});
|
||||
},
|
||||
// 开始人脸识别
|
||||
startFaceID() {
|
||||
let that = this;
|
||||
uni.startSoterAuthentication({
|
||||
requestAuthModes: ["facial"],
|
||||
challenge: this.$t("要携带的参数"),
|
||||
authContent: this.$t("请用FaceID解锁"),
|
||||
success(res) {
|
||||
console.log("人脸识别成功==>", res);
|
||||
that.$store.commit('setGestureAgain', false);
|
||||
// 如果识别成功就
|
||||
uni.showToast({
|
||||
title: this.$t("识别成功"),
|
||||
duration: 500,
|
||||
});
|
||||
},
|
||||
fail(err) {
|
||||
console.log(err);
|
||||
uni.showToast({
|
||||
title: this.$t('验证失败'),
|
||||
duration: 1000,
|
||||
icon: 'none'
|
||||
});
|
||||
setTimeout(() => {
|
||||
that.$urouter.navigateBack()
|
||||
}, 1000)
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
183
common/mixin/calendar.js
Normal file
183
common/mixin/calendar.js
Normal file
@ -0,0 +1,183 @@
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
calendar: [], //日历数组
|
||||
currentDate: [], //当前日期
|
||||
time:'',//选中日期
|
||||
start_time:'',//开始日期
|
||||
end_time:'',//结束日期
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
let currentDate = this.currentime();
|
||||
this.currentDate = currentDate;
|
||||
let currentYear = currentDate[0];
|
||||
let currentMonth = currentDate[1] > 9 ? currentDate[1] : '0'+currentDate[1];
|
||||
let currentDay = currentDate[2] > 9 ? currentDate[2] : '0'+currentDate[2];
|
||||
// 足迹01页面日期筛选默认值
|
||||
this.time = `${currentYear}-${currentMonth}-${currentDay}`;
|
||||
|
||||
// 足迹02页面日期筛选赋值 默认三个月
|
||||
// 开始时间
|
||||
if(currentDate[1] > 4){
|
||||
let prevMonth = currentDate[1]-3 > 9 ? currentDate[1]-3 : '0'+(currentDate[1]-3) ;
|
||||
let prevDay = currentDate[2] > 9 ? currentDate[2] : '0'+currentDate[2];
|
||||
this.start_time = `${currentDate[0]}-${prevMonth}-${prevDay}`;
|
||||
}else{
|
||||
let prevYear = currentDate[0]-1;
|
||||
let prevMonth = currentDate[1]-3 + 12 > 9 ? currentDate[1]-3 + 12 : '0'+(currentDate[1]-3 + 12) ;
|
||||
let prevDay = currentDate[2] > 9 ? currentDate[2] : '0'+currentDate[2];
|
||||
this.start_time = `${prevYear}-${prevMonth}-${prevDay}`;
|
||||
}
|
||||
// 结束时间
|
||||
this.end_time = `${currentYear}-${currentMonth}-${currentDay}`;
|
||||
// 日历赋值
|
||||
this.calendar = this.getCalendar(currentDate[0], currentDate[1]);
|
||||
|
||||
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* @description 获取当前时间函数
|
||||
*/
|
||||
currentime() {
|
||||
var date = new Date();
|
||||
var y = Number(date.getFullYear());
|
||||
var m = Number(date.getMonth() + 1);
|
||||
var d = Number(date.getDate());
|
||||
return [y, m, d];
|
||||
},
|
||||
/**
|
||||
* @author 邓东方
|
||||
* @description 获取日历
|
||||
* @param {String,Number} y 年
|
||||
* @param {String,Number} m 月
|
||||
* @param {String,Number} currentDay 当前日 传入了显示 当前日 active == true
|
||||
*/
|
||||
getCalendar(y, m) {
|
||||
// 求解cy年cm月cd日是星期几,parseInt代表取整 d=1是去每个月第一天
|
||||
var cc = parseInt(y / 100); //c
|
||||
var cy = y - cc * 100; //y
|
||||
var cm = m; //m
|
||||
var cd = 1; //d
|
||||
// 某年的1、2月要看作上一年的13、14月来计算,比如2003年1月1日要看作2002年的13月1日来计算
|
||||
if (m == 1 || m == 2) {
|
||||
cc = parseInt((y - 1) / 100);
|
||||
cy = y - 1 - cc * 100;
|
||||
cm = 12 + m;
|
||||
}
|
||||
//w=y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1
|
||||
// var csum = y + [y / 4] + [c / 4] - 2c+[26(m + 1)/10]+d-1;
|
||||
var csum = cy + parseInt(cy / 4) + parseInt(cc / 4) - 2 * cc + parseInt(26 * (cm + 1) / 10) + cd - 1;
|
||||
// 注意使用蔡勒公式时出现负数情况 fd 每月第一天星期几
|
||||
if (csum < 0) {
|
||||
var fd = parseInt((csum % 7 + 7) % 7);
|
||||
} else {
|
||||
var fd = parseInt(csum % 7);
|
||||
}
|
||||
|
||||
// 上个月天数
|
||||
var cond1 = y % 4 == 0; //条件1:年份必须要能被4整除
|
||||
var cond2 = y % 100 != 0; //条件2:年份不能是整百数
|
||||
var cond3 = y % 400 == 0; //条件3:年份是400的倍数
|
||||
//当条件1和条件2同时成立时,就肯定是闰年,所以条件1和条件2之间为“与”的关系。
|
||||
//如果条件1和条件2不能同时成立,但如果条件3能成立,则仍然是闰年。所以条件3与前2项为“或”的关系。
|
||||
//所以得出判断闰年的表达式:
|
||||
var cond = cond1 && cond2 || cond3;
|
||||
//判断当月有多少天
|
||||
var allDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][m - 1];
|
||||
if (cond && m == 2) {
|
||||
allDays = 29;
|
||||
}
|
||||
//上个月是不是去年
|
||||
let prevYear = y;
|
||||
let prevMonth = m - 1;
|
||||
if (m == 1) {
|
||||
prevYear = y - 1;
|
||||
prevMonth = 12;
|
||||
}
|
||||
let _prevMonth = prevMonth>9?prevMonth:'0'+prevMonth;
|
||||
let _m = m>9?m:'0'+m;
|
||||
//判断上个月天数
|
||||
var prevDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][prevMonth - 1];
|
||||
var arr = [];
|
||||
//这里塞入上个月末尾日期
|
||||
//day 日 active 是否选择 isNot 是不是这个月 formData 日期格式 isBg 是否加背景色(日期段筛选时使用)
|
||||
for (let i = 1; i <= fd; i++) {
|
||||
let prevDay = prevDays - fd + i;
|
||||
let _prevDay = prevDay>9?prevDay:'0'+prevDay;
|
||||
|
||||
arr.push({
|
||||
'day': prevDay,
|
||||
'active': false,
|
||||
'isNot': true,
|
||||
'formData': prevYear + '-' + _prevMonth + '-' + _prevDay
|
||||
})
|
||||
}
|
||||
//这里塞入正常这个月的日期
|
||||
for (let i = 1; i <= allDays; i++) {
|
||||
let _i = i>9?i:'0'+i;
|
||||
arr.push({
|
||||
'day': i,
|
||||
'active': false,
|
||||
'isNot': false,
|
||||
'formData': y + '-' + _m + '-' + _i
|
||||
})
|
||||
}
|
||||
//下个月是不是下一年
|
||||
let nextYear = y;
|
||||
let nextMonth = m + 1;
|
||||
if (m == 12) {
|
||||
nextYear = y + 1;
|
||||
nextMonth = 1;
|
||||
}
|
||||
let _nextMonth = nextMonth>9?nextMonth:'0'+nextMonth;
|
||||
//判断数组最后一排剩余几个位置塞入下个月日期
|
||||
let takedie = arr.length % 7;
|
||||
if (7 - takedie > 0 && 7 - takedie < 7) {
|
||||
for (let i = 1; i <= 7 - takedie; i++) {
|
||||
let _i = i>9?i:'0'+i;
|
||||
arr.push({
|
||||
'day': i,
|
||||
'active': false,
|
||||
'isNot': true,
|
||||
'formData': nextYear + '-' + _nextMonth + '-' + _i
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 处理数组钩子
|
||||
if(this.handleCalendarFn){
|
||||
arr = this.handleCalendarFn(arr);
|
||||
}
|
||||
|
||||
return arr;
|
||||
},
|
||||
/**
|
||||
* @description 上月
|
||||
*/
|
||||
prevMonth() {
|
||||
let currentDate = this.currentDate;
|
||||
if (currentDate[1] - 1 == 0) {
|
||||
currentDate = [currentDate[0] - 1, 12];
|
||||
} else {
|
||||
currentDate = [currentDate[0], currentDate[1] - 1];
|
||||
}
|
||||
this.currentDate = currentDate;
|
||||
this.calendar = this.getCalendar(currentDate[0], currentDate[1]);
|
||||
},
|
||||
/**
|
||||
* @description 下月
|
||||
*/
|
||||
nextMonth() {
|
||||
let currentDate = this.currentDate;
|
||||
if (currentDate[1] == 12) {
|
||||
currentDate = [Number(currentDate[0]) + 1, 1];
|
||||
} else {
|
||||
currentDate = [Number(currentDate[0]), Number(currentDate[1]) + 1];
|
||||
}
|
||||
this.currentDate = currentDate;
|
||||
this.calendar = this.getCalendar(currentDate[0], currentDate[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
49
common/mixin/floor.js
Normal file
49
common/mixin/floor.js
Normal file
@ -0,0 +1,49 @@
|
||||
export default {
|
||||
data(){
|
||||
return {
|
||||
scrollInfo:[], // 页码滚动初始化
|
||||
scrollSize:1, // 滚动页码位置判断
|
||||
}
|
||||
},
|
||||
// 监听滚动传值
|
||||
onPageScroll(res) {
|
||||
let _this = this
|
||||
_this.type = 1
|
||||
this.$emit('gunShowPage', res)
|
||||
// console.log('页面正在滚动',res.scrollTop)
|
||||
var pageIndex =null ;
|
||||
// scrollSize 所处的高度在哪个哪个页码的下标下
|
||||
// currentPage 当前页码
|
||||
// 下滑页码改变时 记录页码增加时的高度,上拉页码改变时
|
||||
if(this.currentPage > this.scrollSize){
|
||||
this.scrollSize = this.currentPage
|
||||
this.scrollInfo.push(res.scrollTop)
|
||||
// console.log(this.scrollInfo)
|
||||
}else if(this.currentPage < this.scrollSize){
|
||||
this.scrollSize = this.currentPage
|
||||
console.log(this.scrollInfo)
|
||||
}
|
||||
// 判断滚动条有历史记录的情况下 返回
|
||||
if(this.scrollInfo[this.scrollSize-2] >res.scrollTop){
|
||||
this.currentPage--
|
||||
this.scrollSize = this.currentPage
|
||||
}
|
||||
// 判断滚动条在有历史记录的情况下 下滑
|
||||
if(this.scrollInfo[this.currentPage-1] < res.scrollTop ){
|
||||
this.currentPage++
|
||||
this.scrollSize = this.currentPage
|
||||
}
|
||||
clearTimeout(this.timer)
|
||||
this.timer = setTimeout(function () {
|
||||
console.log('悬浮按钮状态切换', this.timer)
|
||||
_this.type = 2
|
||||
}, 800)
|
||||
// console.log(this.model)
|
||||
if (res.scrollTop > 50) {
|
||||
this.isShow = true
|
||||
} else {
|
||||
this.isShow = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
294
common/mixin/index.js
Normal file
294
common/mixin/index.js
Normal file
@ -0,0 +1,294 @@
|
||||
import Vue from 'vue';
|
||||
import { Router } from '@/common/utils/index.js';
|
||||
import { needLoginPages, STATIC_URL, HOME_PAGE_URL, LOGIN_PAGE_URL, ACCEPT_PLATFORM, SYSTEM_CONFIG } from '@/common/config.js';
|
||||
const router = new Router({ needLoginPages });
|
||||
Vue.mixin({
|
||||
data() { return { STATIC_URL: STATIC_URL, isPublish: false } },
|
||||
computed: {
|
||||
i18n() {
|
||||
return this.$t('defVal');
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
// #ifdef APP-PLUS
|
||||
toJSON() { },
|
||||
// #endif
|
||||
|
||||
getPublishStatus() {
|
||||
this.$api.post(global.apiUrls.post673572b0bebd7, {app_version: SYSTEM_CONFIG.appVersion, type: ACCEPT_PLATFORM == 'IOS' ? 'ios' : 'android'}) .then(res => {
|
||||
if (res.data.code == 1) {
|
||||
this.isPublish = !res.data.data.is_listing;
|
||||
}
|
||||
})
|
||||
},
|
||||
// 页面抛出事件
|
||||
benbenThrowPageEvent(event, data) {
|
||||
uni.$emit(event, data)
|
||||
},
|
||||
//修改uniapi为promise类型
|
||||
syncUniApi(apiName, params) {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni[apiName]({
|
||||
...params,
|
||||
success: (res) => {
|
||||
resolve(res)
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err)
|
||||
},
|
||||
});
|
||||
})
|
||||
},
|
||||
// 跳转首页
|
||||
toHomeDiy() {
|
||||
router.switchTab(HOME_PAGE_URL[global.appTabBarType]);
|
||||
},
|
||||
// 跳转登录页
|
||||
toLoginDiy() {
|
||||
router.navigateTo(LOGIN_PAGE_URL);
|
||||
},
|
||||
//微信支付
|
||||
requestPaymentWx(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.requestPayment({
|
||||
provider: 'wxpay',
|
||||
// #ifdef MP-WEIXIN
|
||||
timeStamp: data.timeStamp,
|
||||
nonceStr: data.nonceStr,
|
||||
package: data.package,
|
||||
signType: data.signType,
|
||||
paySign: data.paySign,
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
orderInfo: data,
|
||||
// #endif
|
||||
success: (e) => {
|
||||
console.log('success', e)
|
||||
if (e.errMsg == 'requestPayment:ok') {
|
||||
resolve()
|
||||
}
|
||||
},
|
||||
fail: (e) => {
|
||||
// #ifdef APP-PLUS
|
||||
let failMsg = 'requestPayment:fail canceled';
|
||||
// #endif
|
||||
// #ifndef APP-PLUS
|
||||
let failMsg = 'requestPayment:fail cancel';
|
||||
// #endif
|
||||
if (e.errMsg == failMsg) {
|
||||
this.$message.info(this.$t('取消支付'));
|
||||
} else {
|
||||
this.$message.info(this.$t("支付失败,请稍后重试"));
|
||||
}
|
||||
reject(e)
|
||||
},
|
||||
complete: () => {
|
||||
}
|
||||
});
|
||||
})
|
||||
},
|
||||
// 支付宝支付
|
||||
requestPaymentAli(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.requestPayment({
|
||||
provider: 'alipay',
|
||||
orderInfo: data,
|
||||
success: (e) => {
|
||||
if (e.errMsg == 'requestPayment:ok') {
|
||||
resolve()
|
||||
}
|
||||
},
|
||||
fail: (e) => {
|
||||
if (e.errMsg == 'requestPayment:fail canceled') {
|
||||
this.$message.info(this.$t('取消支付'));
|
||||
} else {
|
||||
this.$message.info(this.$t("支付失败,请稍后重试"));
|
||||
}
|
||||
reject(e)
|
||||
},
|
||||
complete: () => {
|
||||
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
// diy点击事件处理函数
|
||||
handleEven(e, params) {
|
||||
let dataset = e.currentTarget && e.currentTarget.dataset;
|
||||
let type, data;
|
||||
if (dataset) {
|
||||
type = dataset.event_type
|
||||
data = dataset.event_params
|
||||
} else {
|
||||
type = e
|
||||
data = params
|
||||
}
|
||||
console.log('点击事件触发', dataset, type, data);
|
||||
this.$util.handleAllFn(type, data);
|
||||
},
|
||||
// 设置自定义头部
|
||||
setNavigationBarTitle(title) {
|
||||
uni.setNavigationBarTitle({
|
||||
title: title
|
||||
})
|
||||
},
|
||||
// 点击复制
|
||||
copyText(data) {
|
||||
uni.setClipboardData({
|
||||
data: data,
|
||||
success: () => {
|
||||
this.$message.success('复制成功')
|
||||
}
|
||||
});
|
||||
},
|
||||
// 点击打电话
|
||||
callMobile(phoneNumber) {
|
||||
let STORE_PERMISSION = uni.getStorageSync('PLATFORM_PERMISSION_PHONE') || false;
|
||||
if (!STORE_PERMISSION && ACCEPT_PLATFORM == 'Android') {
|
||||
this.$util.showModal({
|
||||
title: '提示',
|
||||
content: '萬家商超访问电话权限及功能用于联系平台,是否允许?',
|
||||
confirmColor: "#FF2020",
|
||||
// confirmText: this.i18n['允许'],
|
||||
// cancelText:this.i18n["取消"],
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
uni.setStorageSync('PLATFORM_PERMISSION_PHONE', true)
|
||||
this.$util.showModal({
|
||||
title: '拨打电话给', content: phoneNumber + '', confirmText: '拨打', success: res => {
|
||||
if (res.confirm) {
|
||||
uni.makePhoneCall({
|
||||
phoneNumber: phoneNumber,
|
||||
|
||||
});
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
},
|
||||
});
|
||||
return false;
|
||||
}
|
||||
this.$util.showModal({
|
||||
title: '拨打电话给', content: phoneNumber + '', confirmText: '拨打', success: res => {
|
||||
if (res.confirm) {
|
||||
uni.makePhoneCall({
|
||||
phoneNumber: phoneNumber,
|
||||
|
||||
});
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
// 判断是否多值是否成立
|
||||
in_array(type, str) {
|
||||
let arr = []
|
||||
// str 是否为字符串
|
||||
if (typeof str === 'string') arr = str.split(',')
|
||||
// str 是否为数组
|
||||
if (typeof str === 'object') arr = str
|
||||
let index = -1
|
||||
index = arr.findIndex(item => type == item)
|
||||
console.log('index-------------', index);
|
||||
if (index == -1) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
|
||||
// 设置自定义底部
|
||||
setTabBarItem() {
|
||||
// uni.setTabBarItem({
|
||||
// index: 0,
|
||||
// text: global.i18n.t('首页'),
|
||||
// })
|
||||
// uni.setTabBarItem({
|
||||
// index: 1,
|
||||
// text: global.i18n.t('分类'),
|
||||
// })
|
||||
// uni.setTabBarItem({
|
||||
// index: 2,
|
||||
// text: global.i18n.t('购物车'),
|
||||
// })
|
||||
// uni.setTabBarItem({
|
||||
// index: 3,
|
||||
// text: global.i18n.t('我的'),
|
||||
// })
|
||||
},
|
||||
// 页面跳转
|
||||
handleJump(e) {
|
||||
let target = e.currentTarget || e.target,
|
||||
url = target.dataset.url || 'back',
|
||||
type = target.dataset.type;
|
||||
if (url == '' || url == '#') return;
|
||||
switch (type) {
|
||||
case 'SWITCH':
|
||||
router.switchTab(url);
|
||||
break;
|
||||
case 'REDIRECT':
|
||||
router.redirectTo(url);
|
||||
break;
|
||||
case 'RELAUNCH':
|
||||
router.reLaunch(url);
|
||||
break;
|
||||
case 'BACK':
|
||||
router.navigateBack();
|
||||
break;
|
||||
default:
|
||||
router.navigateTo(url);
|
||||
break;
|
||||
}
|
||||
},
|
||||
// Diy页面跳转
|
||||
handleJumpDiy(e) {
|
||||
let target = e.currentTarget || e.target,
|
||||
url = target.dataset.url || 'back',
|
||||
type = target.dataset.type;
|
||||
if (url == '' || url == '#') return;
|
||||
switch (type) {
|
||||
case 'switchTab':
|
||||
router.switchTab(url);
|
||||
break;
|
||||
case 'redirectTo':
|
||||
router.redirectTo(url);
|
||||
break;
|
||||
case 'reLaunch':
|
||||
router.reLaunch(url);
|
||||
break;
|
||||
case 'navigateTo':
|
||||
router.navigateTo(url);
|
||||
break;
|
||||
case 'back':
|
||||
router.navigateBack(+url);
|
||||
break;
|
||||
default:
|
||||
router.navigateTo(url);
|
||||
break;
|
||||
}
|
||||
},
|
||||
mixinToPlayVideo(src) {
|
||||
let parm = encodeURIComponent(src)
|
||||
router.navigateTo(`/pages/benben-built-in/playVideo/playVideo?src=${parm}`)
|
||||
},
|
||||
singleImagePreview(url) {
|
||||
uni.previewImage({
|
||||
current: url,
|
||||
urls: [url]
|
||||
});
|
||||
},
|
||||
multiImagePreview(url, images, field) {
|
||||
let arr = []
|
||||
if (field) {
|
||||
images.map((item) => {
|
||||
arr.push(item[field])
|
||||
})
|
||||
} else {
|
||||
arr = images
|
||||
}
|
||||
uni.previewImage({
|
||||
current: url,
|
||||
urls: arr
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
98
common/mixin/paging_list.js
Normal file
98
common/mixin/paging_list.js
Normal file
@ -0,0 +1,98 @@
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
allowOnloadGetList: true, // 是否允许页面onload生命周期进入后立马执行getlist
|
||||
minixPagingListsApi: '', // 接口地址
|
||||
pageingListApiMethod: 'post', // 接口请求方法
|
||||
pagingListPage: 1, // 分页
|
||||
pagingListAllowLoadMore: true, // 允许加载更多
|
||||
pagingListLoadedAll: false, // 已加载全部数据
|
||||
pagingListNoListData: false, // 没有列表数据,
|
||||
isOrder: false, // 订单页面
|
||||
listData: [],
|
||||
isLoadInit: false, // 初始化数据之后,若无数据再显示无数据图标
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
listDataLength() {
|
||||
return this.listData.length
|
||||
}
|
||||
},
|
||||
|
||||
// 下拉刷新
|
||||
onPullDownRefresh() {
|
||||
uni.stopPullDownRefresh();
|
||||
if (this.allowOnloadGetList) {
|
||||
this.pagingListToggle(() => {
|
||||
// uni.stopPullDownRefresh();
|
||||
});
|
||||
} else {
|
||||
// uni.stopPullDownRefresh();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
onLoad() {
|
||||
if (this.allowOnloadGetList) this.pagingListGetLists();
|
||||
},
|
||||
|
||||
//上拉加载更多
|
||||
onReachBottom() {
|
||||
this.pagingListGetLists();
|
||||
},
|
||||
|
||||
methods: {
|
||||
// 列表切换
|
||||
pagingListToggle(fn) {
|
||||
this.pagingListPage = 1
|
||||
this.pagingListAllowLoadMore = true
|
||||
this.pagingListLoadedAll = false
|
||||
this.pagingListNoListData = false
|
||||
this.listData.splice(0, this.listData.length)
|
||||
// this.listData = []
|
||||
if (fn) this.pagingListGetLists(fn);
|
||||
else this.pagingListGetLists();
|
||||
},
|
||||
// 获取列表数据
|
||||
pagingListGetLists(fn) {
|
||||
console.log(this.pagingListLoadedAll)
|
||||
if (!this.pagingListAllowLoadMore || this.pagingListLoadedAll || this.pagingListNoListData) return;
|
||||
this.pagingListAllowLoadMore = false;
|
||||
let postData = {
|
||||
page: this.pagingListPage,
|
||||
pagesize: global.PAGE_SIZE,
|
||||
list_rows: global.PAGE_SIZE
|
||||
}
|
||||
if (this.pagingListPostData) {
|
||||
postData = Object.assign({}, postData, this.pagingListPostData());
|
||||
}
|
||||
this.isShowLoading = true
|
||||
this.$api[this.pageingListApiMethod](this.minixPagingListsApi, postData).then(res => {
|
||||
this.isShowLoading = false
|
||||
if (res.data.code == 1) {
|
||||
if (this.pagingListBeforeResponseData) res.data.data = this.pagingListBeforeResponseData(res);
|
||||
let tempLists = res.data.data.data || res.data.data.list,
|
||||
totalPage = res.data.data.last_page || 1
|
||||
if (this.pagingListResponseData) tempLists = this.pagingListResponseData(tempLists);
|
||||
this.listData.push(...tempLists);
|
||||
this.pagingListAllowLoadMore = true;
|
||||
if (this.pagingListPage >= totalPage) this.pagingListLoadedAll = true;
|
||||
if (this.pagingListPage == 1 && this.listData.length == 0) this.pagingListNoListData = true;
|
||||
this.pagingListPage = this.pagingListPage + 1;
|
||||
} else {
|
||||
this.pagingListAllowLoadMore = true;
|
||||
this.pagingListLoadedAll = true;
|
||||
if (this.pagingListPage == 1 && this.listData.length == 0) this.pagingListNoListData = true;
|
||||
}
|
||||
this.isLoadInit = true;
|
||||
if (fn) fn();
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
this.isShowLoading = false
|
||||
this.pagingListAllowLoadMore = true;
|
||||
this.isLoadInit = true;
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user