feat:sfg
This commit is contained in:
@@ -57,7 +57,8 @@
|
||||
"usingComponents" : true
|
||||
},
|
||||
"mp-alipay" : {
|
||||
"usingComponents" : true
|
||||
"usingComponents" : true,
|
||||
"appid" : "2021006125616610"
|
||||
},
|
||||
"mp-baidu" : {
|
||||
"usingComponents" : true
|
||||
|
||||
@@ -98,30 +98,36 @@
|
||||
class="hidden-canvas"
|
||||
style="width: 600px; height: 600px"
|
||||
/>
|
||||
|
||||
<!-- Login Popup -->
|
||||
<LoginPopup ref="loginPopupRef" @logind="handleLogind" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from "vue";
|
||||
import { ref, computed } from "vue";
|
||||
import { getBavBarHeight } from "@/utils/system";
|
||||
import { useUserStore } from "@/stores/user";
|
||||
|
||||
const userStore = useUserStore();
|
||||
const loginPopupRef = ref(null);
|
||||
|
||||
const isLoggedIn = computed(() => !!userStore.userInfo.nickName);
|
||||
|
||||
const systemAvatars = [
|
||||
"https://file.lihailezzc.com/resource/1463f294244c11cf274a5eaae115872a.jpeg",
|
||||
"https://file.lihailezzc.com/20260109082842_666_1.jpg",
|
||||
"https://file.lihailezzc.com/20260108222141_644_1.jpg",
|
||||
"https://file.lihailezzc.com/9a929a32-439f-453b-b603-fda7b04cbe08.png",
|
||||
];
|
||||
const frames = [
|
||||
"https://file.lihailezzc.com/resource/0f8e6a78c1b04a4fb3a6fa1c66f1f7b3.png",
|
||||
"https://file.lihailezzc.com/resource/4a4f0c9e6e1b4c0b9f6f7a1b2c3d4e5f.png",
|
||||
"https://file.lihailezzc.com/resource/aa77f0b45b2e4a0f91c4fda74f3f1123.png",
|
||||
"https://file.lihailezzc.com/resource/bb88f0b45b2e4a0f91c4fda74f3f1199.png",
|
||||
"https://file.lihailezzc.com/6.png",
|
||||
"https://file.lihailezzc.com/7.png",
|
||||
"https://file.lihailezzc.com/yunshi.png",
|
||||
"https://file.lihailezzc.com/x_CURXRzG4wHF2dp_zu_r-removebg-preview.png",
|
||||
];
|
||||
const decors = [
|
||||
"https://file.lihailezzc.com/resource/horse_decor_01.png",
|
||||
"https://file.lihailezzc.com/resource/horse_decor_02.png",
|
||||
"https://file.lihailezzc.com/resource/horse_decor_03.png",
|
||||
"https://file.lihailezzc.com/resource/horse_decor_04.png",
|
||||
"https://file.lihailezzc.com/6.png",
|
||||
"https://file.lihailezzc.com/7.png",
|
||||
];
|
||||
|
||||
const currentAvatar = ref(systemAvatars[0]);
|
||||
@@ -129,8 +135,16 @@ const selectedFrame = ref("");
|
||||
const selectedDecor = ref("");
|
||||
const activeTab = ref("frame");
|
||||
|
||||
const handleLogind = async () => {
|
||||
// Logic after successful login if needed
|
||||
};
|
||||
|
||||
const useWeChatAvatar = () => {
|
||||
uni.showToast({ title: "已应用微信头像", icon: "none" });
|
||||
if (!isLoggedIn.value) {
|
||||
loginPopupRef.value.open();
|
||||
} else {
|
||||
currentAvatar.value = userStore.userInfo.avatarUrl;
|
||||
}
|
||||
};
|
||||
|
||||
const goBack = () => {
|
||||
|
||||
@@ -100,12 +100,28 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from "vue";
|
||||
import { ref, onUnmounted } from "vue";
|
||||
import { getBavBarHeight } from "@/utils/system";
|
||||
|
||||
const status = ref("initial"); // initial, shaking, result
|
||||
const remainingCount = ref(1);
|
||||
|
||||
// 音效控制
|
||||
const audioContext = uni.createInnerAudioContext();
|
||||
audioContext.src = "/static/music/shake.mp3";
|
||||
let playCount = 0;
|
||||
|
||||
audioContext.onEnded(() => {
|
||||
playCount++;
|
||||
if (playCount < 3) {
|
||||
audioContext.play();
|
||||
}
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
audioContext.destroy();
|
||||
});
|
||||
|
||||
const fortunes = [
|
||||
{ title: "好运连连", desc: "2026年你将万事如意,惊喜不断。", icon: "☀" },
|
||||
{ title: "财源滚滚", desc: "正财偏财滚滚来,荷包满满乐开怀。", icon: "💰" },
|
||||
@@ -132,6 +148,10 @@ const startShake = () => {
|
||||
|
||||
status.value = "shaking";
|
||||
|
||||
// 播放音效
|
||||
playCount = 0;
|
||||
audioContext.play();
|
||||
|
||||
// 模拟摇晃动画和数据请求
|
||||
setTimeout(() => {
|
||||
const idx = Math.floor(Math.random() * fortunes.length);
|
||||
|
||||
@@ -1,54 +1,54 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { wxLogin, wxGetUserProfile } from '@/utils/login.js'
|
||||
import {getPlatformProvider} from '@/utils/system'
|
||||
import { defineStore } from "pinia";
|
||||
import { wxLogin, wxGetUserProfile } from "@/utils/login.js";
|
||||
import { getPlatformProvider } from "@/utils/system";
|
||||
|
||||
export const useUserStore = defineStore('user', {
|
||||
export const useUserStore = defineStore("user", {
|
||||
state: () => ({
|
||||
token: '',
|
||||
userInfo: {}
|
||||
token: "",
|
||||
userInfo: {},
|
||||
}),
|
||||
actions: {
|
||||
setToken(token) {
|
||||
this.token = token
|
||||
uni.setStorageSync('token', token) // 持久化 tokenx
|
||||
this.token = token;
|
||||
uni.setStorageSync("token", token); // 持久化 tokenx
|
||||
},
|
||||
setUserInfo(userInfo) {
|
||||
this.userInfo = userInfo
|
||||
uni.setStorageSync('userInfo', JSON.stringify(userInfo)) // 持久化用户信息
|
||||
this.userInfo = userInfo;
|
||||
uni.setStorageSync("userInfo", JSON.stringify(userInfo)); // 持久化用户信息
|
||||
},
|
||||
loadFromStorage() {
|
||||
const token = uni.getStorageSync('token')
|
||||
const userInfoStr = uni.getStorageSync('userInfo')
|
||||
if (token) this.token = token
|
||||
const token = uni.getStorageSync("token");
|
||||
const userInfoStr = uni.getStorageSync("userInfo");
|
||||
if (token) this.token = token;
|
||||
if (userInfoStr) {
|
||||
try {
|
||||
this.userInfo = JSON.parse(userInfoStr)
|
||||
} catch {
|
||||
this.userInfo = {}
|
||||
this.userInfo = JSON.parse(userInfoStr);
|
||||
} catch (e) {
|
||||
this.userInfo = {};
|
||||
}
|
||||
}
|
||||
},
|
||||
clear() {
|
||||
this.token = ''
|
||||
this.userInfo = {}
|
||||
uni.removeStorageSync('token')
|
||||
uni.removeStorageSync('userInfo')
|
||||
this.token = "";
|
||||
this.userInfo = {};
|
||||
uni.removeStorageSync("token");
|
||||
uni.removeStorageSync("userInfo");
|
||||
},
|
||||
loadUserInfo() {
|
||||
const userStr = uni.getStorageSync('userInfo')
|
||||
if (userStr) {
|
||||
try {
|
||||
this.userInfo = JSON.parse(userStr)
|
||||
} catch (e) {
|
||||
this.userInfo = {}
|
||||
}
|
||||
}
|
||||
},
|
||||
logout() {
|
||||
this.userInfo = {}
|
||||
this.token = ''
|
||||
uni.removeStorageSync('userInfo')
|
||||
uni.removeStorageSync('token')
|
||||
}
|
||||
}
|
||||
})
|
||||
loadUserInfo() {
|
||||
const userStr = uni.getStorageSync("userInfo");
|
||||
if (userStr) {
|
||||
try {
|
||||
this.userInfo = JSON.parse(userStr);
|
||||
} catch (e) {
|
||||
this.userInfo = {};
|
||||
}
|
||||
}
|
||||
},
|
||||
logout() {
|
||||
this.userInfo = {};
|
||||
this.token = "";
|
||||
uni.removeStorageSync("userInfo");
|
||||
uni.removeStorageSync("token");
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -32,7 +32,7 @@ export const getLeftIconLeft = () => {
|
||||
|
||||
export function getPlatformProvider() {
|
||||
const platform = process.env.UNI_PLATFORM;
|
||||
return platform ?? "mp-weixin";
|
||||
return platform || "mp-weixin";
|
||||
// const platform = uni.getSystemInfoSync().platform;
|
||||
// console.log(1111111, platform)
|
||||
// // H5 模拟器调试时使用 __wxConfig 环境变量判断
|
||||
|
||||
118
utils/track.js
118
utils/track.js
@@ -1,23 +1,23 @@
|
||||
import { request } from "@/utils/request"
|
||||
import { request } from "@/utils/request";
|
||||
|
||||
// 生成并缓存 device_id
|
||||
function getOrCreateDeviceId() {
|
||||
let deviceId = uni.getStorageSync('device_id')
|
||||
let deviceId = uni.getStorageSync("device_id");
|
||||
if (!deviceId) {
|
||||
deviceId = Date.now() + '_' + Math.random().toString(36).substr(2, 9)
|
||||
uni.setStorageSync('device_id', deviceId)
|
||||
deviceId = Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
||||
uni.setStorageSync("device_id", deviceId);
|
||||
}
|
||||
return deviceId
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
// 获取网络类型
|
||||
function getNetworkType() {
|
||||
return new Promise((resolve) => {
|
||||
uni.getNetworkType({
|
||||
success: (res) => resolve(res.networkType || 'unknown'),
|
||||
fail: () => resolve('unknown')
|
||||
})
|
||||
})
|
||||
success: (res) => resolve(res.networkType || "unknown"),
|
||||
fail: () => resolve("unknown"),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 获取系统平台
|
||||
@@ -25,67 +25,71 @@ function getSystemInfo() {
|
||||
return new Promise((resolve) => {
|
||||
uni.getSystemInfo({
|
||||
success: (res) => resolve(res),
|
||||
fail: () => resolve({})
|
||||
})
|
||||
})
|
||||
fail: () => resolve({}),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 获取当前页面路径
|
||||
function getCurrentPagePath() {
|
||||
const pages = getCurrentPages()
|
||||
const currentPage = pages[pages.length - 1]
|
||||
return currentPage?.route || ''
|
||||
const pages = getCurrentPages();
|
||||
const currentPage = pages[pages.length - 1];
|
||||
return currentPage?.route || "";
|
||||
}
|
||||
|
||||
function getMiniProgramVersion() {
|
||||
const platform = process.env.UNI_PLATFORM
|
||||
let version = ''
|
||||
let envVersion = ''
|
||||
const platform = process.env.UNI_PLATFORM;
|
||||
let version = "";
|
||||
let envVersion = "";
|
||||
|
||||
try {
|
||||
if (platform === 'mp-weixin') {
|
||||
if (platform === "mp-weixin") {
|
||||
// 微信小程序
|
||||
const info = wx.getAccountInfoSync()
|
||||
version = info?.miniProgram?.version || ''
|
||||
envVersion = info?.miniProgram?.envVersion || ''
|
||||
} else if (platform === 'mp-alipay') {
|
||||
const info = wx.getAccountInfoSync();
|
||||
version = info?.miniProgram?.version || "";
|
||||
envVersion = info?.miniProgram?.envVersion || "";
|
||||
} else if (platform === "mp-alipay") {
|
||||
// 支付宝小程序
|
||||
const info = my.getAppInfoSync()
|
||||
version = info?.version || ''
|
||||
} else if (platform === 'mp-toutiao' || platform === 'mp-jd') {
|
||||
const info = my.getAppInfoSync();
|
||||
version = info?.version || "";
|
||||
} else if (platform === "mp-toutiao" || platform === "mp-jd") {
|
||||
// 抖音/头条/京东小程序
|
||||
const info = tt.getAccountInfoSync?.()
|
||||
version = info?.miniProgram?.version || ''
|
||||
envVersion = info?.miniProgram?.envVersion || ''
|
||||
} else if (platform === 'mp-baidu') {
|
||||
const info = tt.getAccountInfoSync?.();
|
||||
version = info?.miniProgram?.version || "";
|
||||
envVersion = info?.miniProgram?.envVersion || "";
|
||||
} else if (platform === "mp-baidu") {
|
||||
// 百度小程序(无标准方法获取版本号)
|
||||
version = '' // 百度不支持获取版本号
|
||||
version = ""; // 百度不支持获取版本号
|
||||
} else {
|
||||
version = ''
|
||||
version = "";
|
||||
}
|
||||
} catch (e) {
|
||||
version = ''
|
||||
envVersion = ''
|
||||
version = "";
|
||||
envVersion = "";
|
||||
}
|
||||
|
||||
return {
|
||||
platform, // 当前小程序平台
|
||||
version, // 小程序版本号
|
||||
envVersion // develop / trial / release(微信等支持)
|
||||
}
|
||||
platform, // 当前小程序平台
|
||||
version, // 小程序版本号
|
||||
envVersion, // develop / trial / release(微信等支持)
|
||||
};
|
||||
}
|
||||
|
||||
// 构造埋点对象
|
||||
async function buildEventData(eventName, eventType = 'click', customParams = {}) {
|
||||
const deviceId = getOrCreateDeviceId()
|
||||
const systemInfo = await getSystemInfo()
|
||||
const networkType = await getNetworkType()
|
||||
async function buildEventData(
|
||||
eventName,
|
||||
eventType = "click",
|
||||
customParams = {}
|
||||
) {
|
||||
const deviceId = getOrCreateDeviceId();
|
||||
const systemInfo = await getSystemInfo();
|
||||
const networkType = await getNetworkType();
|
||||
// const location = await getLocation()
|
||||
const appVersion = (typeof plus !== 'undefined') ? plus?.runtime?.version : ''
|
||||
const { envVersion, platform, version} = getMiniProgramVersion()
|
||||
const appVersion = typeof plus !== "undefined" ? plus?.runtime?.version : "";
|
||||
const { envVersion, platform, version } = getMiniProgramVersion();
|
||||
|
||||
return {
|
||||
userId: uni.getStorageSync('user_id') || null,
|
||||
userId: uni.getStorageSync("user_id") || null,
|
||||
deviceId: deviceId,
|
||||
eventName: eventName,
|
||||
eventType: eventType,
|
||||
@@ -95,23 +99,23 @@ async function buildEventData(eventName, eventType = 'click', customParams = {})
|
||||
elementContent: customParams.element_content || null,
|
||||
customParams: customParams,
|
||||
networkType: networkType,
|
||||
os: systemInfo.platform || 'unknown',
|
||||
appVersion: version || 'unknown',
|
||||
envVersion: envVersion ?? '',
|
||||
platform: platform ?? ''
|
||||
}
|
||||
os: systemInfo.platform || "unknown",
|
||||
appVersion: version || "unknown",
|
||||
envVersion: envVersion || "",
|
||||
platform: platform || "",
|
||||
};
|
||||
}
|
||||
|
||||
// 发送埋点数据到服务器
|
||||
async function sendTrack(eventName, eventType = 'click', customParams = {}) {
|
||||
async function sendTrack(eventName, eventType = "click", customParams = {}) {
|
||||
const eventData = await buildEventData(eventName, eventType, customParams);
|
||||
request({
|
||||
url: '/api/common/tracking/create',
|
||||
method: 'POST',
|
||||
data: eventData
|
||||
})
|
||||
url: "/api/common/tracking/create",
|
||||
method: "POST",
|
||||
data: eventData,
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
sendTrack
|
||||
}
|
||||
sendTrack,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user