This commit is contained in:
zzc
2026-01-16 15:09:19 +08:00
parent 67684572da
commit 9d5b9b6812
6 changed files with 148 additions and 109 deletions

View File

@@ -57,7 +57,8 @@
"usingComponents" : true "usingComponents" : true
}, },
"mp-alipay" : { "mp-alipay" : {
"usingComponents" : true "usingComponents" : true,
"appid" : "2021006125616610"
}, },
"mp-baidu" : { "mp-baidu" : {
"usingComponents" : true "usingComponents" : true

View File

@@ -98,30 +98,36 @@
class="hidden-canvas" class="hidden-canvas"
style="width: 600px; height: 600px" style="width: 600px; height: 600px"
/> />
<!-- Login Popup -->
<LoginPopup ref="loginPopupRef" @logind="handleLogind" />
</view> </view>
</template> </template>
<script setup> <script setup>
import { ref } from "vue"; import { ref, computed } from "vue";
import { getBavBarHeight } from "@/utils/system"; 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 = [ const systemAvatars = [
"https://file.lihailezzc.com/resource/1463f294244c11cf274a5eaae115872a.jpeg",
"https://file.lihailezzc.com/20260109082842_666_1.jpg", "https://file.lihailezzc.com/20260109082842_666_1.jpg",
"https://file.lihailezzc.com/20260108222141_644_1.jpg", "https://file.lihailezzc.com/20260108222141_644_1.jpg",
"https://file.lihailezzc.com/9a929a32-439f-453b-b603-fda7b04cbe08.png", "https://file.lihailezzc.com/9a929a32-439f-453b-b603-fda7b04cbe08.png",
]; ];
const frames = [ const frames = [
"https://file.lihailezzc.com/resource/0f8e6a78c1b04a4fb3a6fa1c66f1f7b3.png", "https://file.lihailezzc.com/6.png",
"https://file.lihailezzc.com/resource/4a4f0c9e6e1b4c0b9f6f7a1b2c3d4e5f.png", "https://file.lihailezzc.com/7.png",
"https://file.lihailezzc.com/resource/aa77f0b45b2e4a0f91c4fda74f3f1123.png", "https://file.lihailezzc.com/yunshi.png",
"https://file.lihailezzc.com/resource/bb88f0b45b2e4a0f91c4fda74f3f1199.png", "https://file.lihailezzc.com/x_CURXRzG4wHF2dp_zu_r-removebg-preview.png",
]; ];
const decors = [ const decors = [
"https://file.lihailezzc.com/resource/horse_decor_01.png", "https://file.lihailezzc.com/6.png",
"https://file.lihailezzc.com/resource/horse_decor_02.png", "https://file.lihailezzc.com/7.png",
"https://file.lihailezzc.com/resource/horse_decor_03.png",
"https://file.lihailezzc.com/resource/horse_decor_04.png",
]; ];
const currentAvatar = ref(systemAvatars[0]); const currentAvatar = ref(systemAvatars[0]);
@@ -129,8 +135,16 @@ const selectedFrame = ref("");
const selectedDecor = ref(""); const selectedDecor = ref("");
const activeTab = ref("frame"); const activeTab = ref("frame");
const handleLogind = async () => {
// Logic after successful login if needed
};
const useWeChatAvatar = () => { const useWeChatAvatar = () => {
uni.showToast({ title: "已应用微信头像", icon: "none" }); if (!isLoggedIn.value) {
loginPopupRef.value.open();
} else {
currentAvatar.value = userStore.userInfo.avatarUrl;
}
}; };
const goBack = () => { const goBack = () => {

View File

@@ -100,12 +100,28 @@
</template> </template>
<script setup> <script setup>
import { ref } from "vue"; import { ref, onUnmounted } from "vue";
import { getBavBarHeight } from "@/utils/system"; import { getBavBarHeight } from "@/utils/system";
const status = ref("initial"); // initial, shaking, result const status = ref("initial"); // initial, shaking, result
const remainingCount = ref(1); 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 = [ const fortunes = [
{ title: "好运连连", desc: "2026年你将万事如意惊喜不断。", icon: "☀" }, { title: "好运连连", desc: "2026年你将万事如意惊喜不断。", icon: "☀" },
{ title: "财源滚滚", desc: "正财偏财滚滚来,荷包满满乐开怀。", icon: "💰" }, { title: "财源滚滚", desc: "正财偏财滚滚来,荷包满满乐开怀。", icon: "💰" },
@@ -132,6 +148,10 @@ const startShake = () => {
status.value = "shaking"; status.value = "shaking";
// 播放音效
playCount = 0;
audioContext.play();
// 模拟摇晃动画和数据请求 // 模拟摇晃动画和数据请求
setTimeout(() => { setTimeout(() => {
const idx = Math.floor(Math.random() * fortunes.length); const idx = Math.floor(Math.random() * fortunes.length);

View File

@@ -1,54 +1,54 @@
import { defineStore } from 'pinia' import { defineStore } from "pinia";
import { wxLogin, wxGetUserProfile } from '@/utils/login.js' import { wxLogin, wxGetUserProfile } from "@/utils/login.js";
import {getPlatformProvider} from '@/utils/system' import { getPlatformProvider } from "@/utils/system";
export const useUserStore = defineStore('user', { export const useUserStore = defineStore("user", {
state: () => ({ state: () => ({
token: '', token: "",
userInfo: {} userInfo: {},
}), }),
actions: { actions: {
setToken(token) { setToken(token) {
this.token = token this.token = token;
uni.setStorageSync('token', token) // 持久化 tokenx uni.setStorageSync("token", token); // 持久化 tokenx
}, },
setUserInfo(userInfo) { setUserInfo(userInfo) {
this.userInfo = userInfo this.userInfo = userInfo;
uni.setStorageSync('userInfo', JSON.stringify(userInfo)) // 持久化用户信息 uni.setStorageSync("userInfo", JSON.stringify(userInfo)); // 持久化用户信息
}, },
loadFromStorage() { loadFromStorage() {
const token = uni.getStorageSync('token') const token = uni.getStorageSync("token");
const userInfoStr = uni.getStorageSync('userInfo') const userInfoStr = uni.getStorageSync("userInfo");
if (token) this.token = token if (token) this.token = token;
if (userInfoStr) { if (userInfoStr) {
try { try {
this.userInfo = JSON.parse(userInfoStr) this.userInfo = JSON.parse(userInfoStr);
} catch { } catch (e) {
this.userInfo = {} this.userInfo = {};
} }
} }
}, },
clear() { clear() {
this.token = '' this.token = "";
this.userInfo = {} this.userInfo = {};
uni.removeStorageSync('token') uni.removeStorageSync("token");
uni.removeStorageSync('userInfo') uni.removeStorageSync("userInfo");
}, },
loadUserInfo() { loadUserInfo() {
const userStr = uni.getStorageSync('userInfo') const userStr = uni.getStorageSync("userInfo");
if (userStr) { if (userStr) {
try { try {
this.userInfo = JSON.parse(userStr) this.userInfo = JSON.parse(userStr);
} catch (e) { } catch (e) {
this.userInfo = {} this.userInfo = {};
} }
} }
}, },
logout() { logout() {
this.userInfo = {} this.userInfo = {};
this.token = '' this.token = "";
uni.removeStorageSync('userInfo') uni.removeStorageSync("userInfo");
uni.removeStorageSync('token') uni.removeStorageSync("token");
} },
} },
}) });

View File

@@ -32,7 +32,7 @@ export const getLeftIconLeft = () => {
export function getPlatformProvider() { export function getPlatformProvider() {
const platform = process.env.UNI_PLATFORM; const platform = process.env.UNI_PLATFORM;
return platform ?? "mp-weixin"; return platform || "mp-weixin";
// const platform = uni.getSystemInfoSync().platform; // const platform = uni.getSystemInfoSync().platform;
// console.log(1111111, platform) // console.log(1111111, platform)
// // H5 模拟器调试时使用 __wxConfig 环境变量判断 // // H5 模拟器调试时使用 __wxConfig 环境变量判断

View File

@@ -1,23 +1,23 @@
import { request } from "@/utils/request" import { request } from "@/utils/request";
// 生成并缓存 device_id // 生成并缓存 device_id
function getOrCreateDeviceId() { function getOrCreateDeviceId() {
let deviceId = uni.getStorageSync('device_id') let deviceId = uni.getStorageSync("device_id");
if (!deviceId) { if (!deviceId) {
deviceId = Date.now() + '_' + Math.random().toString(36).substr(2, 9) deviceId = Date.now() + "_" + Math.random().toString(36).substr(2, 9);
uni.setStorageSync('device_id', deviceId) uni.setStorageSync("device_id", deviceId);
} }
return deviceId return deviceId;
} }
// 获取网络类型 // 获取网络类型
function getNetworkType() { function getNetworkType() {
return new Promise((resolve) => { return new Promise((resolve) => {
uni.getNetworkType({ uni.getNetworkType({
success: (res) => resolve(res.networkType || 'unknown'), success: (res) => resolve(res.networkType || "unknown"),
fail: () => resolve('unknown') fail: () => resolve("unknown"),
}) });
}) });
} }
// 获取系统平台 // 获取系统平台
@@ -25,67 +25,71 @@ function getSystemInfo() {
return new Promise((resolve) => { return new Promise((resolve) => {
uni.getSystemInfo({ uni.getSystemInfo({
success: (res) => resolve(res), success: (res) => resolve(res),
fail: () => resolve({}) fail: () => resolve({}),
}) });
}) });
} }
// 获取当前页面路径 // 获取当前页面路径
function getCurrentPagePath() { function getCurrentPagePath() {
const pages = getCurrentPages() const pages = getCurrentPages();
const currentPage = pages[pages.length - 1] const currentPage = pages[pages.length - 1];
return currentPage?.route || '' return currentPage?.route || "";
} }
function getMiniProgramVersion() { function getMiniProgramVersion() {
const platform = process.env.UNI_PLATFORM const platform = process.env.UNI_PLATFORM;
let version = '' let version = "";
let envVersion = '' let envVersion = "";
try { try {
if (platform === 'mp-weixin') { if (platform === "mp-weixin") {
// 微信小程序 // 微信小程序
const info = wx.getAccountInfoSync() const info = wx.getAccountInfoSync();
version = info?.miniProgram?.version || '' version = info?.miniProgram?.version || "";
envVersion = info?.miniProgram?.envVersion || '' envVersion = info?.miniProgram?.envVersion || "";
} else if (platform === 'mp-alipay') { } else if (platform === "mp-alipay") {
// 支付宝小程序 // 支付宝小程序
const info = my.getAppInfoSync() const info = my.getAppInfoSync();
version = info?.version || '' version = info?.version || "";
} else if (platform === 'mp-toutiao' || platform === 'mp-jd') { } else if (platform === "mp-toutiao" || platform === "mp-jd") {
// 抖音/头条/京东小程序 // 抖音/头条/京东小程序
const info = tt.getAccountInfoSync?.() const info = tt.getAccountInfoSync?.();
version = info?.miniProgram?.version || '' version = info?.miniProgram?.version || "";
envVersion = info?.miniProgram?.envVersion || '' envVersion = info?.miniProgram?.envVersion || "";
} else if (platform === 'mp-baidu') { } else if (platform === "mp-baidu") {
// 百度小程序(无标准方法获取版本号) // 百度小程序(无标准方法获取版本号)
version = '' // 百度不支持获取版本号 version = ""; // 百度不支持获取版本号
} else { } else {
version = '' version = "";
} }
} catch (e) { } catch (e) {
version = '' version = "";
envVersion = '' envVersion = "";
} }
return { return {
platform, // 当前小程序平台 platform, // 当前小程序平台
version, // 小程序版本号 version, // 小程序版本号
envVersion // develop / trial / release微信等支持 envVersion, // develop / trial / release微信等支持
} };
} }
// 构造埋点对象 // 构造埋点对象
async function buildEventData(eventName, eventType = 'click', customParams = {}) { async function buildEventData(
const deviceId = getOrCreateDeviceId() eventName,
const systemInfo = await getSystemInfo() eventType = "click",
const networkType = await getNetworkType() customParams = {}
) {
const deviceId = getOrCreateDeviceId();
const systemInfo = await getSystemInfo();
const networkType = await getNetworkType();
// const location = await getLocation() // const location = await getLocation()
const appVersion = (typeof plus !== 'undefined') ? plus?.runtime?.version : '' const appVersion = typeof plus !== "undefined" ? plus?.runtime?.version : "";
const { envVersion, platform, version} = getMiniProgramVersion() const { envVersion, platform, version } = getMiniProgramVersion();
return { return {
userId: uni.getStorageSync('user_id') || null, userId: uni.getStorageSync("user_id") || null,
deviceId: deviceId, deviceId: deviceId,
eventName: eventName, eventName: eventName,
eventType: eventType, eventType: eventType,
@@ -95,23 +99,23 @@ async function buildEventData(eventName, eventType = 'click', customParams = {})
elementContent: customParams.element_content || null, elementContent: customParams.element_content || null,
customParams: customParams, customParams: customParams,
networkType: networkType, networkType: networkType,
os: systemInfo.platform || 'unknown', os: systemInfo.platform || "unknown",
appVersion: version || 'unknown', appVersion: version || "unknown",
envVersion: envVersion ?? '', envVersion: envVersion || "",
platform: platform ?? '' platform: platform || "",
} };
} }
// 发送埋点数据到服务器 // 发送埋点数据到服务器
async function sendTrack(eventName, eventType = 'click', customParams = {}) { async function sendTrack(eventName, eventType = "click", customParams = {}) {
const eventData = await buildEventData(eventName, eventType, customParams); const eventData = await buildEventData(eventName, eventType, customParams);
request({ request({
url: '/api/common/tracking/create', url: "/api/common/tracking/create",
method: 'POST', method: "POST",
data: eventData data: eventData,
}) });
} }
export default { export default {
sendTrack sendTrack,
} };