|
@@ -1,118 +1,117 @@
|
|
|
// 不含icon提示框
|
|
|
export const toast = str => {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- if(str.length < 20) {
|
|
|
- uni.showToast({
|
|
|
- title: str,
|
|
|
- icon: "none",
|
|
|
- duration: 1500,
|
|
|
- success: () => {
|
|
|
- setTimeout(() => {
|
|
|
- resolve
|
|
|
- }, 1500)
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- else {
|
|
|
- uni.showModal({
|
|
|
- title: "提示",
|
|
|
- content: String(str),
|
|
|
- showCancel: false,
|
|
|
- confirmText: "我知道了",
|
|
|
- success(res) {
|
|
|
- if (res.confirm) {
|
|
|
- resolve(res);
|
|
|
- } else {
|
|
|
- reject();
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- })
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ if (str.length < 20) {
|
|
|
+ uni.showToast({
|
|
|
+ title: str,
|
|
|
+ icon: "none",
|
|
|
+ duration: 1500,
|
|
|
+ success: () => {
|
|
|
+ setTimeout(() => {
|
|
|
+ resolve
|
|
|
+ }, 1500)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ uni.showModal({
|
|
|
+ title: "提示",
|
|
|
+ content: String(str),
|
|
|
+ showCancel: false,
|
|
|
+ confirmText: "我知道了",
|
|
|
+ success(res) {
|
|
|
+ if (res.confirm) {
|
|
|
+ resolve(res);
|
|
|
+ } else {
|
|
|
+ reject();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ })
|
|
|
};
|
|
|
|
|
|
// 成功提示框
|
|
|
export const successToast = (str) => {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- uni.showToast({
|
|
|
- title: str || '请求成功',
|
|
|
- icon: 'success',
|
|
|
- duration: 1500,
|
|
|
- success: () => {
|
|
|
- setTimeout(() => {
|
|
|
- resolve();
|
|
|
- }, 1500);
|
|
|
- },
|
|
|
- });
|
|
|
- });
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ uni.showToast({
|
|
|
+ title: str || '请求成功',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1500,
|
|
|
+ success: () => {
|
|
|
+ setTimeout(() => {
|
|
|
+ resolve();
|
|
|
+ }, 1500);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
// loading
|
|
|
export const showLoading = () => {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- uni.showLoading({
|
|
|
- success: () => {
|
|
|
- resolve();
|
|
|
- },
|
|
|
- });
|
|
|
- });
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ uni.showLoading({
|
|
|
+ success: () => {
|
|
|
+ resolve();
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
// 提示loading
|
|
|
export const tipLoading = (str) => {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- uni.showLoading({
|
|
|
- title: str,
|
|
|
- success: () => {
|
|
|
- resolve();
|
|
|
- },
|
|
|
- });
|
|
|
- });
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ uni.showLoading({
|
|
|
+ title: str,
|
|
|
+ success: () => {
|
|
|
+ resolve();
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
// 隐藏loading
|
|
|
export const hideLoading = () => {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- uni.hideLoading({
|
|
|
- success: () => {
|
|
|
- resolve();
|
|
|
- },
|
|
|
- });
|
|
|
- });
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ uni.hideLoading({
|
|
|
+ success: () => {
|
|
|
+ resolve();
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
// 模态弹窗
|
|
|
export const modal = (options = {}) => {
|
|
|
- if (!options) return;
|
|
|
- const {
|
|
|
- title,
|
|
|
- content,
|
|
|
- showCancel,
|
|
|
- cancelText,
|
|
|
- cancelColor,
|
|
|
- confirmText,
|
|
|
- confirmColor,
|
|
|
- } = Object.assign({}, options.content ? options : {
|
|
|
- content: options
|
|
|
- });
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- uni.showModal({
|
|
|
- title: title || '提示',
|
|
|
- content: String(content),
|
|
|
- showCancel: typeof showCancel == 'boolean' ? showCancel : true,
|
|
|
- cancelText: cancelText || '取消',
|
|
|
- cancelColor: cancelColor || '#323233',
|
|
|
- confirmText: confirmText || '确定',
|
|
|
- confirmColor: confirmColor || '#3D8FFD',
|
|
|
- complete(res) {
|
|
|
- if (res.confirm) {
|
|
|
- resolve(res);
|
|
|
- } else {
|
|
|
- reject();
|
|
|
- }
|
|
|
- },
|
|
|
- });
|
|
|
- });
|
|
|
+ if (!options) return;
|
|
|
+ const {
|
|
|
+ title,
|
|
|
+ content,
|
|
|
+ showCancel,
|
|
|
+ cancelText,
|
|
|
+ cancelColor,
|
|
|
+ confirmText,
|
|
|
+ confirmColor,
|
|
|
+ } = Object.assign({}, options.content ? options : {
|
|
|
+ content: options
|
|
|
+ });
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ uni.showModal({
|
|
|
+ title: title || '提示',
|
|
|
+ content: String(content),
|
|
|
+ showCancel: typeof showCancel == 'boolean' ? showCancel : true,
|
|
|
+ cancelText: cancelText || '取消',
|
|
|
+ cancelColor: cancelColor || '#323233',
|
|
|
+ confirmText: confirmText || '确定',
|
|
|
+ confirmColor: confirmColor || '#3D8FFD',
|
|
|
+ complete(res) {
|
|
|
+ if (res.confirm) {
|
|
|
+ resolve(res);
|
|
|
+ } else {
|
|
|
+ reject();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
/**
|
|
@@ -123,18 +122,18 @@ export const modal = (options = {}) => {
|
|
|
* @returns
|
|
|
*/
|
|
|
export const navPage = (url, isAuth = 0) => {
|
|
|
- if ((isAuth && store.state.isLogin) || !isAuth) {
|
|
|
- uni.navigateTo({
|
|
|
- url,
|
|
|
- fail: (err) => {
|
|
|
- console.log('页面跳转失败', url, err);
|
|
|
- },
|
|
|
- });
|
|
|
- } else {
|
|
|
- uni.navigateTo({
|
|
|
- url: '/pages/login/index',
|
|
|
- });
|
|
|
- }
|
|
|
+ if ((isAuth && store.state.isLogin) || !isAuth) {
|
|
|
+ uni.navigateTo({
|
|
|
+ url,
|
|
|
+ fail: (err) => {
|
|
|
+ console.log('页面跳转失败', url, err);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ uni.navigateTo({
|
|
|
+ url: '/pages/login/index',
|
|
|
+ });
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
/**
|
|
@@ -145,18 +144,18 @@ export const navPage = (url, isAuth = 0) => {
|
|
|
* @returns
|
|
|
*/
|
|
|
export const redPage = (url, isAuth = 0) => {
|
|
|
- if ((isAuth && store.state.isLogin) || !isAuth) {
|
|
|
- uni.redirectTo({
|
|
|
- url,
|
|
|
- fail: (err) => {
|
|
|
- console.log('页面跳转失败', url, err);
|
|
|
- },
|
|
|
- });
|
|
|
- } else {
|
|
|
- uni.navigateTo({
|
|
|
- url: '/pages/login/index',
|
|
|
- });
|
|
|
- }
|
|
|
+ if ((isAuth && store.state.isLogin) || !isAuth) {
|
|
|
+ uni.redirectTo({
|
|
|
+ url,
|
|
|
+ fail: (err) => {
|
|
|
+ console.log('页面跳转失败', url, err);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ uni.navigateTo({
|
|
|
+ url: '/pages/login/index',
|
|
|
+ });
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
/**
|
|
@@ -166,12 +165,12 @@ export const redPage = (url, isAuth = 0) => {
|
|
|
* @returns
|
|
|
*/
|
|
|
export const backPage = (num = 1, time = 0) => {
|
|
|
- if (!num) return false;
|
|
|
- setTimeout(() => {
|
|
|
- uni.navigateBack({
|
|
|
- delta: num,
|
|
|
- });
|
|
|
- }, time);
|
|
|
+ if (!num) return false;
|
|
|
+ setTimeout(() => {
|
|
|
+ uni.navigateBack({
|
|
|
+ delta: num,
|
|
|
+ });
|
|
|
+ }, time);
|
|
|
};
|
|
|
|
|
|
/**
|
|
@@ -180,19 +179,19 @@ export const backPage = (num = 1, time = 0) => {
|
|
|
* @param {String} orderId 服务单id,如果需要请求记录接口
|
|
|
*/
|
|
|
export const callPhone = (phone) => {
|
|
|
- if (!phone)
|
|
|
- return modal({
|
|
|
- content: '手机号码不存在',
|
|
|
- showCancel: false,
|
|
|
- })
|
|
|
- .then(() => {})
|
|
|
- .catch(() => {});
|
|
|
- uni.makePhoneCall({
|
|
|
- phoneNumber: phone,
|
|
|
- success: () => {
|
|
|
- // logCallPhone(orderId);
|
|
|
- },
|
|
|
- });
|
|
|
+ if (!phone)
|
|
|
+ return modal({
|
|
|
+ content: '手机号码不存在',
|
|
|
+ showCancel: false,
|
|
|
+ })
|
|
|
+ .then(() => {})
|
|
|
+ .catch(() => {});
|
|
|
+ uni.makePhoneCall({
|
|
|
+ phoneNumber: phone,
|
|
|
+ success: () => {
|
|
|
+ // logCallPhone(orderId);
|
|
|
+ },
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
/**
|
|
@@ -200,53 +199,57 @@ export const callPhone = (phone) => {
|
|
|
* @param {String} val 复制内容
|
|
|
*/
|
|
|
export const copy = (val) => {
|
|
|
- uni.setClipboardData({
|
|
|
- data: val,
|
|
|
- success: () => {
|
|
|
- successToast('复制成功');
|
|
|
- },
|
|
|
- });
|
|
|
+ uni.setClipboardData({
|
|
|
+ data: val,
|
|
|
+ success: () => {
|
|
|
+ successToast('复制成功');
|
|
|
+ },
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
// 判断微信环境
|
|
|
export function isWeixin() {
|
|
|
- var ua = navigator.userAgent.toLowerCase();
|
|
|
- if (ua.indexOf('micromessenger') != -1) {
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ if (navigator && navigator.userAgent) {
|
|
|
+ var ua = navigator.userAgent.toLowerCase();
|
|
|
+ if (ua.indexOf('micromessenger') != -1) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return false
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 解析地址栏参数
|
|
|
export function getQueryVariable(variable) {
|
|
|
- // 从?开始获取后面的所有数据
|
|
|
- var query = window.location.search.substring(1);
|
|
|
- // 从字符串&开始分隔成数组split
|
|
|
- var vars = query.split('&');
|
|
|
- // 遍历该数组
|
|
|
- for (var i = 0; i < vars.length; i++) {
|
|
|
- // 从等号部分分割成字符
|
|
|
- var pair = vars[i].split('=');
|
|
|
- // 如果第一个元素等于 传进来的参的话 就输出第二个元素
|
|
|
- if (pair[0] == variable) {
|
|
|
- return pair[1];
|
|
|
- }
|
|
|
- }
|
|
|
- return undefined;
|
|
|
+ // 从?开始获取后面的所有数据
|
|
|
+ var query = window.location.search.substring(1);
|
|
|
+ // 从字符串&开始分隔成数组split
|
|
|
+ var vars = query.split('&');
|
|
|
+ // 遍历该数组
|
|
|
+ for (var i = 0; i < vars.length; i++) {
|
|
|
+ // 从等号部分分割成字符
|
|
|
+ var pair = vars[i].split('=');
|
|
|
+ // 如果第一个元素等于 传进来的参的话 就输出第二个元素
|
|
|
+ if (pair[0] == variable) {
|
|
|
+ return pair[1];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return undefined;
|
|
|
}
|
|
|
|
|
|
|
|
|
export default {
|
|
|
- toast,
|
|
|
- successToast,
|
|
|
- showLoading,
|
|
|
- tipLoading,
|
|
|
- hideLoading,
|
|
|
- modal,
|
|
|
- navPage,
|
|
|
- redPage,
|
|
|
- backPage,
|
|
|
- callPhone,
|
|
|
- copy
|
|
|
-};
|
|
|
+ toast,
|
|
|
+ successToast,
|
|
|
+ showLoading,
|
|
|
+ tipLoading,
|
|
|
+ hideLoading,
|
|
|
+ modal,
|
|
|
+ navPage,
|
|
|
+ redPage,
|
|
|
+ backPage,
|
|
|
+ callPhone,
|
|
|
+ copy
|
|
|
+};
|