文件
yjyf/yjyf-master-app/utils/share.js
MiAn 14533eadb7 feat: 用户端与师傅端双小程序架构解耦,新增师傅独立认证及超时自动关单机制
1. 账号体系与数据库解耦:
   - 师傅表 fa_master 解除对 fa_user.id 的外键依赖,升级为独立认证账号主表;
   - 新增师傅端独立支撑表:fa_master_security、fa_master_token、fa_master_wechat、fa_master_agreement_read;
   - 新增工单超时未接单自动关闭与原路退款配置(order_unaccepted_close_days)。

2. 服务端(Server):
   - 新增师傅端独立 API 控制器与认证库(MasterAuth, MasterBase, MasterMessage, MasterSecurity, MasterToken);
   - WxLogin 支持双小程序端(user/master)独立换取 session_key、openid 与 access_token;
   - 新增控制台调度命令 php think order:autoclose,支持订单超时自动关闭与售后退款闭环;
   - 修复 PHP 8.5 兼容性问题(Request.php 的 (bool) 强制转换);
   - 系统业务配置全面收敛至数据库 fa_config 及 site.php。

3. 小程序端:
   - yjyf-app(用户端):彻底剥离师傅端路由、组件及静态资源,增加隐私授权弹窗与评价模块;
   - yjyf-master-app(师傅端):全新独立微信小程序工程(wx140d90ceda786107),实现工作台、接单大厅、资质认证、工单协同与钱包提现完整闭环。
2026-11-23 15:10:30 +08:00

212 行
6.2 KiB
JavaScript

/**
* 优匠优服师傅端 · 小程序分享统一引擎
*/
import { getCurrentInstance } from 'vue';
import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
import { getUser } from './request.js';
export const DEFAULT_SHARE_TITLE = '优匠优服师傅端 · 实名认证接同城好单';
export const DEFAULT_SHARE_PATH = '/pages/master/hall';
export const DEFAULT_SHARE_IMAGE = '/static/brand-logo.png';
const PUBLIC_SHARE_ROUTES = [
'pages/master/hall',
'pages/master/detail',
'pages/master/apply'
];
const ROUTE_SHARE_TITLES = {
'pages/master/hall': '优匠优服师傅端 · 海量同城安装维修工单实时派发',
'pages/master/detail': '【同城工单派发】优匠优服新工单,认证师傅快来接单',
'pages/master/apply': '优匠优服师傅招募 · 实名技能认证,海量同城好单随时接'
};
export function stringifyShareQuery(params = {}) {
if (!params || typeof params !== 'object') return '';
const parts = [];
Object.keys(params).forEach((key) => {
const val = params[key];
if (val !== undefined && val !== null && val !== '') {
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(val))}`);
}
});
return parts.join('&');
}
export function parseSharePath(fullPath = '') {
const clean = String(fullPath || '').trim() || DEFAULT_SHARE_PATH;
const normalized = clean.startsWith('/') ? clean : '/' + clean;
const qIndex = normalized.indexOf('?');
if (qIndex === -1) {
return {
route: normalized.replace(/^\/+/, ''),
path: normalized,
queryStr: ''
};
}
const pathOnly = normalized.slice(0, qIndex);
const queryStr = normalized.slice(qIndex + 1);
return {
route: pathOnly.replace(/^\/+/, ''),
path: pathOnly,
queryStr
};
}
function getCurrentPageMeta() {
try {
const pages = typeof getCurrentPages === 'function' ? getCurrentPages() : [];
if (pages && pages.length) {
const cur = pages[pages.length - 1];
const route = cur.route || (cur.$page && cur.$page.route) || 'pages/master/hall';
const options = cur.options || (cur.$page && cur.$page.options) || {};
return { route: route.replace(/^\/+/, ''), options, pageInstance: cur };
}
} catch (e) {}
return { route: 'pages/master/hall', options: {}, pageInstance: null };
}
function appendSharerTrack(queryStr = '') {
try {
const master = getUser();
if (master && master.id) {
if (!/(^|&)share_mid=/.test(queryStr)) {
return queryStr ? `${queryStr}&share_mid=${master.id}` : `share_mid=${master.id}`;
}
}
} catch (e) {}
return queryStr;
}
export function buildDefaultShareData(vm) {
const { route, options } = getCurrentPageMeta();
const isPublic = PUBLIC_SHARE_ROUTES.includes(route);
let title = ROUTE_SHARE_TITLES[route] || DEFAULT_SHARE_TITLE;
let targetRoute = isPublic ? `/${route}` : DEFAULT_SHARE_PATH;
let queryStr = isPublic ? stringifyShareQuery(options) : '';
let imageUrl = '';
const customGetter = vm && vm.$ && typeof vm.$.__yjyfShareGetter === 'function'
? vm.$.__yjyfShareGetter
: null;
if (customGetter) {
try {
const custom = customGetter() || {};
if (custom.title) title = custom.title;
if (custom.imageUrl) imageUrl = custom.imageUrl;
if (custom.path) {
const parsed = parseSharePath(custom.path);
targetRoute = parsed.path;
queryStr = parsed.queryStr;
}
if (custom.query !== undefined) {
queryStr = typeof custom.query === 'object'
? stringifyShareQuery(custom.query)
: String(custom.query || '').replace(/^\?/, '');
}
} catch (e) {}
}
const trackedQuery = appendSharerTrack(queryStr);
const finalPath = trackedQuery ? `${targetRoute}?${trackedQuery}` : targetRoute;
return {
title: title || DEFAULT_SHARE_TITLE,
path: finalPath || DEFAULT_SHARE_PATH,
query: trackedQuery,
imageUrl: imageUrl || ''
};
}
export function useShare(getterOrConfig) {
const instance = getCurrentInstance();
const getter = typeof getterOrConfig === 'function'
? getterOrConfig
: () => (getterOrConfig || {});
if (instance) {
instance.__yjyfShareGetter = getter;
}
onShareAppMessage(() => {
const proxy = instance && instance.proxy ? instance.proxy : null;
const data = buildDefaultShareData(proxy);
const out = { title: data.title, path: data.path };
if (data.imageUrl) out.imageUrl = data.imageUrl;
return out;
});
onShareTimeline(() => {
const proxy = instance && instance.proxy ? instance.proxy : null;
const data = buildDefaultShareData(proxy);
const out = { title: data.title, query: data.query || '' };
if (data.imageUrl) out.imageUrl = data.imageUrl;
return out;
});
}
export function triggerCustomShare(customInfo = {}) {
const title = customInfo.title || DEFAULT_SHARE_TITLE;
const path = customInfo.path || DEFAULT_SHARE_PATH;
// #ifdef H5
const fullUrl = typeof window !== 'undefined' && window.location
? `${window.location.origin}/#${path.startsWith('/') ? path : '/' + path}`
: path;
if (typeof navigator !== 'undefined' && typeof navigator.share === 'function') {
navigator.share({ title, text: title, url: fullUrl }).catch(() => {});
return;
}
uni.setClipboardData({
data: `${title} ${fullUrl}`,
success: () => uni.showToast({ title: '已复制分享链接', icon: 'none' })
});
// #endif
// #ifndef H5
uni.setClipboardData({
data: `${title}`,
success: () => uni.showToast({ title: '请点击右上角“...”转发给好友或分享朋友圈', icon: 'none' })
});
// #endif
}
export default {
onLoad() {
// #ifdef MP-WEIXIN
if (typeof uni.showShareMenu === 'function') {
uni.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline'],
fail: () => {}
});
}
// #endif
},
onShow() {
// #ifdef MP-WEIXIN
if (typeof uni.showShareMenu === 'function') {
uni.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline'],
fail: () => {}
});
}
// #endif
},
onShareAppMessage() {
const data = buildDefaultShareData(this);
const out = { title: data.title, path: data.path };
if (data.imageUrl) out.imageUrl = data.imageUrl;
return out;
},
onShareTimeline() {
const data = buildDefaultShareData(this);
const out = { title: data.title, query: data.query || '' };
if (data.imageUrl) out.imageUrl = data.imageUrl;
return out;
}
};