- 新增身份选择组件,用户登录后未选择身份时弹出选择框 - 优化登录跳转逻辑,支持页面栈返回模式 - 修复跳转时参数处理的边界情况 - 新增服务配置缓存机制,减少重复请求 - 优化小程序跳转逻辑,增加防重复点击锁 - 修复订单页联系人信息初始化逻辑
211 行
8.7 KiB
JavaScript
211 行
8.7 KiB
JavaScript
/**
|
|
* 师傅端接口清单(仅保留师傅端与公共字典/协议/上传接口)
|
|
*/
|
|
import { get, post, uploadFile } from './request';
|
|
import config from '@/config/config.js';
|
|
|
|
const SERVICE_CONFIG_CACHE_TTL = 5 * 60 * 1000;
|
|
|
|
function resolveTargetMiniProgramEnv() {
|
|
// #ifdef MP-WEIXIN
|
|
try {
|
|
const getter = (typeof uni !== 'undefined' && typeof uni.getAccountInfoSync === 'function')
|
|
? uni.getAccountInfoSync
|
|
: (typeof wx !== 'undefined' && typeof wx.getAccountInfoSync === 'function' ? wx.getAccountInfoSync : null);
|
|
if (getter) {
|
|
const info = getter();
|
|
const envVersion = info && info.miniProgram && info.miniProgram.envVersion;
|
|
if (envVersion === 'develop' || envVersion === 'trial') {
|
|
return envVersion;
|
|
}
|
|
}
|
|
} catch (e) {}
|
|
// #endif
|
|
return 'release';
|
|
}
|
|
|
|
export default {
|
|
/* ---------- 公共 / 上传 / 字典 ---------- */
|
|
upload: (filePath, category = 'other') => uploadFile(filePath, category),
|
|
areas: (data = {}) => get('/common/areas', data, { silent: true }),
|
|
expressCompanies: () => get('/common/expressCompanies', {}, { silent: true }),
|
|
commonDicts: () => get('/common/dicts', {}, { silent: true }),
|
|
cats: () => get('/home/cats'),
|
|
agreement: (type, opt) => get('/home/agreement', { type: type, side: 'master' }, opt || { silent: true }),
|
|
agreementRead: (data, opt) => post('/home/agreementRead', Object.assign({ side: 'master' }, data || {}), Object.assign({ silent: true, allowConcurrent: true }, opt || {})),
|
|
|
|
/* ---------- 师傅端独立鉴权与安全 ---------- */
|
|
login: (data) => post('/master_auth/login', data, { silent: true }),
|
|
wxPhoneLogin: (data) => post('/master_auth/wxPhoneLogin', data, { silent: true }),
|
|
logout: () => post('/master_auth/logout', {}, { silent: true }),
|
|
profile: () => get('/master_auth/profile'),
|
|
securityStatus: () => get('/master_auth/securityStatus'),
|
|
sendPasswordSms: (opt) => post('/master_auth/sendPasswordSms', {}, opt),
|
|
sendPaymentPasswordSms: (opt) => post('/master_auth/sendPaymentPasswordSms', {}, opt),
|
|
changeLoginPassword: (data, opt) => post('/master_auth/changeLoginPassword', data, opt),
|
|
sendResetPasswordSms: (data) => post('/master_auth/sendResetPasswordSms', data),
|
|
resetPasswordBySms: (data) => post('/master_auth/resetPasswordBySms', data),
|
|
setPaymentPassword: (data, opt) => post('/master_auth/setPaymentPassword', data, opt),
|
|
changePaymentPassword: (data, opt) => post('/master_auth/changePaymentPassword', data, opt),
|
|
|
|
/* ---------- 师傅业务 ---------- */
|
|
masterApply: (data) => post('/master/apply', data),
|
|
masterOcrIdCard: (data) => post('/master/ocrIdCard', data),
|
|
masterInfo: () => get('/master/info'),
|
|
masterSaveProfile: (data) => post('/master/saveProfile', data),
|
|
masterHall: (data) => get('/master/hall', data),
|
|
masterOrderDetail: (id, params) => get('/master/orderDetail', { id: id, ...(params || {}) }),
|
|
masterGrab: (data) => post('/master/grab', data),
|
|
masterOrders: (data) => get('/master/orders', data),
|
|
masterContact: (data) => post('/master/contact', data),
|
|
masterSchedule: (data) => post('/master/schedule', data),
|
|
masterArrive: (data) => post('/master/arrive', data),
|
|
masterStart: (data) => post('/master/startJob', data),
|
|
masterFinish: (data) => post('/master/finish', data),
|
|
masterVerifyCode: (data) => post('/master/verifyCode', data),
|
|
masterRequestDiff: (data) => post('/master/requestDiff', data),
|
|
masterIncome: () => get('/master/income'),
|
|
masterToggle: (data) => post('/master/toggleWork', data),
|
|
masterUpdateLocation: (data) => post('/master/updateLocation', data),
|
|
masterResolveLocation: (data) => get('/master/resolveLocation', data, { silent: true }),
|
|
masterSearchLocation: (data) => get('/master/searchLocation', data, { silent: true }),
|
|
masterLocationContext: (data) => get('/master/locationContext', data, { silent: true }),
|
|
masterLocationStats: (data) => get('/master/locationOrderStats', data, { silent: true }),
|
|
masterLocateCity: (data) => get('/master/locateCity', data),
|
|
masterCredit: () => get('/master/credit'),
|
|
masterAppeals: () => get('/master/appeals'),
|
|
masterAppeal: (data) => post('/master/appeal', data),
|
|
masterQuotes: () => get('/master/quotes'),
|
|
masterQuote: (data) => post('/master/quote', data),
|
|
masterWithdraw: (data) => post('/master/withdraw', data),
|
|
masterTransferPackage: (data) => post('/master/transferPackage', data),
|
|
masterSyncWithdraw: (data) => post('/master/syncWithdraw', data, { silent: true, allowConcurrent: true }),
|
|
masterSkillDict: () => get('/master/skillDict'),
|
|
masterSaveSkills: (data) => post('/master/saveSkills', data),
|
|
masterCerts: () => get('/master/certs'),
|
|
masterCertDetail: (params) => get('/master/certDetail', params),
|
|
masterSaveCert: (data) => post('/master/saveCert', data),
|
|
masterDeleteCert: (data) => post('/master/deleteCert', data),
|
|
reviewList: () => get('/master/reviews'),
|
|
|
|
/* ---------- 师傅端独立消息中心 ---------- */
|
|
messageList: (data) => get('/master_message/index', data),
|
|
messageRead: (data) => post('/master_message/read', data),
|
|
messageReadAll: (data) => post('/master_message/readAll', data),
|
|
messageUnread: (data) => get('/master_message/unread', data, { silent: true }),
|
|
|
|
/* ---------- 客服配置与跨小程序跳转 ---------- */
|
|
getCachedServiceConfig: function () {
|
|
try {
|
|
const cached = uni.getStorageSync('yjyf_master_service_config');
|
|
if (cached && typeof cached === 'object') {
|
|
return {
|
|
service_phone: String(cached.service_phone || '').trim(),
|
|
service_work_time: String(cached.service_work_time || '').trim(),
|
|
service_corp_id: String(cached.service_corp_id || '').trim(),
|
|
service_kf_url: String(cached.service_kf_url || '').trim(),
|
|
user_appid: String(cached.user_appid || '').trim(),
|
|
updated_at: Number(cached.updated_at || 0),
|
|
};
|
|
}
|
|
} catch (e) {}
|
|
return {
|
|
service_phone: String(uni.getStorageSync('yjyf_service_phone') || '').trim(),
|
|
service_work_time: '',
|
|
service_corp_id: '',
|
|
service_kf_url: '',
|
|
user_appid: '',
|
|
updated_at: 0,
|
|
};
|
|
},
|
|
getServiceConfig: async function (force = false) {
|
|
const cached = this.getCachedServiceConfig();
|
|
const isFresh = cached.updated_at > 0 && (Date.now() - cached.updated_at < SERVICE_CONFIG_CACHE_TTL);
|
|
if (!force && isFresh && cached.user_appid) {
|
|
return cached;
|
|
}
|
|
try {
|
|
const res = await get('/home/serviceConfig', {}, { silent: true });
|
|
if (res && typeof res === 'object') {
|
|
const cfg = {
|
|
service_phone: String(res.service_phone || '').trim(),
|
|
service_work_time: String(res.service_work_time || '').trim(),
|
|
service_corp_id: String(res.service_corp_id || '').trim(),
|
|
service_kf_url: String(res.service_kf_url || '').trim(),
|
|
user_appid: String(res.user_appid || '').trim(),
|
|
updated_at: Date.now(),
|
|
};
|
|
uni.setStorageSync('yjyf_master_service_config', cfg);
|
|
if (cfg.service_phone) {
|
|
uni.setStorageSync('yjyf_service_phone', cfg.service_phone);
|
|
}
|
|
return cfg;
|
|
}
|
|
} catch (e) {
|
|
console.warn('获取客服配置失败', e);
|
|
}
|
|
return cached;
|
|
},
|
|
_openingUserMini: false,
|
|
openUserMiniProgram: async function (path = 'pages/index/index') {
|
|
if (this._openingUserMini) return;
|
|
this._openingUserMini = true;
|
|
const releaseLock = () => {
|
|
setTimeout(() => { this._openingUserMini = false; }, 600);
|
|
};
|
|
const cached = this.getCachedServiceConfig();
|
|
// #ifdef MP-WEIXIN
|
|
const launch = (appId) => {
|
|
if (!appId) {
|
|
releaseLock();
|
|
uni.showModal({
|
|
title: '优匠优服用户端',
|
|
content: '后台暂未配置用户端小程序 AppID,请在微信搜索打开「优匠优服」小程序或联系平台管理员在后台系统配置中完善。',
|
|
showCancel: false,
|
|
confirmText: '知道了',
|
|
confirmColor: '#F0710D'
|
|
});
|
|
return;
|
|
}
|
|
uni.navigateToMiniProgram({
|
|
appId: appId,
|
|
path: path,
|
|
envVersion: resolveTargetMiniProgramEnv(),
|
|
complete: () => {
|
|
releaseLock();
|
|
},
|
|
fail: (err) => {
|
|
if (err && err.errMsg && err.errMsg.indexOf('cancel') !== -1) return;
|
|
console.warn('[openUserMiniProgram] navigateToMiniProgram fail:', err);
|
|
uni.showToast({ title: '打开用户端小程序失败,请稍后重试', icon: 'none' });
|
|
}
|
|
});
|
|
};
|
|
if (cached.user_appid) {
|
|
launch(cached.user_appid);
|
|
if (!cached.updated_at || Date.now() - cached.updated_at >= SERVICE_CONFIG_CACHE_TTL) {
|
|
this.getServiceConfig(true).catch(() => {});
|
|
}
|
|
return;
|
|
}
|
|
try {
|
|
const cfg = await this.getServiceConfig(true);
|
|
launch(cfg.user_appid);
|
|
} catch (e) {
|
|
releaseLock();
|
|
uni.showToast({ title: '获取用户端配置失败,请稍后重试', icon: 'none' });
|
|
}
|
|
// #endif
|
|
// #ifndef MP-WEIXIN
|
|
releaseLock();
|
|
uni.showModal({
|
|
title: '前往优匠优服用户端',
|
|
content: '请在微信中搜索「优匠优服」小程序发布安装维修需求。',
|
|
showCancel: false,
|
|
confirmText: '知道了',
|
|
confirmColor: '#F0710D'
|
|
});
|
|
// #endif
|
|
}
|
|
};
|