feat: 添加华夏变现、添加三方权限配置

This commit is contained in:
2026-09-22 10:09:04 +08:00
parent 2a25354ee4
commit 4e190b5879
5 changed files with 564 additions and 141 deletions
+228 -50
View File
@@ -110,7 +110,10 @@
</view>
</view>
</view>
<view v-if="showThirdPartyServiceCard" class="card card5 third-party-card bg24">
<view
v-if="showThirdPartyServiceCard"
class="card card5 third-party-card bg24"
>
<view class="card_title">第三方服务</view>
<view class="flex-center card5_con wrap ju-flex-start">
@@ -118,10 +121,10 @@
class="flex-center flex-column card5_item"
v-for="(v, i) in thirdPartyServiceList"
:key="i"
@click="openThirdPartyService(v)"
@click="onThirdPartyServiceClick(v)"
>
<view class="card5_icon third-party-icon m-b-18 w_84 h_84">
<image :src="v.icon" mode="scaleToFill" />
<image :src="getThirdPartyIcon(v.icon)" mode="scaleToFill" />
</view>
<view class="card5_name size28 color_3">{{ v.name }}</view>
</view>
@@ -134,9 +137,19 @@
<script setup>
import sheep from '@/sheep';
import cardTabber from '@/components/card_tabber/card_tabber.vue';
import { ref, reactive, onMounted, onUnmounted, getCurrentInstance, watch, nextTick, computed } from 'vue';
import {
ref,
reactive,
onMounted,
onUnmounted,
getCurrentInstance,
watch,
nextTick,
computed,
} from 'vue';
import { onShow } from '@dcloudio/uni-app';
import { getWallet } from '@/sheep/api/home/pay';
import * as incrementApi from '@/sheep/api/increment';
import UserApi from '@/sheep/api/member/user';
import OrderApi from '@/sheep/api/trade/order';
@@ -176,20 +189,6 @@
url: '/pages/home/pointsDetail?type=1',
color: '#0ED72C',
},
// {
// id: 2,
// name: '佣金',
// value: 'commission_num',
// unit: '元',
// url: '/pages/home/pointsDetail?type=2',
// },
// {
// id: 3,
// name: '代理收益',
// value: 'agency_income',
// unit: '元',
// url: '/pages/home/pointsDetail?type=3',
// },
{
id: 4,
name: '消费金',
@@ -272,40 +271,157 @@
url: '/pages/public/setting',
},
]);
const showThirdPartyServiceCard = true;
let thirdPartyServiceList = ref([
{
name: '无双',
icon: '/static/icon/web/wushuang.png',
title: '无双',
url: 'https://shop.wushuange.com/web/#/pages/store/index?store_id=5',
},
]);
const goReal = () => {
uni.navigateTo({
url: '/pages/public/realname?status=' + realStatus.value,
// query: obj,
});
};
const go = (path, obj) => {
if (!path) {
// 打电话
// uni.makePhoneCall({
// phoneNumber: '4000621698',
// });
uni.showToast({
title: '功能开发中, 敬请期待',
icon: 'none',
});
return;
} else {
uni.navigateTo({
url: path,
query: obj,
});
}
const LIQUIDATION_TYPE_META = {
2: {
name: '无双',
title: '无双',
icon: '/static/icon/web/wushuang.png',
keywords: ['无双'],
},
3: {
name: '华夏',
title: '华夏',
inlineIcon: true,
keywords: ['华夏'],
},
};
const matchChannelMeta = (channel) => {
const lt = Number(channel?.liquidationType);
if ([2, 3].includes(lt) && LIQUIDATION_TYPE_META[lt]) {
return { liquidationType: lt, meta: LIQUIDATION_TYPE_META[lt] };
}
const name = String(channel?.channelName || channel?.name || '').trim();
if (!name) return null;
for (const key of Object.keys(LIQUIDATION_TYPE_META)) {
const m = LIQUIDATION_TYPE_META[key];
const keywords = Array.isArray(m?.keywords) ? m.keywords : [];
if (keywords.some((kw) => name.includes(kw))) {
return { liquidationType: Number(key), meta: m };
}
}
return null;
};
const WUSHUANG_DEFAULT_STORE_ID = 5;
const resolveWushuangStoreId = () => WUSHUANG_DEFAULT_STORE_ID;
const buildWushuangStoreUrl = (fallbackBaseUrl) => {
const id = resolveWushuangStoreId();
if (!id) return '';
let base = String(fallbackBaseUrl || '').trim().replace(/`/g, '').trim();
const tail = `/web/#/pages/store/index?store_id=${id}`;
if (/^https?:\/\//i.test(base)) {
const cleanBase = base.replace(/\/+$/, '');
return cleanBase + tail;
}
return `https://shop.wushuange.com${tail}`;
};
const buildHuaxiaInlineIcon = () => {
const svg =
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 84 84">' +
'<circle cx="42" cy="42" r="42" fill="#18b37b"/>' +
'<text x="42" y="42" font-family="PingFang SC,Helvetica Neue,Microsoft YaHei,Arial,sans-serif" font-weight="700" font-size="30" fill="#ffffff" text-anchor="middle" dominant-baseline="middle">华夏</text>' +
'</svg>';
return 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svg);
};
const tradeChannelList = ref([]);
const fetchTradeChannels = async () => {
try {
const res = await incrementApi.getTradeChannelList();
if (res?.code === 0 && Array.isArray(res?.data)) {
tradeChannelList.value = res.data.filter((it) => Number(it?.status) === 1);
}
} catch (e) {}
};
const normalizeChannelUrl = (raw, liquidationType) => {
let base = String(raw || '').trim().replace(/`/g, '').trim();
if (!base) return '';
if (Number(liquidationType) === 2) {
return buildWushuangStoreUrl(base);
}
return base;
};
const showThirdPartyServiceCard = computed(
() => thirdPartyServiceList.value.length > 0,
);
const thirdPartyServiceList = computed(() => {
const list = [];
const added = new Set();
const channels = Array.isArray(tradeChannelList.value) ? tradeChannelList.value : [];
channels.forEach((it) => {
if (Number(it?.status) !== 1) return;
const matched = matchChannelMeta(it);
if (!matched) return;
const lt = matched.liquidationType;
const meta = matched.meta;
if (added.has(lt)) return;
let url = '';
if (lt !== 3) {
url = normalizeChannelUrl(it?.baseUrl || it?.url, lt);
if (!url) return;
}
added.add(lt);
const item = {
name: meta.name,
title: meta.title,
url,
liquidationType: lt,
channelId: it?.id ?? it?.channelId,
channelBaseUrl: String(it?.baseUrl || it?.url || '').trim(),
};
if (meta.inlineIcon) {
item.icon = buildHuaxiaInlineIcon();
} else if (meta.icon) {
item.icon = meta.icon;
}
list.push(item);
});
return list;
});
const getThirdPartyIcon = (icon) => {
const iconText = String(icon || '');
if (iconText.startsWith('data:') || iconText.startsWith('/')) {
return iconText;
}
return iconText;
};
const showModalAsync = (options) =>
new Promise((resolve) => {
uni.showModal({
...(options || {}),
success: (res) => resolve(res),
fail: () => resolve({ confirm: false, cancel: true }),
});
});
const pendingThirdPartyItem = ref(null);
const ensureRealNameOrRedirect = async (item) => {
if (Number(realStatus.value || dataInfo.value?.realStatus) === 1) return true;
pendingThirdPartyItem.value = item || null;
const res = await showModalAsync({
title: '实名认证提示',
content: '使用华夏服务需先完成实名认证,是否前往认证?',
confirmText: '去认证',
cancelText: '取消',
confirmColor: '#2c8cfa',
});
if (!res?.confirm) {
pendingThirdPartyItem.value = null;
return false;
}
uni.navigateTo({
url: '/pages/public/realname?status=0',
});
return false;
};
const openThirdPartyService = (item) => {
if (!item?.url) return;
const title = encodeURIComponent(item.title || item.name || '第三方服务');
@@ -328,6 +444,60 @@
}
openWebview();
};
const onThirdPartyServiceClick = async (item) => {
if (!item) return;
const isHuaxia =
Number(item?.liquidationType) === 3 || String(item?.name || '') === '华夏';
if (isHuaxia) {
const ok = await ensureRealNameOrRedirect(item);
if (!ok) return;
const query = {};
if (item?.channelId != null && item?.channelId !== '') {
query.channelId = Number(item.channelId);
}
const regRes = await incrementApi
.checkHuaxiaRegister(query)
.catch(() => ({ code: -1 }));
if (regRes?.code !== 0) {
if (regRes?.msg) {
uni.showToast({ title: regRes.msg, icon: 'none' });
}
return;
}
const data = regRes?.data || {};
const url = typeof data === 'string'
? String(data).trim()
: String(data?.url || data?.redirectUrl || '').trim();
if (!url) {
uni.showToast({ title: '跳转链接为空', icon: 'none' });
return;
}
openThirdPartyService({ ...item, url });
return;
}
openThirdPartyService(item);
};
const goReal = () => {
uni.navigateTo({
url: '/pages/public/realname?status=' + realStatus.value,
});
};
const go = (path, obj) => {
if (!path) {
uni.showToast({
title: '功能开发中, 敬请期待',
icon: 'none',
});
return;
} else {
uni.navigateTo({
url: path,
query: obj,
});
}
};
const updateAvatar = async (avatar) => {
if (!avatar) return;
const res = await UserApi.updateUser({
@@ -404,9 +574,17 @@
}
});
};
onMounted(() => {
fetchTradeChannels();
});
onShow(async () => {
getData();
getNumData();
if (pendingThirdPartyItem.value && Number(realStatus.value || 0) === 1) {
const next = pendingThirdPartyItem.value;
pendingThirdPartyItem.value = null;
nextTick(() => onThirdPartyServiceClick(next));
}
});
</script>
<style lang="scss" scoped>