71 lines
2.1 KiB
JavaScript
71 lines
2.1 KiB
JavaScript
/**
|
|
* 角色协议卡点:未签当前版本则跳转签署页,签完 resolve(true)。
|
|
* @param {string} role dashou|guanshi|zuzhang
|
|
* @param {string} [gate] qiangdan|register|tixian|invite — 按后台卡点判断
|
|
*/
|
|
import request from './request.js';
|
|
|
|
export async function fetchRoleAgreement(role, gate = '', viewOnly = false) {
|
|
const data = { role };
|
|
if (gate) data.gate = gate;
|
|
if (viewOnly) data.view = 1;
|
|
const res = await request({
|
|
url: '/yonghu/role-agreement/current',
|
|
method: 'POST',
|
|
data,
|
|
});
|
|
const body = res?.data;
|
|
if (body && (body.code === 200 || body.code === 0)) {
|
|
return body.data || {};
|
|
}
|
|
return { need_sign: false, enabled: false };
|
|
}
|
|
|
|
/**
|
|
* @returns {Promise<boolean>} true=已签或无需签;false=用户未完成签署
|
|
*/
|
|
export function ensureRoleAgreement(role, gate = '') {
|
|
return fetchRoleAgreement(role, gate, false).then((data) => {
|
|
if (!data || !data.need_sign) {
|
|
return true;
|
|
}
|
|
return new Promise((resolve) => {
|
|
const app = getApp();
|
|
if (!app.globalData) app.globalData = {};
|
|
app.globalData._pendingAgreementResolve = (ok) => {
|
|
app.globalData._pendingAgreementResolve = null;
|
|
resolve(!!ok);
|
|
};
|
|
const q = [`role=${encodeURIComponent(role)}`];
|
|
if (gate) q.push(`gate=${encodeURIComponent(gate)}`);
|
|
wx.navigateTo({
|
|
url: `/pages/role-agreement/role-agreement?${q.join('&')}`,
|
|
fail: () => {
|
|
app.globalData._pendingAgreementResolve = null;
|
|
resolve(false);
|
|
},
|
|
});
|
|
});
|
|
}).catch(() => true);
|
|
}
|
|
|
|
/** 资产 type → 协议 role(提现卡点用) */
|
|
export function assetTypeToAgreementRole(assetType) {
|
|
const map = {
|
|
dashou_yue: 'dashou',
|
|
dashou_yajin: 'dashou',
|
|
guanshi_fenyong: 'guanshi',
|
|
zuzhang_fenyong: 'zuzhang',
|
|
};
|
|
return map[assetType] || '';
|
|
}
|
|
|
|
export function finishPendingAgreement(ok) {
|
|
const app = getApp();
|
|
const fn = app.globalData && app.globalData._pendingAgreementResolve;
|
|
if (typeof fn === 'function') {
|
|
app.globalData._pendingAgreementResolve = null;
|
|
fn(!!ok);
|
|
}
|
|
}
|