抖音小程序试水

This commit is contained in:
shikong 2024-11-08 20:22:58 +08:00
parent 3f1abfa35f
commit 5857e62e49
Signed by: Shikong
GPG Key ID: BD85FF18B373C341
7 changed files with 5843 additions and 4575 deletions

View File

@ -6,6 +6,10 @@
{
"launchtype" : "local"
},
"mp-toutiao" :
{
"launchtype" : "local"
},
"mp-weixin" :
{
"launchtype" : "local"

View File

@ -61,7 +61,6 @@
"@dcloudio/uni-ui": "^1.5.6",
"crypto-js": "^3.3.0",
"destr": "^2.0.3",
"moment": "^2.30.1",
"pinia": "^2.2.4",
"pinia-plugin-persistedstate": "^3.2.1",
"qs": "6.7.0",

File diff suppressed because it is too large Load Diff

View File

@ -31,6 +31,23 @@ export default {
}
});
//#endif
// #ifdef MP-TOUTIAO
uni.login({
provider: 'toutiao', //使
onlyAuthorize: false, //
success(loginRes){
console.log("登录信息", loginRes)
uni.getUserInfo({
provider: 'toutiao',
success(userInfoRes){
console.log("用户信息", userInfoRes)
}
})
}
});
// #endif
},
onShow: function () {
console.log('App Show')

View File

@ -1,13 +1,13 @@
<template>
<view class="flex flex-col h-full">
<NavBar/>
<NavBar />
<view class="flex-1 flex-grow-1 min-h-0 content overflow-auto">
<Banner/>
<Banner />
<HotPanel/>
<HotPanel />
<ZhiHuHotList/>
<ZhiHuHotList />
<view class="text-center">
<text class="title">{{ title }}</text>
@ -20,13 +20,13 @@
</template>
<script>
import moment from 'moment'
import NavBar from "./components/nav-bar/index.vue"
import Banner from "./components/banner/index.vue"
import HotPanel from "./components/hot-panel/index.vue"
import ZhiHuHotList from "./components/zhihu-hot-list/index.vue"
let timer = null
export default {
// import moment from 'moment'
import NavBar from "./components/nav-bar/index.vue"
import Banner from "./components/banner/index.vue"
import HotPanel from "./components/hot-panel/index.vue"
import ZhiHuHotList from "./components/zhihu-hot-list/index.vue"
let timer = null
export default {
components: {
NavBar,
Banner,
@ -35,8 +35,8 @@ export default {
},
data() {
return {
now: moment().format('YYYY-MM-DD HH:mm:ss'),
now: new Date().toTimeString(),
// now: moment().format('YYYY-MM-DD HH:mm:ss'),
title: 'Hello',
}
},
@ -45,33 +45,34 @@ export default {
},
mounted() {
if(timer){
if (timer) {
clearInterval(timer)
}
timer = setInterval(() => {
this.now = new moment().format('YYYY-MM-DD HH:mm:ss')
// this.now = new moment().format('YYYY-MM-DD HH:mm:ss')
this.now = new Date().toTimeString()
}, 1000)
},
methods: {
}
}
}
</script>
<style>
.banner {
.banner {
width: 750rpx;
height: 420rpx;
}
}
.content {
.content {
display: flex;
flex-direction: column;
}
}
.title {
.title {
font-size: 36rpx;
color: #8f8f94;
}
}
</style>

View File

@ -7,7 +7,9 @@
<button class="avatar-wrapper" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
<image class="avatar" :src="ctx.avatarUrl"></image>
</button>
<input class="uni-input" placeholder="请输入昵称"/>
<input class="uni-input" placeholder="请输入昵称" />
<button type="primary" @tap="getUserProfile" data-eventsync="true">获取用户信息</button>
</view>
<view class="warp">
@ -27,26 +29,39 @@
</template>
<script setup>
import {reactive, watchEffect} from "vue"
import {useI18n} from "vue-i18n"
import {onReady} from "@dcloudio/uni-app";
const {t, locale} = useI18n()
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
import {
reactive,
watchEffect
} from "vue"
import {
useI18n
} from "vue-i18n"
import {
onReady
} from "@dcloudio/uni-app";
const {
t,
locale
} = useI18n()
const defaultAvatarUrl =
'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
const ctx = reactive({
const ctx = reactive({
lang: {
switchTo: ''
},
avatarUrl: defaultAvatarUrl,
})
})
function onChooseAvatar(e) {
const { avatarUrl } = e.detail
function onChooseAvatar(e) {
const {
avatarUrl
} = e.detail
ctx.avatarUrl = avatarUrl
}
}
function switchLanguage(){
if(uni.getLocale().startsWith("en")){
function switchLanguage() {
if (uni.getLocale().startsWith("en")) {
uni.setLocale("zh-Hans")
locale.value = "zh-Hans"
} else {
@ -58,38 +73,38 @@ function switchLanguage(){
title: t("pages.my")
})
console.log(uni.getLocale())
}
}
function initLanguage(){
if(uni.getLocale().startsWith("en")){
function initLanguage() {
if (uni.getLocale().startsWith("en")) {
ctx.lang.switchTo = "language.zhHans"
} else {
ctx.lang.switchTo = "language.en"
}
}
}
watchEffect(()=>{
watchEffect(() => {
initLanguage()
})
})
onReady(()=>{
onReady(() => {
initLanguage()
uni.setNavigationBarTitle({
title: t("pages.my")
})
})
})
function toTestPage(){
function toTestPage() {
uni.navigateTo({
url: '/sub-packages/test-page/pages/test-page',
animationDuration: 100
})
}
}
function getLocation(){
function getLocation() {
uni.getLocation({
type: "wgs84",
success: function (res) {
success: function(res) {
console.log(`当前位置: ${res.longitude},${res.latitude}`)
uni.showModal({
title: '获取位置成功',
@ -97,7 +112,7 @@ function getLocation(){
showCancel: false
})
},
fail: function (err) {
fail: function(err) {
console.log(err, `获取位置失败: ${err.errMsg}`)
uni.showModal({
title: '获取位置失败',
@ -106,14 +121,28 @@ function getLocation(){
})
}
})
}
}
function getUserProfile() {
uni.getUserProfile({
desc: '获取你的昵称、头像、地区及性别',
success(profileRes) {
console.log("用户资料", profileRes)
ctx.avatarUrl = profileRes.userInfo.avatarUrl
},
fail(res) {
console.error("用户资料获取失败", res)
}
})
}
</script>
<style>
.warp {
.warp {
padding: 5rpx;
}
.button {
}
.button {
margin-bottom: 10px;
}
}
</style>

View File

@ -1,8 +1,15 @@
import path from "path";
import {fileURLToPath, URL} from 'node:url'
import { defineConfig } from 'vite'
import {
fileURLToPath,
URL
} from 'node:url'
import {
defineConfig
} from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import { UnifiedViteWeappTailwindcssPlugin as uvwt } from "weapp-tailwindcss/vite";
import {
UnifiedViteWeappTailwindcssPlugin as uvwt
} from "weapp-tailwindcss/vite";
// 注意: 打包成 h5 和 app 都不需要开启插件配置
const isH5 = process.env.UNI_PLATFORM === "h5";
const isApp = process.env.UNI_PLATFORM === "app";
@ -12,7 +19,7 @@ const resolve = (p) => {
};
// https://vitejs.dev/config/
export default defineConfig({
build:{
build: {
},
plugins: [
@ -22,6 +29,11 @@ export default defineConfig({
disabled: weAppTailwindcssDisabled
})
],
define: {
__VUE_I18N_FULL_INSTALL__: JSON.stringify(true),
__VUE_I18N_LEGACY_API__: JSON.stringify(false),
__INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false),
},
css: {
postcss: {
plugins: [