!55 解析分享参数,绑定推广员

Merge pull request !55 from puhui999/master
pull/58/head
芋道源码 2024-05-27 13:57:30 +00:00 committed by Gitee
commit 6550441bc9
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 131 additions and 114 deletions

View File

@ -29,6 +29,7 @@
<!-- 海报画板默认隐藏只用来生成海报生成方式为主动调用 --> <!-- 海报画板默认隐藏只用来生成海报生成方式为主动调用 -->
<l-painter <l-painter
isCanvasToTempFilePath isCanvasToTempFilePath
pathType="url"
@success="setPainterImageUrl" @success="setPainterImageUrl"
hidden hidden
ref="painterRef" ref="painterRef"
@ -65,7 +66,7 @@
css: { css: {
// //
width: sheep.$platform.device.windowWidth * 0.9, width: sheep.$platform.device.windowWidth * 0.9,
height: 600, height: 550,
}, },
views: [], views: [],
}); });
@ -92,6 +93,7 @@
sheep.$helper.toast('请长按图片保存'); sheep.$helper.toast('请长按图片保存');
return; return;
} }
// H5 // H5
uni.saveImageToPhotosAlbum({ uni.saveImageToPhotosAlbum({
filePath: painterImageUrl.value, filePath: painterImageUrl.value,
@ -108,6 +110,7 @@
// //
async function getPoster() { async function getPoster() {
painterImageUrl.value = undefined
poster.views = await getPosterData({ poster.views = await getPosterData({
width: poster.css.width, width: poster.css.width,
shareInfo: props.shareInfo, shareInfo: props.shareInfo,

View File

@ -1,11 +1,10 @@
import sheep from '@/sheep'; import sheep from '@/sheep';
import third from '@/sheep/api/migration/third'; import { formatImageUrlProtocol, getWxaQrcode } from './index';
import { formatImageUrlProtocol } from './index';
const goods = async (poster) => { const goods = async (poster) => {
const width = poster.width; const width = poster.width;
const userInfo = sheep.$store('user').userInfo; const userInfo = sheep.$store('user').userInfo;
const wxa_qrcode = 'data:image/png;base64,' + (await third.wechat.getWxacode(poster.shareInfo.path, poster.shareInfo.query)).data; const wxa_qrcode = await getWxaQrcode(poster.shareInfo.path, poster.shareInfo.query);
return [ return [
{ {
type: 'image', type: 'image',
@ -62,7 +61,7 @@ const goods = async (poster) => {
top: width * 1.18, top: width * 1.18,
color: '#333', color: '#333',
fontSize: 14, fontSize: 14,
lineHeight: 5, lineHeight: 15,
maxWidth: width * 0.91, maxWidth: width * 0.91,
}, },
}, },
@ -72,7 +71,7 @@ const goods = async (poster) => {
css: { css: {
position: 'fixed', position: 'fixed',
left: width * 0.04, left: width * 0.04,
top: width * 1.3, top: width * 1.31,
fontSize: 20, fontSize: 20,
fontFamily: 'OPPOSANS', fontFamily: 'OPPOSANS',
color: '#333', color: '#333',
@ -87,7 +86,7 @@ const goods = async (poster) => {
css: { css: {
position: 'fixed', position: 'fixed',
left: width * 0.3, left: width * 0.3,
top: width * 1.32, top: width * 1.33,
color: '#999', color: '#999',
fontSize: 10, fontSize: 10,
fontFamily: 'OPPOSANS', fontFamily: 'OPPOSANS',

View File

@ -1,11 +1,10 @@
import sheep from '@/sheep'; import sheep from '@/sheep';
import { formatImageUrlProtocol } from './index'; import { formatImageUrlProtocol, getWxaQrcode } from './index';
import third from '@/sheep/api/migration/third';
const groupon = async (poster) => { const groupon = async (poster) => {
const width = poster.width; const width = poster.width;
const userInfo = sheep.$store('user').userInfo; const userInfo = sheep.$store('user').userInfo;
const wxa_qrcode = 'data:image/png;base64,' + (await third.wechat.getWxacode(poster.shareInfo.path, poster.shareInfo.query)).data; const wxa_qrcode = await getWxaQrcode(poster.shareInfo.path, poster.shareInfo.query);
return [ return [
{ {
type: 'image', type: 'image',

View File

@ -1,6 +1,7 @@
import user from './user'; import user from './user';
import goods from './goods'; import goods from './goods';
import groupon from './groupon'; import groupon from './groupon';
import third from '@/sheep/api/migration/third';
export function getPosterData(options) { export function getPosterData(options) {
switch (options.shareInfo.poster.type) { switch (options.shareInfo.poster.type) {
@ -30,3 +31,9 @@ export function formatImageUrlProtocol(url) {
return url; return url;
} }
// 获得微信小程序码 Base64 image
export async function getWxaQrcode(path, query) {
const res = await third.wechat.getWxacode(path, query);
return 'data:image/png;base64,' + res.data;
}

View File

@ -1,11 +1,10 @@
import sheep from '@/sheep'; import sheep from '@/sheep';
import { formatImageUrlProtocol } from './index'; import { formatImageUrlProtocol, getWxaQrcode } from './index';
import third from '@/sheep/api/migration/third';
const user = async (poster) => { const user = async (poster) => {
const width = poster.width; const width = poster.width;
const userInfo = sheep.$store('user').userInfo; const userInfo = sheep.$store('user').userInfo;
const wxa_qrcode = 'data:image/png;base64,' + (await third.wechat.getWxacode(poster.shareInfo.path, poster.shareInfo.query)).data; const wxa_qrcode = await getWxaQrcode(poster.shareInfo.path, poster.shareInfo.query);
return [ return [
{ {
type: 'image', type: 'image',

View File

@ -1,6 +1,7 @@
// 登录 // 登录
import third from '@/sheep/api/migration/third'; import third from '@/sheep/api/migration/third';
import SocialApi from '@/sheep/api/member/social'; import SocialApi from '@/sheep/api/member/social';
import $share from '@/sheep/platform/share';
// TODO 芋艿:等后面搞 App 再弄 // TODO 芋艿:等后面搞 App 再弄
const socialType = 32; // 社交类型 - 微信开放平台 const socialType = 32; // 社交类型 - 微信开放平台
@ -16,6 +17,7 @@ const login = () => {
}); });
debugger debugger
if (loginRes.errMsg == 'login:ok') { if (loginRes.errMsg == 'login:ok') {
// TODO third.wechat.login 函数未实现
const res = await third.wechat.login({ const res = await third.wechat.login({
platform: 'openPlatform', platform: 'openPlatform',
shareInfo: uni.getStorageSync('shareLog') || {}, shareInfo: uni.getStorageSync('shareLog') || {},
@ -27,6 +29,7 @@ const login = () => {
}); });
if (res.error === 0) { if (res.error === 0) {
$share.bindBrokerageUser()
resolve(true); resolve(true);
} }
} else { } else {

View File

@ -2,6 +2,7 @@ import $store from '@/sheep/store';
import $platform from '@/sheep/platform'; import $platform from '@/sheep/platform';
import $router from '@/sheep/router'; import $router from '@/sheep/router';
import $url from '@/sheep/url'; import $url from '@/sheep/url';
import BrokerageApi from '@/sheep/api/trade/brokerage';
// #ifdef H5 // #ifdef H5
import $wxsdk from '@/sheep/libs/sdk-h5-weixin'; import $wxsdk from '@/sheep/libs/sdk-h5-weixin';
// #endif // #endif
@ -152,18 +153,16 @@ const decryptSpm = (spm) => {
id: shareParamsArray[2], id: shareParamsArray[2],
}; };
break; break;
case '6': // 分销
// TODO puhui999: 如果用户未登录想想怎么搞
} }
shareParams.platform = platformMap[shareParamsArray[3] - 1]; shareParams.platform = platformMap[shareParamsArray[3] - 1];
shareParams.from = fromMap[shareParamsArray[4] - 1]; shareParams.from = fromMap[shareParamsArray[4] - 1];
if (shareParams.shareId != 0) { if (shareParams.shareId !== 0) {
// 已登录 立即添加分享记录 // 已登录 绑定推广员
if (user.isLogin) { if (user.isLogin) {
user.addShareLog(shareParams); bindBrokerageUser(shareParams.shareId);
} else { } else {
// 未登录 待用户登录后添加分享记录 // 记录分享者编号
uni.setStorageSync('shareLog', shareParams); uni.setStorageSync('shareId', shareParams.shareId);
} }
} }
@ -173,6 +172,19 @@ const decryptSpm = (spm) => {
return shareParams; return shareParams;
}; };
// 绑定推广员
const bindBrokerageUser = async (val= undefined) => {
try {
const shareId = val || uni.getStorageSync('shareId');
if (!shareId) {
return;
}
await BrokerageApi.bindBrokerageUser({ bindUserId: shareId });
uni.removeStorageSync('shareId');
} catch {
}
};
// 更新公众号分享sdk // 更新公众号分享sdk
const updateShareInfo = (shareInfo) => { const updateShareInfo = (shareInfo) => {
// #ifdef H5 // #ifdef H5
@ -186,4 +198,5 @@ export default {
getShareInfo, getShareInfo,
updateShareInfo, updateShareInfo,
decryptSpm, decryptSpm,
bindBrokerageUser,
}; };

View File

@ -1,17 +1,9 @@
import { import { defineStore } from 'pinia';
defineStore
} from 'pinia';
import $share from '@/sheep/platform/share'; import $share from '@/sheep/platform/share';
import { import { clone, cloneDeep } from 'lodash';
isEmpty,
cloneDeep,
clone
} from 'lodash';
import cart from './cart'; import cart from './cart';
import app from './app'; import app from './app';
import { import { showAuthModal } from '@/sheep/hooks/useModal';
showAuthModal
} from '@/sheep/hooks/useModal';
import UserApi from '@/sheep/api/member/user'; import UserApi from '@/sheep/api/member/user';
import PayWalletApi from '@/sheep/api/pay/wallet'; import PayWalletApi from '@/sheep/api/pay/wallet';
import OrderApi from '@/sheep/api/trade/order'; import OrderApi from '@/sheep/api/trade/order';
@ -19,17 +11,17 @@ import CouponApi from '@/sheep/api/promotion/coupon';
// 默认用户信息 // 默认用户信息
const defaultUserInfo = { const defaultUserInfo = {
avatar: '', // 头像 avatar: '', // 头像
nickname: '', // 昵称 nickname: '', // 昵称
gender: 0, // 性别 gender: 0, // 性别
mobile: '', // 手机号 mobile: '', // 手机号
point: 0, // 积分 point: 0, // 积分
}; };
// 默认钱包信息 // 默认钱包信息
const defaultUserWallet = { const defaultUserWallet = {
balance: 0, // 余额 balance: 0, // 余额
} };
// 默认订单、优惠券等其他资产信息 // 默认订单、优惠券等其他资产信息
const defaultNumData = { const defaultNumData = {
@ -41,29 +33,29 @@ const defaultNumData = {
deliveredCount: 0, deliveredCount: 0,
uncommentedCount: 0, uncommentedCount: 0,
afterSaleCount: 0, afterSaleCount: 0,
}, },
}; };
const user = defineStore({ const user = defineStore({
id: 'user', id: 'user',
state: () => ({ state: () => ({
userInfo: clone(defaultUserInfo), // 用户信息 userInfo: clone(defaultUserInfo), // 用户信息
userWallet: clone(defaultUserWallet), // 用户钱包信息 userWallet: clone(defaultUserWallet), // 用户钱包信息
isLogin: !!uni.getStorageSync('token'), // 登录状态 isLogin: !!uni.getStorageSync('token'), // 登录状态
numData: cloneDeep(defaultNumData), // 用户其他数据 numData: cloneDeep(defaultNumData), // 用户其他数据
lastUpdateTime: 0, // 上次更新时间 lastUpdateTime: 0, // 上次更新时间
}), }),
actions: { actions: {
// 获取用户信息 // 获取用户信息
async getInfo() { async getInfo() {
const { code, data } = await UserApi.getUserInfo(); const { code, data } = await UserApi.getUserInfo();
if (code !== 0) { if (code !== 0) {
return; return;
} }
this.userInfo = data; this.userInfo = data;
return Promise.resolve(data); return Promise.resolve(data);
}, },
// 获得用户钱包 // 获得用户钱包
async getWallet() { async getWallet() {
@ -74,7 +66,7 @@ const user = defineStore({
this.userWallet = data; this.userWallet = data;
}, },
// 获取订单、优惠券等其他资产信息 // 获取订单、优惠券等其他资产信息
getNumData() { getNumData() {
OrderApi.getOrderCount().then(res => { OrderApi.getOrderCount().then(res => {
if (res.code === 0) { if (res.code === 0) {
@ -86,101 +78,103 @@ const user = defineStore({
this.numData.unusedCouponCount = res.data; this.numData.unusedCouponCount = res.data;
} }
}); });
}, },
// 添加分享记录 // 添加分享记录
// TODO 芋艿:整理下; // TODO 芋艿:整理下;
async addShareLog(params) { // async addShareLog(params) {
const { // const {
error // error
} = await userApi.addShareLog(params); // } = await userApi.addShareLog(params);
if (error === 0) uni.removeStorageSync('shareLog'); // if (error === 0) uni.removeStorageSync('shareLog');
}, // },
// 设置 token // 设置 token
setToken(token = '', refreshToken = '') { setToken(token = '', refreshToken = '') {
if (token === '') { if (token === '') {
this.isLogin = false; this.isLogin = false;
uni.removeStorageSync('token'); uni.removeStorageSync('token');
uni.removeStorageSync('refresh-token') uni.removeStorageSync('refresh-token');
} else { } else {
this.isLogin = true; this.isLogin = true;
uni.setStorageSync('token', token); uni.setStorageSync('token', token);
uni.setStorageSync('refresh-token', refreshToken); uni.setStorageSync('refresh-token', refreshToken);
this.loginAfter(); this.loginAfter();
} }
return this.isLogin; return this.isLogin;
}, },
// 更新用户相关信息 (手动限流5 秒之内不刷新) // 更新用户相关信息 (手动限流5 秒之内不刷新)
async updateUserData() { async updateUserData() {
if (!this.isLogin) { if (!this.isLogin) {
this.resetUserData(); this.resetUserData();
return; return;
} }
// 防抖5 秒之内不刷新 // 防抖5 秒之内不刷新
const nowTime = new Date().getTime(); const nowTime = new Date().getTime();
if (this.lastUpdateTime + 5000 > nowTime) { if (this.lastUpdateTime + 5000 > nowTime) {
return; return;
} }
this.lastUpdateTime = nowTime; this.lastUpdateTime = nowTime;
// 获取最新信息 // 获取最新信息
await this.getInfo(); await this.getInfo();
this.getWallet(); this.getWallet();
this.getNumData(); this.getNumData();
return this.userInfo; return this.userInfo;
}, },
// 重置用户默认数据 // 重置用户默认数据
resetUserData() { resetUserData() {
// 清空 token // 清空 token
this.setToken(); this.setToken();
// 清空用户相关的缓存 // 清空用户相关的缓存
this.userInfo = clone(defaultUserInfo); this.userInfo = clone(defaultUserInfo);
this.userWallet = clone(defaultUserWallet); this.userWallet = clone(defaultUserWallet);
this.numData = cloneDeep(defaultNumData); this.numData = cloneDeep(defaultNumData);
// 清空购物车的缓存 // 清空购物车的缓存
cart().emptyList(); cart().emptyList();
}, },
// 登录后,加载各种信息 // 登录后,加载各种信息
// TODO 芋艿:整理下; // TODO 芋艿:整理下;
async loginAfter() { async loginAfter() {
await this.updateUserData(); await this.updateUserData();
// 加载购物车 // 加载购物车
cart().getList(); cart().getList();
// 登录后设置全局分享参数 // 登录后设置全局分享参数
$share.getShareInfo(); $share.getShareInfo();
// 提醒绑定手机号 // 提醒绑定手机号
if (app().platform.bind_mobile && !this.userInfo.mobile) { if (app().platform.bind_mobile && !this.userInfo.mobile) {
showAuthModal('changeMobile'); showAuthModal('changeMobile');
} }
// 添加分享记录 // 绑定推广员
$share.bindBrokerageUser()
// 添加分享记录
// TODO 芋艿:整理下; // TODO 芋艿:整理下;
const shareLog = uni.getStorageSync('shareLog'); // const shareLog = uni.getStorageSync('shareLog');
if (!isEmpty(shareLog)) { // if (!isEmpty(shareLog)) {
this.addShareLog({ // this.addShareLog({
...shareLog, // ...shareLog,
}); // });
} // }
}, },
// 登出系统 // 登出系统
async logout() { async logout() {
this.resetUserData(); this.resetUserData();
return !this.isLogin; return !this.isLogin;
} }
}, },
persist: { persist: {
enabled: true, enabled: true,
strategies: [{ strategies: [{
key: 'user-store', key: 'user-store',
}, ], }]
}, },
}); });
export default user; export default user;