feat: 抖音小程序开发

This commit is contained in:
2026-01-19 17:31:14 +08:00
parent 5d6db862ee
commit 388b1d1754
15 changed files with 216 additions and 113 deletions

View File

@@ -13,7 +13,25 @@
"ipLargeImageStep": 147,
"ipSmallImageStep": 117,
"ipLargeTime": 4,
"ipSmallTime": 4
"ipSmallTime": 4,
"grantType": "wechat"
},
"zhinianDY": {
"clientId": "7",
"appId": "wx5e79df5996572539",
"name": "智念",
"placeholder": "快告诉智念您在想什么~",
"loginDesc": "您好,欢迎来到智念科技",
"logo": "https://oss.nianxx.cn/mp/static/version_101/login/dh_logo.png",
"ipLargeImage": "https://oss.nianxx.cn/mp/static/version_101/dh/dh_large.png",
"ipSmallImage": "https://oss.nianxx.cn/mp/static/version_101/dh/dh_small.png",
"ipLargeImageHeight": 19687,
"ipSmallImageHeight": 3744,
"ipLargeImageStep": 147,
"ipSmallImageStep": 117,
"ipLargeTime": 4,
"ipSmallTime": 4,
"grantType": "douyin"
},
"duohua": {
"clientId": "2",
@@ -29,7 +47,8 @@
"ipLargeImageStep": 147,
"ipSmallImageStep": 117,
"ipLargeTime": 4,
"ipSmallTime": 4
"ipSmallTime": 4,
"grantType": "wechat"
},
"tianmu": {
"clientId": "4",
@@ -45,6 +64,24 @@
"ipLargeImageStep": 71,
"ipSmallImageStep": 148,
"ipLargeTime": 4,
"ipSmallTime": 6
"ipSmallTime": 6,
"grantType": "wechat"
},
"tianmuDY": {
"clientId": "7",
"appId": "wx0be424e1d22065a9",
"name": "沐沐",
"placeholder": "快告诉沐沐您在想什么~",
"loginDesc": "您好,欢迎来到天沐温泉",
"logo": "https://oss.nianxx.cn/mp/static/version_101/login/tm_logo.png",
"ipLargeImage": "https://oss.nianxx.cn/mp/static/version_101/tm/tm_large.png",
"ipSmallImage": "https://oss.nianxx.cn/mp/static/version_101/tm/tm_small.png",
"ipLargeImageHeight": 9514,
"ipSmallImageHeight": 4736,
"ipLargeImageStep": 71,
"ipSmallImageStep": 148,
"ipLargeTime": 4,
"ipSmallTime": 6,
"grantType": "douyin"
}
}

View File

@@ -1,5 +1,5 @@
{
"appid": "wx0be424e1d22065a9",
"appid": "wx5e79df5996572539",
"compileType": "miniprogram",
"libVersion": "3.8.10",
"packOptions": {

View File

@@ -67,7 +67,12 @@ const swipering = ref(false);
const animatingOut = ref(false);
let reorderTimer = null;
// #ifdef MP-TOUTIAO
const { windowWidth } = tt.getSystemInfoSync();
// #endif
// #ifdef MP-WEIXIN
const { windowWidth } = uni.getWindowInfo();
// #endif
let uidCounter = 0;
// 始终生成全局唯一的 __uid避免因重复 key 导致后续卡片无法正确重渲染与绑定事件

View File

@@ -1,37 +1,23 @@
<template>
<view :class="navBarClass" :style="navBarStyle">
<!-- 状态栏占位 -->
<view
:style="{ height: statusBarHeight + 'px' }"
v-if="!hideStatusBar"
></view>
<view :style="{ height: statusBarHeight + 'px' }" v-if="!hideStatusBar"></view>
<!-- 导航栏内容 -->
<view
class="flex flex-items-center flex-justify-between border-box pl-8 pr-8"
:style="{ height: navBarHeight + 'px' }"
>
<view class="flex flex-items-center flex-justify-between border-box pl-8 pr-8"
:style="{ height: navBarHeight + 'px' }">
<!-- 左侧返回按钮 -->
<view
class="nav-bar-left flex flex-items-center flex-justify-center"
v-if="showBack"
@click="handleBack"
>
<view class="nav-bar-left flex flex-items-center flex-justify-center" v-if="showBack" @click="handleBack">
<uni-icons type="left" size="20" :color="backIconColor" />
</view>
<!-- 中间标题区域 -->
<view
:class="[
<view :class="[
'nav-bar-center flex flex-items-center flex-justify-center',
`nav-bar-center--${titleAlign}`,
]"
>
]">
<slot name="title">
<text
class="font-size-17 font-500 color-000"
:style="{ color: titleColor }"
>
<text class="font-size-17 font-500 color-000" :style="{ color: titleColor }">
{{ title }}
</text>
</slot>
@@ -107,7 +93,13 @@ const navBarHeight = ref(44); // 默认导航栏高度
// 获取系统信息
onMounted(() => {
const systemInfo = uni.getSystemInfoSync();
// #ifdef MP-TOUTIAO
const systemInfo = tt.getSystemInfoSync();
// #endif
// #ifdef MP-WEIXIN
const systemInfo = uni.getWindowInfo();
// #endif
statusBarHeight.value = systemInfo.statusBarHeight || 0;
// 根据平台设置导航栏高度

View File

@@ -12,8 +12,9 @@ import rawConfigs from '../../client-configs.json' with { type: 'json' };
export const CLIENT_CONFIGS = rawConfigs;
// 获取当前用户端配置
export const getCurrentConfig = () => CLIENT_CONFIGS.tianmu;
export const getCurrentConfig = () => CLIENT_CONFIGS.zhinianDY;
export const clientId = getCurrentConfig().clientId;
export const grantType = getCurrentConfig().grantType;
export const appId = getCurrentConfig().appId;

View File

@@ -1,6 +1,6 @@
import { oauthToken, checkUserPhone } from "@/request/api/LoginApi";
import { loginAuth, bindPhone } from "@/manager/LoginManager";
import { clientId } from "@/constant/base";
import { clientId, grantType } from "@/constant/base";
import { getAccessToken, removeAccessToken, setAccessToken } from "../constant/token";
import { NOTICE_EVENT_LOGIN_SUCCESS } from "@/constant/constant";
@@ -70,13 +70,19 @@ export const checkToken = () => {
// 刷新token
export const refreshToken = () => {
return new Promise(async (resolve) => {
uni.getProvider({
service: 'oauth',
success: function (res) {
// 获取客户端类型
console.log('获取客户端类型:', res.provider)
uni.login({
provider: "weixin", //使用微信登录
provider: res.provider, //使用微信登录
success: async ({ code }) => {
console.log("进入 refreshToken success", code);
console.log("进入 refreshToken success code:", code);
// console.log("进入 refreshToken success anonymousCode:", anonymousCode);
const params = {
openIdCode: [code],
grant_type: "wechat",
grant_type: grantType,
scope: "server",
clientId: clientId,
};
@@ -100,5 +106,7 @@ export const refreshToken = () => {
}
},
});
}
});
});
};

View File

@@ -60,7 +60,7 @@
wx23f86d809ae80259
*/
"mp-weixin": {
"appid": "wx0be424e1d22065a9",
"appid": "wx5e79df5996572539",
"setting": {
"urlCheck": false,
"minified": true

View File

@@ -16,10 +16,12 @@
<text class="amt font-size-18 font-500 font-family-misans-vf line-height-24 color-FF3D60 mr-4">
{{ item.specificationPrice }}
</text>
<!-- #ifdef MP-WEIXIN -->
<text class="font-size-12 line-height-16 color-99A0AE">
/{{ item.stockUnitLabel }}
</text>
<text class="btn border-box rounded-10 color-white ml-16" @click.stop="handleBooking(item)"></text>
<!-- #endif -->
</view>
</view>
</view>

View File

@@ -49,7 +49,7 @@
>
{{ calculatedTotalPrice }}
</view>
<!-- #ifdef MP-WEIXIN -->
<view
class="btn border-box rounded-10 flex flex-items-center ml-auto pl-8"
@click="navigateToPay(goodsData)"
@@ -60,8 +60,10 @@
/>
<text class="font-size-16 font-500 color-white">立即预定</text>
</view>
<!-- #endif -->
</view>
<!-- 日历组件 -->
<Calender
:visible="calendarVisible"

View File

@@ -180,6 +180,7 @@ const initRecord = () => {
// 监听键盘高度变化
onMounted(() => {
// 监听键盘弹起
// #ifdef MP-WEIXIN
uni.onKeyboardHeightChange((res) => {
keyboardHeight.value = res.height;
if (res.height) {
@@ -188,8 +189,8 @@ onMounted(() => {
emit("keyboardHide");
}
});
initRecord();
// #endif
});
const sendMessage = () => {

View File

@@ -296,11 +296,19 @@ const addNoticeListener = () => {
/// =============生命周期函数↓================
onLoad(() => {
uni.getSystemInfo({
success: (res) => {
statusBarHeight.value = res.statusBarHeight || 20;
},
});
console.log(21212121212)
nextTick(() => {
// #ifdef MP-TOUTIAO
const systemInfo = tt.getSystemInfoSync();
// #endif
// #ifdef MP-WEIXIN
const systemInfo = uni.getWindowInfo();
// #endif
statusBarHeight.value = systemInfo.statusBarHeight || 20;
console.log(1213213123, statusBarHeight.value, systemInfo.statusBarHeight)
})
});
// token存在初始化数据

View File

@@ -38,8 +38,9 @@
</button>
<!-- #endif -->
<!-- #ifdef MP-TOUTIAO -->
<button class="login-btn" type="primary" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumberHandler"
bindtap="bindPhone">登录</button>
<!-- <button class="login-btn" type="primary" open-type="getPhoneNumber" @getphonenumber="getPhoneNumberHandler"
@bindtap="bindPhone">登录</button> -->
<button class="login-btn" type="primary" @click="loginhandle">登录</button>
<!-- #endif -->
</view>
@@ -107,9 +108,13 @@ const getPhoneNumber = (e) => {
};
const getPhoneNumberHandler = (e) => {
console.log(e.detail.errMsg);
console.log(e.detail.iv);
console.log(e.detail.encryptedData);
console.log('getphonenumber:', e)
// console.log(e.detail.errMsg);
// console.log(e.detail.iv);
// console.log(e.detail.encryptedData);
}
const bindPhone = (e) => {
console.log('bindPhone:', e)
}
// 抖音登录获取code
@@ -188,10 +193,35 @@ getPrivacyAgreementData();
// 页面显示时刷新token
onShow(async () => {
loginDy();
// #ifdef MP-TOUTIAO
// loginDy();
// #endif
// #ifdef MP-WEIXIN
loginhandle();
// #endif
});
const loginhandle = async () => {
// 如果需要微信登录,直接返回
// #ifdef MP-TOUTIAO
if (!isAgree.value) {
uni.showToast({
title: "请先同意服务协议和隐私协议",
icon: "none",
});
return;
}
// #endif
const res = await refreshToken();
needWxAuthLogin.value = res;
});
// #ifdef MP-TOUTIAO
loginSuccess();
// #endif
};
</script>

View File

@@ -151,7 +151,9 @@ export default {
},
mounted () {
this.$nextTick(() => {
if (this.root) {
for (this.root = this.$parent; this.root.$options.name !== 'mp-html'; this.root = this.root.$parent);
}
})
// #ifdef H5 || APP-PLUS
if (this.opts[0]) {

View File

@@ -77,18 +77,31 @@ const config = {
}
const tagSelector = {}
let windowWidth, system
// #ifdef MP-TOUTIAO
const systemInfo = tt.getSystemInfoSync()
windowWidth = systemInfo.windowWidth
system = systemInfo.system
// #endif
// #ifdef MP-WEIXIN
if (uni.canIUse('getWindowInfo')) {
windowWidth = uni.getWindowInfo().windowWidth
system = uni.getDeviceInfo().system
} else {
// #endif
if (uni.canIUse('getWindowInfo')) {
// #ifdef MP-WEIXIN
windowWidth = uni.getWindowInfo().windowWidth
system = uni.getDeviceInfo().system
// #endif
} else {
// #ifdef MP-WEIXIN
const systemInfo = uni.getSystemInfoSync()
windowWidth = systemInfo.windowWidth
// #ifdef MP-WEIXIN
system = systemInfo.system
}
// #endif
}
const blankChar = makeMap(' ,\r,\n,\t,\f')
let idIndex = 0

View File

@@ -8,7 +8,9 @@ export default {
if (allowShare) {
uni.showShareMenu({
withShareTicket: true,
// #ifdef MP-WEIXIN
menus: ["shareAppMessage", "shareTimeline"],
// #endif
});
}
},