Commit 7efe0ec2 by Jaxon

chore: stylelint 配置支持小程序与uniapp的特殊rpx值与特有的选择器

1 parent a4bc4cbc
Showing 152 changed files with 1404 additions and 1370 deletions
......@@ -3,3 +3,4 @@ public
__tests__
coverage
miniprogram_npm
uni_modules
......@@ -36,33 +36,33 @@
"source.fixAll.stylelint": "explicit",
"source.organizeImports": "never"
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[scss]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[vue]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
// extensions
"extensions.ignoreRecommendations": true,
......@@ -107,19 +107,22 @@
"**/.git/subtree-cache/**": true,
"**/.vscode/**": true,
"**/node_modules/**": true,
"**/uni_modules/**": true,
"**/miniprogram_npm/**": true,
"**/tmp/**": true,
"**/bower_components/**": true,
"**/dist/**": true,
"**/yarn.lock": true
},
"typescript.tsserver.exclude": ["**/node_modules", "**/dist", "**/.turbo"],
"typescript.tsserver.exclude": ["**/node_modules", "**/dist", "**/.turbo","**/uni_modules","**/miniprogram_npm"],
// search
"search.searchEditor.singleClickBehaviour": "peekDefinition",
"search.followSymlinks": false,
// 在使用搜索功能时,将这些文件夹/文件排除在外
"search.exclude": {
"**/uni_modules": true,
"**/miniprogram_npm":true,
"**/node_modules": true,
"**/*.log": true,
......@@ -226,5 +229,15 @@
"vue.server.hybridMode": true,
"typescript.tsdk": "node_modules/typescript/lib",
"oxc.enable": false,
"cSpell.words": ["archiver", "axios", "dotenv", "isequal", "jspm", "napi", "nolebase", "rollup", "vitest"]
"cSpell.words": [
"archiver",
"axios",
"dotenv",
"isequal",
"jspm",
"napi",
"nolebase",
"rollup",
"vitest"
]
}
---
name: Bug report(报告问题)
about: Create a report to help us improve
---
<!--
注意:为更好的解决你的问题,请参考模板提供完整信息,准确描述问题,信息不全的 issue 将被关闭。
Note: In order to better solve your problem, please refer to the template to provide complete information, accurately describe the problem, and the incomplete information issue will be closed.
-->
# Bug report(问题描述)
please write your issue description here
## Steps to reproduce(问题复现步骤)
<!--
1. [xxx]
2. [xxx]
3. [xxxx]
-->
## Screenshot or Gif(截图或动态图)
## minimal reproduction(最小可还原代码)
## System Info
`npx envinfo --system --npmPackages vue --binaries --browsers`
执行上面命令,将结果贴下面
---
name: Feature Request(新功能建议)
about: Suggest an idea for this project
---
# Feature request(新功能建议)
name: Deploy Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ['main']
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
jobs:
# Build job
build:
runs-on: ubuntu-latest
steps:
# 设置服务器时区为东八区
- name: Set time zone
run: sudo timedatectl set-timezone 'Asia/Shanghai'
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'pnpm'
- name: Install dependencies
run: pnpm i --no-frozen-lockfile
- name: Build
run: pnpm build:h5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./dist/build/h5
# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
import path from "node:path";
import process from "node:process";
// manifest.config.ts
import { defineManifestConfig } from '@uni-helper/vite-plugin-uni-manifest'
import path from 'node:path'
import { loadEnv } from 'vite'
import { defineManifestConfig } from "@uni-helper/vite-plugin-uni-manifest";
import { loadEnv } from "vite";
// 获取环境变量的范例
const env = loadEnv(process.env.NODE_ENV!, path.resolve(process.cwd(), 'env'))
const env = loadEnv(process.env.NODE_ENV ?? "development", path.resolve(process.cwd(), "env"));
// console.log('manifest.config.ts')
// console.log(env)
const {
......@@ -13,14 +15,14 @@ const {
VITE_WX_APPID,
VITE_APP_PUBLIC_BASE,
VITE_FALLBACK_LOCALE,
} = env
} = env;
export default defineManifestConfig({
name: VITE_APP_TITLE,
appid: VITE_UNI_APPID,
description: '',
versionName: '1.0.0',
versionCode: '100',
description: "",
versionName: "1.0.0",
versionCode: "100",
transformPx: false,
locale: VITE_FALLBACK_LOCALE, // 'zh-Hans'
h5: {
......@@ -29,9 +31,9 @@ export default defineManifestConfig({
},
},
/* 5+App特有相关 */
'app-plus': {
"app-plus": {
usingComponents: true,
nvueStyleCompiler: 'uni-app',
nvueStyleCompiler: "uni-app",
compilerVersion: 3,
splashscreen: {
alwaysShowBeforeRender: true,
......@@ -47,7 +49,7 @@ export default defineManifestConfig({
android: {
minSdkVersion: 30,
targetSdkVersion: 30,
abiFilters: ['armeabi-v7a', 'arm64-v8a'],
abiFilters: [ "armeabi-v7a", "arm64-v8a" ],
permissions: [
'<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>',
'<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>',
......@@ -80,7 +82,7 @@ export default defineManifestConfig({
/* 快应用特有相关 */
quickapp: {},
/* 小程序特有相关 */
'mp-weixin': {
"mp-weixin": {
appid: VITE_WX_APPID,
setting: {
urlCheck: false,
......@@ -88,17 +90,17 @@ export default defineManifestConfig({
usingComponents: true,
// __usePrivacyCheck__: true,
},
'mp-alipay': {
"mp-alipay": {
usingComponents: true,
},
'mp-baidu': {
"mp-baidu": {
usingComponents: true,
},
'mp-toutiao': {
"mp-toutiao": {
usingComponents: true,
},
uniStatistics: {
enable: false,
},
vueVersion: '3',
})
vueVersion: "3",
});
import { createProdMockServer } from 'vite-plugin-mock/client'
const modules = import.meta.glob('/mock/**/*.ts', { eager: true })
const mockModules: any[] = []
Object.keys(modules).forEach((key) => {
if (key.includes('/_')) {
return
}
mockModules.push(...(modules as Recordable)[key].default)
})
console.log('mockModules -> ', mockModules)
/**
* Used in a production environment. Need to manually import all modules
*/
export function setupProdMockServer() {
createProdMockServer(mockModules)
}
// test.ts
import { MockMethod, MockConfig } from 'vite-plugin-mock'
export default [
{
url: '/api/get',
method: 'get',
response: ({ query }) => {
return {
code: 0,
data: {
name: '菲鸽',
},
}
},
},
{
url: '/api/post',
method: 'post',
timeout: 2000,
response: {
code: 0,
data: {
name: '菲鸽',
},
},
},
{
url: '/api/text',
method: 'post',
rawResponse: async (req, res) => {
let reqbody = ''
await new Promise((resolve) => {
req.on('data', (chunk) => {
reqbody += chunk
})
req.on('end', () => resolve(undefined))
})
res.setHeader('Content-Type', 'text/plain')
res.statusCode = 200
res.end(`hello, ${reqbody}`)
},
},
] as MockMethod[]
{
"name": "unibest",
"type": "commonjs",
"version": "1.5.0",
"description": "unibest - 最好的 uniapp 开发模板",
"homepage": "https://feige996.github.io/hello-unibest/",
"bugs": {
"url": "https://github.com/feige996/unibest/issues"
},
"repository": "https://github.com/feige996/unibest",
"license": "MIT",
"author": {
"name": "feige996",
"zhName": "菲鸽",
......@@ -10,17 +15,8 @@
"github": "https://github.com/feige996",
"gitee": "https://gitee.com/feige996"
},
"license": "MIT",
"repository": "https://github.com/feige996/unibest",
"type": "commonjs",
"repository-gitee": "https://gitee.com/feige996/unibest",
"bugs": {
"url": "https://github.com/feige996/unibest/issues"
},
"homepage": "https://feige996.github.io/hello-unibest/",
"engines": {
"node": ">=18",
"pnpm": ">=7.30"
},
"scripts": {
"dev:app": "uni -p app",
"dev:app-android": "uni -p app-android",
......@@ -66,20 +62,6 @@
"prepare": "node ./shell/postinstall.js & git init && husky install ",
"type-check": "vue-tsc --noEmit"
},
"lint-staged": {
"**/*.{html,vue,ts,cjs,json,md}": [
"prettier --write"
],
"**/*.{vue,js,ts,jsx,tsx}": [
"eslint --fix"
],
"**/*.{vue,css,scss,html}": [
"stylelint --fix --allow-empty-input"
]
},
"resolutions": {
"bin-wrapper": "npm:bin-wrapper-china"
},
"dependencies": {
"@climblee/uv-ui": "^1.1.20",
"@dcloudio/uni-app": "3.0.0-4000820240401001",
......@@ -109,8 +91,6 @@
"z-paging": "^2.7.8"
},
"devDependencies": {
"@commitlint/cli": "^18.4.3",
"@commitlint/config-conventional": "^18.4.3",
"@dcloudio/types": "^3.4.8",
"@dcloudio/uni-automator": "3.0.0-4000820240401001",
"@dcloudio/uni-cli-shared": "3.0.0-4000820240401001",
......@@ -120,8 +100,6 @@
"@ttou/uv-typings": "^1.10.2",
"@types/node": "^20.11.5",
"@types/wechat-miniprogram": "^3.4.7",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.15.0",
"@uni-helper/uni-ui-types": "^0.5.11",
"@uni-helper/vite-plugin-uni-components": "^0.0.8",
"@uni-helper/vite-plugin-uni-layouts": "^0.1.7",
......@@ -132,16 +110,7 @@
"@vue/runtime-core": "^3.3.13",
"@vue/tsconfig": "^0.1.3",
"autoprefixer": "^10.4.16",
"commitlint": "^18.4.3",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard": "^17.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.0",
"eslint-plugin-vue": "^9.19.2",
"husky": "^8.0.3",
"lint-staged": "^15.2.0",
"postcss": "^8.4.32",
"postcss-html": "^1.5.0",
"postcss-scss": "^4.0.9",
......@@ -155,7 +124,6 @@
"stylelint-config-standard-scss": "^12.0.0",
"stylelint-prettier": "^5.0.0",
"terser": "^5.26.0",
"typescript": "^4.9.4",
"unocss": "^0.58.9",
"unocss-applet": "^0.7.8",
"unplugin-auto-import": "^0.17.2",
......@@ -167,5 +135,14 @@
"vite-plugin-vue-setup-extend": "^0.4.0",
"vite-svg-loader": "^5.1.0",
"vue-tsc": "^1.8.25"
},
"engines": {
"node": ">=18",
"pnpm": ">=7.30"
},
"resolutions": {
"bin-wrapper": "npm:bin-wrapper-china"
},
"lint-staged": {
}
}
import { defineUniPages } from '@uni-helper/vite-plugin-uni-pages'
import { defineUniPages } from "@uni-helper/vite-plugin-uni-pages";
export default defineUniPages({
globalStyle: {
navigationStyle: 'default',
navigationBarTitleText: 'unibest',
navigationBarBackgroundColor: '#f8f8f8',
navigationBarTextStyle: 'black',
backgroundColor: '#FFFFFF',
navigationStyle: "default",
navigationBarTitleText: "unibest",
navigationBarBackgroundColor: "#f8f8f8",
navigationBarTextStyle: "black",
backgroundColor: "#FFFFFF",
h5: {
// navigationStyle: 'custom',
},
......@@ -14,35 +14,35 @@ export default defineUniPages({
easycom: {
autoscan: true,
custom: {
'^uni-(.*)': '@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue',
'^uv-(.*)': '@climblee/uv-ui/components/uv-$1/uv-$1.vue',
'^wd-(.*)': 'wot-design-uni/components/wd-$1/wd-$1.vue',
'^(?!z-paging-refresh|z-paging-load-more)z-paging(.*)':
'z-paging/components/z-paging$1/z-paging$1.vue',
"^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue",
"^uv-(.*)": "@climblee/uv-ui/components/uv-$1/uv-$1.vue",
"^wd-(.*)": "wot-design-uni/components/wd-$1/wd-$1.vue",
"^(?!z-paging-refresh|z-paging-load-more)z-paging(.*)":
"z-paging/components/z-paging$1/z-paging$1.vue",
},
},
tabBar: {
color: '#999999',
selectedColor: '#018d71',
backgroundColor: '#F8F8F8',
borderStyle: 'black',
height: '50px',
fontSize: '10px',
iconWidth: '24px',
spacing: '3px',
color: "#999999",
selectedColor: "#018d71",
backgroundColor: "#F8F8F8",
borderStyle: "black",
height: "50px",
fontSize: "10px",
iconWidth: "24px",
spacing: "3px",
list: [
{
iconPath: 'static/tabbar/home.png',
selectedIconPath: 'static/tabbar/homeHL.png',
pagePath: 'pages/index/index',
text: '首页',
iconPath: "static/tabbar/home.png",
selectedIconPath: "static/tabbar/homeHL.png",
pagePath: "pages/index/index",
text: "首页",
},
{
iconPath: 'static/tabbar/example.png',
selectedIconPath: 'static/tabbar/exampleHL.png',
pagePath: 'pages/demo/index',
text: '示例',
iconPath: "static/tabbar/example.png",
selectedIconPath: "static/tabbar/exampleHL.png",
pagePath: "pages/demo/index",
text: "示例",
},
],
},
})
});
......@@ -7,15 +7,15 @@
*/
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs')
const fs = require("node:fs");
const filePath = './src/manifest.json'
const filePath = "./src/manifest.json";
if (fs.existsSync(filePath)) {
// console.log(`${filePath}存在`)
} else {
// console.log(`${filePath}不存在,需要创建`)
fs.writeFile(filePath, '{}\n', {}, () => {
fs.writeFile(filePath, "{}\n", {}, () => {
// console.log(`${filePath}已经成功创建,并写入{}`)
})
});
}
/// <reference types='@dcloudio/types' />
import 'vue'
// / <reference types='@dcloudio/types' />
import "vue";
declare module '@vue/runtime-core' {
declare module "@vue/runtime-core" {
type Hooks = App.AppInstance & Page.PageInstance
interface ComponentCustomOptions extends Hooks {}
}
<script setup lang="ts">
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
import { onHide, onLaunch, onShow } from "@dcloudio/uni-app";
onLaunch(() => {
console.log('App Launch')
})
console.log("App Launch");
});
onShow(() => {
console.log('App Show')
})
console.log("App Show");
});
onHide(() => {
console.log('App Hide')
})
console.log("App Hide");
});
</script>
<style lang="scss">
......
<template>
<svg aria-hidden="true">
<use :href="symbolId" :fill="color" />
<use :fill="color" :href="symbolId" />
</svg>
</template>
<script lang="ts" setup name="SvgIcon">
const props = withDefaults(
defineProps<{
prefix?: string
name: string
color?: string
name: string
prefix?: string
}>(),
{
prefix: 'icon',
name: '',
color: '#333',
prefix: "icon",
name: "",
color: "#333",
},
)
const symbolId = computed(() => `#${props.prefix}-${props.name}`)
);
const symbolId = computed(() => `#${props.prefix}-${props.name}`);
</script>
<template>
<view class="fly-content">
<view v-for="n in line" :key="n" class="h-10 leading-10 text-center">
<view v-for="n in line"
:key="n"
class="h-10 leading-10 text-center"
title="3">
很多内容,这里是第{{ n }}行
</view>
</view>
</template>
<script lang="ts" setup>
withDefaults(defineProps<{ line?: number }>(), { line: 10 })
withDefaults(defineProps<{ line?: number }>(), { line: 10 });
</script>
<template>
<view class="text-green-500">header</view>
<view class="text-green-500">
header
</view>
</template>
<template>
<view class="fly-login" v-if="modelValue">
<view v-if="modelValue" class="fly-login">
<view class="fly-login-mask" />
<view class="fly-login-content px-4">
<view class="font-bold h-16 leading-16">获取您的昵称、头像</view>
<view
class="rounded-full bg-light-600 w-6 h-6 text-center absolute top-4 right-4"
@click="onClose"
>
<view class="font-bold h-16 leading-16">
获取您的昵称、头像
</view>
<view class="rounded-full bg-light-600 w-6 h-6 text-center absolute top-4 right-4"
@click="onClose">
<view class="i-carbon-close text-gray-700" />
</view>
<view
class="flex items-center h-16 leading-16 border-b-gray-400 border-b-solid border-[1rpx]"
>
<view class="flex items-center h-16 leading-16 border-b-gray-400 border-b-solid border-[1rpx]">
<text class="mr-4 flex-shrink-0">头像</text>
<button
class="bg-transparent flex items-center after:b-none w-full h-12 leading-12"
<button class="bg-transparent flex items-center after:b-none w-full h-12 leading-12"
open-type="chooseAvatar"
@chooseavatar="onChooseAvatar"
>
@chooseavatar="onChooseAvatar">
<image class="w-8 h-8 rounded-full" :src="avatarUrl"></image>
<text class="ml-auto i-carbon-chevron-right"></text>
</button>
</view>
<view
class="flex items-center h-16 leading-16 border-b-gray-400 border-b-solid border-1 mt-4"
>
<view class="flex items-center h-16 leading-16 border-b-gray-400 border-b-solid border-1 mt-4">
<text class="mr-4 flex-shrink-0">昵称</text>
<input type="nickname" placeholder="请输入昵称" @change="onChange" @blur="onChange" />
<input placeholder="请输入昵称"
type="nickname"
@blur="onChange"
@change="onChange" />
</view>
<button
<button class="text-center leading-12 w-40 my-4"
size="default"
type="default"
style="color: #fff; background-color: #1aad19; border-color: #1aad19"
class="text-center leading-12 w-40 my-4"
@click="onSubmit"
>
type="default"
@click="onSubmit">
确定
</button>
</view>
</view>
</template>
<script lang="ts" setup>
import { useUserStore } from '@/store'
import defaultAvatarUrl from './defaultAvatar.png'
import { useUserStore } from "@/store";
const emit = defineEmits(['update:modelValue'])
defineProps<{ modelValue: boolean }>()
import defaultAvatarUrl from "./defaultAvatar.png";
const userStore = useUserStore()
defineProps<{ modelValue: boolean }>();
const emit = defineEmits([ "update:modelValue" ]);
const userStore = useUserStore();
const avatarUrl = ref(defaultAvatarUrl)
const nickname = ref('')
const avatarUrl = ref(defaultAvatarUrl);
const nickname = ref("");
const onClose = () => {
emit('update:modelValue', false)
}
emit("update:modelValue", false);
};
const onChooseAvatar = (e) => {
const { avatarUrl: url } = e.detail
avatarUrl.value = url
const { avatarUrl: url } = e.detail;
avatarUrl.value = url;
// 这里就要上传,加快速度,提升体验(用户多次选择头像就多次上传吧,总有取舍)
console.log(url)
}
console.log(url);
};
const onChange = (e) => {
const { value } = e.detail
nickname.value = value
console.log(value)
}
const { value } = e.detail;
nickname.value = value;
console.log(value);
};
const onSubmit = () => {
// 1、上传刚刚的图片,并返回网络地址
// 2、把用户信息存起来
if (avatarUrl.value === defaultAvatarUrl) {
uni.showToast({
title: '请选择头像',
icon: 'none',
})
return
title: "请选择头像",
icon: "none",
});
return;
}
if (!nickname.value) {
uni.showToast({
title: '请填写昵称',
icon: 'none',
})
return
title: "请填写昵称",
icon: "none",
});
return;
}
emit('update:modelValue', false)
console.log('保存用户信息')
userStore.setUserInfo({ nickname: nickname.value, avatar: avatarUrl.value })
}
emit("update:modelValue", false);
console.log("保存用户信息");
userStore.setUserInfo({ nickname: nickname.value, avatar: avatarUrl.value });
};
</script>
<style lang="scss" scoped>
......
<template>
<!-- 自定义导航栏: 默认透明不可见, scroll-view 滚动到 50 时展示 -->
<view class="fly-navbar" :style="{ paddingTop: safeAreaInsets?.top + 'px' }">
<view class="fly-navbar" :style="{ paddingTop: `${safeAreaInsets?.top }px` }">
<!-- 1/3,多于1个页面,用返回图标 -->
<navigator v-if="pages.length > 1" open-type="navigateBack" class="left-icon">
<navigator v-if="pages.length > 1"
class="left-icon"
open-type="navigateBack">
<view class="bg-gray-500/80 rounded-full w-8 h-8 flex items-center justify-center">
<button class="i-carbon-chevron-left text-white w-7 h-7"></button>
</view>
</navigator>
<!-- 2/3,只有1个页面,如果不是tabbar,需要首页图标 -->
<!-- 这种情况一般出现在用户直接打开分享出去的详情页面,或者使用redirectTo等API -->
<navigator
v-else-if="!isTabbar"
open-type="switchTab"
url="/pages/index/index"
<navigator v-else-if="!isTabbar"
class="left-icon"
>
open-type="switchTab"
url="/pages/index/index">
<view class="bg-gray-500/80 rounded-full w-8 h-8 flex items-center justify-center">
<button class="i-carbon-home text-white w-6 h-6"></button>
</view>
</navigator>
<!-- 3/3,如果当前页就是tabbar页,不用去首页,也就是什么图标都不需要 -->
<view class="title">{{ title || '' }}</view>
<view class="title">
{{ title || '' }}
</view>
</view>
</template>
<script lang="ts" setup>
import { getIsTabbar } from '@/utils/index'
import { getIsTabbar } from "@/utils/index";
defineProps<{ title?: string }>()
defineProps<{ title?: string }>();
// 获取页面栈
const pages = getCurrentPages()
const isTabbar = getIsTabbar()
console.log({ isTabbar, pagesLen: pages.length })
const pages = getCurrentPages();
const isTabbar = getIsTabbar();
console.log({ isTabbar, pagesLen: pages.length });
// 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync()
const { safeAreaInsets } = uni.getSystemInfoSync();
</script>
<style lang="scss" scoped>
......
This diff could not be displayed because it is too large.
<template>
<view class="chartsview">
<view class="charts-error"></view>
<view class="charts-font">{{ errorMessage == null ? '请点击重试' : errorMessage }}</view>
<view class="charts-font">
{{ errorMessage === null ? '请点击重试' : errorMessage }}
</view>
</view>
</template>
<script>
export default {
name: 'qiun-error',
name: "QiunError",
props: {
errorMessage: {
type: String,
......@@ -15,9 +17,9 @@ export default {
},
},
data() {
return {}
return {};
},
}
};
</script>
<style>
......
......@@ -9,11 +9,11 @@
<script>
export default {
name: 'loading1',
name: "Loading1",
data() {
return {}
return {};
},
}
};
</script>
<style scoped="true">
......
......@@ -9,11 +9,11 @@
<script>
export default {
name: 'loading2',
name: "Loading2",
data() {
return {}
return {};
},
}
};
</script>
<style scoped="true">
......@@ -25,18 +25,13 @@ export default {
.container.loading2 {
transform: rotate(10deg);
transform: rotate(10deg);
animation: rotation 1s infinite;
}
.container.loading2 .shape {
border-radius: 5px;
}
.container.loading2 {
animation: rotation 1s infinite;
animation: rotation 1s infinite;
}
.container .shape {
position: absolute;
width: 10px;
......@@ -67,117 +62,97 @@ export default {
.loading2 .shape1 {
animation: animation2shape1 0.5s ease 0s infinite alternate;
animation: animation2shape1 0.5s ease 0s infinite alternate;
}
@keyframes animation2shape1 {
from {
transform: translate(0, 0);
transform: translate(0, 0);
}
to {
transform: translate(20px, 20px);
transform: translate(20px, 20px);
}
}
@keyframes animation2shape1 {
from {
transform: translate(0, 0);
transform: translate(0, 0);
}
to {
transform: translate(20px, 20px);
transform: translate(20px, 20px);
}
}
.loading2 .shape2 {
animation: animation2shape2 0.5s ease 0s infinite alternate;
animation: animation2shape2 0.5s ease 0s infinite alternate;
}
@keyframes animation2shape2 {
from {
transform: translate(0, 0);
transform: translate(0, 0);
}
to {
transform: translate(-20px, 20px);
transform: translate(-20px, 20px);
}
}
@keyframes animation2shape2 {
from {
transform: translate(0, 0);
transform: translate(0, 0);
}
to {
transform: translate(-20px, 20px);
transform: translate(-20px, 20px);
}
}
.loading2 .shape3 {
animation: animation2shape3 0.5s ease 0s infinite alternate;
animation: animation2shape3 0.5s ease 0s infinite alternate;
}
@keyframes animation2shape3 {
from {
transform: translate(0, 0);
transform: translate(0, 0);
}
to {
transform: translate(20px, -20px);
transform: translate(20px, -20px);
}
}
@keyframes animation2shape3 {
from {
transform: translate(0, 0);
transform: translate(0, 0);
}
to {
transform: translate(20px, -20px);
transform: translate(20px, -20px);
}
}
.loading2 .shape4 {
animation: animation2shape4 0.5s ease 0s infinite alternate;
animation: animation2shape4 0.5s ease 0s infinite alternate;
}
@keyframes animation2shape4 {
from {
transform: translate(0, 0);
transform: translate(0, 0);
}
to {
transform: translate(-20px, -20px);
transform: translate(-20px, -20px);
}
}
@keyframes animation2shape4 {
from {
transform: translate(0, 0);
transform: translate(0, 0);
}
to {
transform: translate(-20px, -20px);
transform: translate(-20px, -20px);
}
}
</style>
......@@ -9,11 +9,11 @@
<script>
export default {
name: 'loading3',
name: "Loading3",
data() {
return {}
return {};
},
}
};
</script>
<style scoped="true">
......@@ -25,7 +25,6 @@ export default {
.container.loading3 {
animation: rotation 1s infinite;
animation: rotation 1s infinite;
}
.container.loading3 .shape1 {
......@@ -74,117 +73,97 @@ export default {
.loading3 .shape1 {
animation: animation3shape1 0.5s ease 0s infinite alternate;
animation: animation3shape1 0.5s ease 0s infinite alternate;
}
@keyframes animation3shape1 {
from {
transform: translate(0, 0);
transform: translate(0, 0);
}
to {
transform: translate(5px, 5px);
transform: translate(5px, 5px);
}
}
@keyframes animation3shape1 {
from {
transform: translate(0, 0);
transform: translate(0, 0);
}
to {
transform: translate(5px, 5px);
transform: translate(5px, 5px);
}
}
.loading3 .shape2 {
animation: animation3shape2 0.5s ease 0s infinite alternate;
animation: animation3shape2 0.5s ease 0s infinite alternate;
}
@keyframes animation3shape2 {
from {
transform: translate(0, 0);
transform: translate(0, 0);
}
to {
transform: translate(-5px, 5px);
transform: translate(-5px, 5px);
}
}
@keyframes animation3shape2 {
from {
transform: translate(0, 0);
transform: translate(0, 0);
}
to {
transform: translate(-5px, 5px);
transform: translate(-5px, 5px);
}
}
.loading3 .shape3 {
animation: animation3shape3 0.5s ease 0s infinite alternate;
animation: animation3shape3 0.5s ease 0s infinite alternate;
}
@keyframes animation3shape3 {
from {
transform: translate(0, 0);
transform: translate(0, 0);
}
to {
transform: translate(5px, -5px);
transform: translate(5px, -5px);
}
}
@keyframes animation3shape3 {
from {
transform: translate(0, 0);
transform: translate(0, 0);
}
to {
transform: translate(5px, -5px);
transform: translate(5px, -5px);
}
}
.loading3 .shape4 {
animation: animation3shape4 0.5s ease 0s infinite alternate;
animation: animation3shape4 0.5s ease 0s infinite alternate;
}
@keyframes animation3shape4 {
from {
transform: translate(0, 0);
transform: translate(0, 0);
}
to {
transform: translate(-5px, -5px);
transform: translate(-5px, -5px);
}
}
@keyframes animation3shape4 {
from {
transform: translate(0, 0);
transform: translate(0, 0);
}
to {
transform: translate(-5px, -5px);
transform: translate(-5px, -5px);
}
}
</style>
......@@ -9,11 +9,11 @@
<script>
export default {
name: 'loading5',
name: "Loading5",
data() {
return {}
return {};
},
}
};
</script>
<style scoped="true">
......@@ -63,44 +63,36 @@ export default {
@keyframes animation5shape1 {
0% {
transform: translate(0, 0);
transform: translate(0, 0);
}
25% {
transform: translate(0, 15px);
transform: translate(0, 15px);
}
50% {
transform: translate(15px, 15px);
transform: translate(15px, 15px);
}
75% {
transform: translate(15px, 0);
transform: translate(15px, 0);
}
}
@keyframes animation5shape1 {
0% {
transform: translate(0, 0);
transform: translate(0, 0);
}
25% {
transform: translate(0, 15px);
transform: translate(0, 15px);
}
50% {
transform: translate(15px, 15px);
transform: translate(15px, 15px);
}
75% {
transform: translate(15px, 0);
transform: translate(15px, 0);
}
}
......@@ -111,44 +103,36 @@ export default {
@keyframes animation5shape2 {
0% {
transform: translate(0, 0);
transform: translate(0, 0);
}
25% {
transform: translate(-15px, 0);
transform: translate(-15px, 0);
}
50% {
transform: translate(-15px, 15px);
transform: translate(-15px, 15px);
}
75% {
transform: translate(0, 15px);
transform: translate(0, 15px);
}
}
@keyframes animation5shape2 {
0% {
transform: translate(0, 0);
transform: translate(0, 0);
}
25% {
transform: translate(-15px, 0);
transform: translate(-15px, 0);
}
50% {
transform: translate(-15px, 15px);
transform: translate(-15px, 15px);
}
75% {
transform: translate(0, 15px);
transform: translate(0, 15px);
}
}
......@@ -159,44 +143,36 @@ export default {
@keyframes animation5shape3 {
0% {
transform: translate(0, 0);
transform: translate(0, 0);
}
25% {
transform: translate(15px, 0);
transform: translate(15px, 0);
}
50% {
transform: translate(15px, -15px);
transform: translate(15px, -15px);
}
75% {
transform: translate(0, -15px);
transform: translate(0, -15px);
}
}
@keyframes animation5shape3 {
0% {
transform: translate(0, 0);
transform: translate(0, 0);
}
25% {
transform: translate(15px, 0);
transform: translate(15px, 0);
}
50% {
transform: translate(15px, -15px);
transform: translate(15px, -15px);
}
75% {
transform: translate(0, -15px);
transform: translate(0, -15px);
}
}
......@@ -207,44 +183,36 @@ export default {
@keyframes animation5shape4 {
0% {
transform: translate(0, 0);
transform: translate(0, 0);
}
25% {
transform: translate(0, -15px);
transform: translate(0, -15px);
}
50% {
transform: translate(-15px, -15px);
transform: translate(-15px, -15px);
}
75% {
transform: translate(-15px, 0);
transform: translate(-15px, 0);
}
}
@keyframes animation5shape4 {
0% {
transform: translate(0, 0);
transform: translate(0, 0);
}
25% {
transform: translate(0, -15px);
transform: translate(0, -15px);
}
50% {
transform: translate(-15px, -15px);
transform: translate(-15px, -15px);
}
75% {
transform: translate(-15px, 0);
transform: translate(-15px, 0);
}
}
</style>
......@@ -9,11 +9,11 @@
<script>
export default {
name: 'loading6',
name: "Loading6",
data() {
return {}
return {};
},
}
};
</script>
<style scoped="true">
.container {
......@@ -24,7 +24,6 @@ export default {
.container.loading6 {
animation: rotation 1s infinite;
animation: rotation 1s infinite;
}
.container.loading6 .shape {
......@@ -63,197 +62,161 @@ export default {
.loading6 .shape1 {
animation: animation6shape1 2s linear 0s infinite normal;
animation: animation6shape1 2s linear 0s infinite normal;
}
@keyframes animation6shape1 {
0% {
transform: translate(0, 0);
transform: translate(0, 0);
}
25% {
transform: translate(0, 18px);
transform: translate(0, 18px);
}
50% {
transform: translate(18px, 18px);
transform: translate(18px, 18px);
}
75% {
transform: translate(18px, 0);
transform: translate(18px, 0);
}
}
@keyframes animation6shape1 {
0% {
transform: translate(0, 0);
transform: translate(0, 0);
}
25% {
transform: translate(0, 18px);
transform: translate(0, 18px);
}
50% {
transform: translate(18px, 18px);
transform: translate(18px, 18px);
}
75% {
transform: translate(18px, 0);
transform: translate(18px, 0);
}
}
.loading6 .shape2 {
animation: animation6shape2 2s linear 0s infinite normal;
animation: animation6shape2 2s linear 0s infinite normal;
}
@keyframes animation6shape2 {
0% {
transform: translate(0, 0);
transform: translate(0, 0);
}
25% {
transform: translate(-18px, 0);
transform: translate(-18px, 0);
}
50% {
transform: translate(-18px, 18px);
transform: translate(-18px, 18px);
}
75% {
transform: translate(0, 18px);
transform: translate(0, 18px);
}
}
@keyframes animation6shape2 {
0% {
transform: translate(0, 0);
transform: translate(0, 0);
}
25% {
transform: translate(-18px, 0);
transform: translate(-18px, 0);
}
50% {
transform: translate(-18px, 18px);
transform: translate(-18px, 18px);
}
75% {
transform: translate(0, 18px);
transform: translate(0, 18px);
}
}
.loading6 .shape3 {
animation: animation6shape3 2s linear 0s infinite normal;
animation: animation6shape3 2s linear 0s infinite normal;
}
@keyframes animation6shape3 {
0% {
transform: translate(0, 0);
transform: translate(0, 0);
}
25% {
transform: translate(18px, 0);
transform: translate(18px, 0);
}
50% {
transform: translate(18px, -18px);
transform: translate(18px, -18px);
}
75% {
transform: translate(0, -18px);
transform: translate(0, -18px);
}
}
@keyframes animation6shape3 {
0% {
transform: translate(0, 0);
transform: translate(0, 0);
}
25% {
transform: translate(18px, 0);
transform: translate(18px, 0);
}
50% {
transform: translate(18px, -18px);
transform: translate(18px, -18px);
}
75% {
transform: translate(0, -18px);
transform: translate(0, -18px);
}
}
.loading6 .shape4 {
animation: animation6shape4 2s linear 0s infinite normal;
animation: animation6shape4 2s linear 0s infinite normal;
}
@keyframes animation6shape4 {
0% {
transform: translate(0, 0);
transform: translate(0, 0);
}
25% {
transform: translate(0, -18px);
transform: translate(0, -18px);
}
50% {
transform: translate(-18px, -18px);
transform: translate(-18px, -18px);
}
75% {
transform: translate(-18px, 0);
transform: translate(-18px, 0);
}
}
@keyframes animation6shape4 {
0% {
transform: translate(0, 0);
transform: translate(0, 0);
}
25% {
transform: translate(0, -18px);
transform: translate(0, -18px);
}
50% {
transform: translate(-18px, -18px);
transform: translate(-18px, -18px);
}
75% {
transform: translate(-18px, 0);
transform: translate(-18px, 0);
}
}
</style>
<template>
<view>
<Loading1 v-if="loadingType == 1" />
<Loading2 v-if="loadingType == 2" />
<Loading3 v-if="loadingType == 3" />
<Loading4 v-if="loadingType == 4" />
<Loading5 v-if="loadingType == 5" />
<Loading1 v-if="loadingType === 1" />
<Loading2 v-if="loadingType === 2" />
<Loading3 v-if="loadingType === 3" />
<Loading4 v-if="loadingType === 4" />
<Loading5 v-if="loadingType === 5" />
</view>
</template>
<script>
import Loading1 from './loading1.vue'
import Loading2 from './loading2.vue'
import Loading3 from './loading3.vue'
import Loading4 from './loading4.vue'
import Loading5 from './loading5.vue'
import Loading1 from "./loading1.vue";
import Loading2 from "./loading2.vue";
import Loading3 from "./loading3.vue";
import Loading4 from "./loading4.vue";
import Loading5 from "./loading5.vue";
export default {
name: "QiunLoading",
components: { Loading1, Loading2, Loading3, Loading4, Loading5 },
name: 'qiun-loading',
props: {
loadingType: {
type: Number,
......@@ -25,9 +25,9 @@ export default {
},
},
data() {
return {}
return {};
},
}
};
</script>
<style></style>
<template>
<view class="qiun-title-bar">
<view class="qiun-title-dot"></view>
<view class="qiun-title-text">{{ title }}</view>
<view class="qiun-title-text">
{{ title }}
</view>
</view>
</template>
<script>
export default {
name: 'title-bar',
name: "TitleBar",
props: {
title: {
type: String,
default: '',
default: "",
},
},
mounted() {},
methods: {},
}
};
</script>
<style>
......
/// <reference types="vite/client" />
/// <reference types="vite-svg-loader" />
// / <reference types="vite/client" />
// / <reference types="vite-svg-loader" />
/* eslint-disable */
declare module "*.vue" {
import { DefineComponent } from "vue";
declare module '*.vue' {
import { DefineComponent } from 'vue'
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
const component: DefineComponent<{}, {}, any>
export default component
const component: DefineComponent<{}, {}, any>;
export default component;
}
interface ImportMetaEnv {
......
/* eslint-disable import/first */
// 小程序中引入 echarts
// #ifndef APP-PLUS || H5
// eslint-disable-next-line @typescript-eslint/no-var-requires
const echarts = require('../uni_modules/lime-echart/static/echarts.min')
/* eslint-disable */
import { ref } from "vue";
// #endif
// APP 与 H5 引入 echarts
// #ifdef APP-PLUS || H5
import * as echartsAppOrH5 from 'echarts'
import * as echartsAppOrH5 from "echarts";
// #endif
import { ref } from 'vue'
// 小程序中引入 echarts
// #ifndef APP-PLUS || H5
const echarts = require("../uni_modules/lime-echart/static/echarts.min");
// echarts 图表 Hooks
export const useEcharts = (options): any => {
// echarts 图实例
const chartRef = ref(null)
const chartRef = ref(null);
// echarts 图绘制函数
const draw = () => {
setTimeout(async () => {
if (!chartRef.value) return
if (!chartRef.value) return;
// #ifndef APP-PLUS || H5
const chart = await chartRef.value.init(echarts)
chart.setOption(options.value)
const chart = await chartRef.value.init(echarts);
chart.setOption(options.value);
// #endif
// #ifdef APP-PLUS || H5
const chartAPP = await chartRef.value.init(echartsAppOrH5)
chartAPP.setOption(options.value)
const chartAPP = await chartRef.value.init(echartsAppOrH5);
chartAPP.setOption(options.value);
// #endif
}, 300)
}
}, 300);
};
// 这里就封装巧妙之处,如果是对象,那么需要重命名,而是是数组,无需重命名
return [chartRef, options, draw]
}
return [ chartRef, options, draw ];
};
import { onReady } from '@dcloudio/uni-app'
import { getIsTabbar, getLastItem } from '@/utils/index'
import { getIsTabbar, getLastItem } from "@/utils/index";
import { onReady } from "@dcloudio/uni-app";
export default () => {
export const useNavbarWeixin = () => {
// 获取页面栈
const pages = getCurrentPages()
const isTabbar = getIsTabbar()
const pages = getCurrentPages();
const isTabbar = getIsTabbar();
// 页面滚动到底部时的操作,通常用于加载更多数据
const onScrollToLower = () => {}
const onScrollToLower = () => {};
// 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync()
const { safeAreaInsets } = uni.getSystemInfoSync();
// #ifdef MP-WEIXIN
// 基于小程序的 Page 类型扩展 uni-app 的 Page
type PageInstance = Page.PageInstance & WechatMiniprogram.Page.InstanceMethods<any>
// 获取当前页面实例,数组最后一项
const pageInstance = getLastItem(getCurrentPages()) as PageInstance
const pageInstance = getLastItem(getCurrentPages()) as PageInstance;
// 页面渲染完毕,绑定动画效果
onReady(() => {
// 动画效果,导航栏背景色
pageInstance.animate(
'.fly-navbar',
[{ backgroundColor: 'transparent' }, { backgroundColor: '#f8f8f8' }],
".fly-navbar",
[ { backgroundColor: "transparent" }, { backgroundColor: "#f8f8f8" } ],
1000,
{
scrollSource: '#scroller',
scrollSource: "#scroller",
timeRange: 1000,
startScrollOffset: 0,
endScrollOffset: 50,
},
)
);
// 动画效果,导航栏标题
pageInstance.animate(
'.fly-navbar .title',
[{ color: 'transparent' }, { color: '#000' }],
".fly-navbar .title",
[ { color: "transparent" }, { color: "#000" } ],
1000,
{
scrollSource: '#scroller',
scrollSource: "#scroller",
timeRange: 1000,
startScrollOffset: 0,
endScrollOffset: 50,
},
)
);
// 动画效果,导航栏返回按钮
pageInstance.animate('.fly-navbar .left-icon', [{ color: '#fff' }, { color: '#000' }], 1000, {
scrollSource: '#scroller',
pageInstance.animate(".fly-navbar .left-icon", [ { color: "#fff" }, { color: "#000" } ], 1000, {
scrollSource: "#scroller",
timeRange: 1000,
startScrollOffset: 0,
endScrollOffset: 50,
})
})
});
});
// #endif
return {
......@@ -58,5 +58,7 @@ export default () => {
isTabbar,
onScrollToLower,
safeAreaInsets,
}
}
};
};
export default useNavbarWeixin;
import { UnwrapRef } from 'vue'
type IUseRequestOptions<T> = {
/** 是否立即执行,如果是则在onLoad执行 */
......@@ -17,28 +16,29 @@ type IUseRequestOptions<T> = {
*/
export default function useRequest<T>(
func: () => Promise<IResData<T>>,
options: IUseRequestOptions<T> = { immediate: true },
options: IUseRequestOptions<T>,
) {
const loading = ref(false)
const error = ref(false)
const data = ref<T>(options.initialData)
options = options ?? { immediate: true };
const loading = ref(false);
const error = ref(false);
const data = ref<T>(options.initialData);
const run = async () => {
loading.value = true
loading.value = true;
func()
.then((res) => {
data.value = res.data as UnwrapRef<T>
error.value = false
data.value = res.data as T;
error.value = false;
})
.catch((err) => {
error.value = err
.catch((error_) => {
error.value = error;
})
.finally(() => {
loading.value = false
})
}
loading.value = false;
});
};
onLoad(() => {
options.immediate && run()
})
return { loading, error, data, run }
options.immediate && run();
});
return { loading, error, data, run };
}
// TODO: 别忘加更改环境变量的 VITE_UPLOAD_BASEURL 地址。
const VITE_UPLOAD_BASEURL = import.meta.env.VITE_UPLOAD_BASEURL
const VITE_UPLOAD_BASEURL = import.meta.env.VITE_UPLOAD_BASEURL;
/**
* useUpload 是一个定制化的请求钩子,用于处理上传图片。
......@@ -7,61 +7,61 @@ const VITE_UPLOAD_BASEURL = import.meta.env.VITE_UPLOAD_BASEURL
* @returns 返回一个对象{loading, error, data, run},包含请求的加载状态、错误信息、响应数据和手动触发请求的函数。
*/
export default function useUpload<T = string>(formData: Record<string, any> = {}) {
const loading = ref(false)
const error = ref(false)
const data = ref<T>()
const loading = ref(false);
const error = ref(false);
const data = ref<T>();
const run = () => {
// #ifdef MP-WEIXIN
// 微信小程序从基础库 2.21.0 开始, wx.chooseImage 停止维护,请使用 uni.chooseMedia 代替。
// 微信小程序在2023年10月17日之后,使用本API需要配置隐私协议
uni.chooseMedia({
count: 1,
mediaType: ['image'],
mediaType: [ "image" ],
success: (res) => {
loading.value = true
const tempFilePath = res.tempFiles[0].tempFilePath
uploadFile<T>({ tempFilePath, formData, data, error, loading })
loading.value = true;
const tempFilePath = res.tempFiles[0].tempFilePath;
uploadFile<T>({ tempFilePath, formData, data, error, loading });
},
fail: (err) => {
console.log('uni.chooseMedia err->', err)
error.value = true
console.log("uni.chooseMedia err->", err);
error.value = true;
},
})
});
// #endif
// #ifndef MP-WEIXIN
uni.chooseImage({
count: 1,
success: (res) => {
loading.value = true
const tempFilePath = res.tempFilePaths[0]
uploadFile<T>({ tempFilePath, formData, data, error, loading })
loading.value = true;
const tempFilePath = res.tempFilePaths[0];
uploadFile<T>({ tempFilePath, formData, data, error, loading });
},
fail: (err) => {
console.log('uni.chooseImage err->', err)
error.value = true
console.log("uni.chooseImage err->", err);
error.value = true;
},
})
});
// #endif
}
};
return { loading, error, data, run }
return { loading, error, data, run };
}
function uploadFile<T>({ tempFilePath, formData, data, error, loading }) {
uni.uploadFile({
url: VITE_UPLOAD_BASEURL,
filePath: tempFilePath,
name: 'file',
name: "file",
formData,
success: (uploadFileRes) => {
data.value = uploadFileRes.data as T
data.value = uploadFileRes.data as T;
},
fail: (err) => {
console.log('uni.uploadFile err->', err)
error.value = true
console.log("uni.uploadFile err->", err);
error.value = true;
},
complete: () => {
loading.value = false
loading.value = false;
},
})
});
}
/* eslint-disable no-unused-vars */
export {}
declare module 'vue' {
declare module "vue" {
interface ComponentCustomProperties {
$t: (key: string, opt?: Record<string, any>) => string
$tm: (key: string, opt?: Record<string, any>) => [] | { [p: string]: any }
......
export { routeInterceptor } from './route'
export { requestInterceptor } from './request'
export { requestInterceptor } from "./request";
export { routeInterceptor } from "./route";
/* eslint-disable no-param-reassign */
import qs from 'qs'
import { useUserStore } from '@/store'
export type CustomRequestOptions = UniApp.RequestOptions & {
query?: Record<string, any>
} & IUniUploadFileOptions // 添加uni.uploadFile参数类型
import { useUserStore } from "@/store";
import qs from "qs";
export type CustomRequestOptions = IUniUploadFileOptions;
// 请求基地址
const baseURL = import.meta.env.VITE_SERVER_BASEURL
const baseURL = import.meta.env.VITE_SERVER_BASEURL;
// 拦截器配置
const httpInterceptor = {
......@@ -15,39 +14,39 @@ const httpInterceptor = {
invoke(options: CustomRequestOptions) {
// 接口请求支持通过 query 参数配置 queryString
if (options.query) {
const queryStr = qs.stringify(options.query)
if (options.url.includes('?')) {
options.url += `&${queryStr}`
const queryStr = qs.stringify(options.query);
if (options.url.includes("?")) {
options.url += `&${queryStr}`;
} else {
options.url += `?${queryStr}`
options.url += `?${queryStr}`;
}
}
// api 目前为 mock 接口,所以无需处理
if (!options.url.startsWith('http')) {
if (!options.url.startsWith("http")) {
// 1. 非 http 开头需拼接地址
options.url = baseURL + options.url
options.url = baseURL + options.url;
}
// 2. 请求超时
options.timeout = 10000 // 10s
options.timeout = 10_000; // 10s
// 3. 添加小程序端请求头标识
options.header = {
platform: 'mp-weixin', // 可选值与 uniapp 定义的平台一致,告诉后台来源
platform: "mp-weixin", // 可选值与 uniapp 定义的平台一致,告诉后台来源
...options.header,
}
};
// 4. 添加 token 请求头标识
const userStore = useUserStore()
const { token } = userStore.userInfo as unknown as IUserInfo
const userStore = useUserStore();
const { token } = userStore.userInfo as unknown as IUserInfo;
if (token) {
options.header.Authorization = `Bearer ${token}`
options.header.Authorization = `Bearer ${token}`;
}
},
}
};
export const requestInterceptor = {
install() {
// 拦截 request 请求
uni.addInterceptor('request', httpInterceptor)
uni.addInterceptor("request", httpInterceptor);
// 拦截 uploadFile 文件上传
uni.addInterceptor('uploadFile', httpInterceptor)
uni.addInterceptor("uploadFile", httpInterceptor);
},
}
};
......@@ -4,51 +4,51 @@
* 可以设置路由白名单,或者黑名单,看业务需要选哪一个
* 我这里应为大部分都可以随便进入,所以使用黑名单
*/
import { useUserStore } from '@/store'
import { getNeedLoginPages, needLoginPages as _needLoginPages } from '@/utils'
import { useUserStore } from "@/store";
import { needLoginPages as _needLoginPages, getNeedLoginPages } from "@/utils";
// TODO Check
const loginRoute = '/pages/login/index'
const loginRoute = "/pages/login/index";
const isLogined = () => {
const userStore = useUserStore()
return userStore.isLogined
}
const userStore = useUserStore();
return userStore.isLogined;
};
const isDev = import.meta.env.DEV
const isDev = import.meta.env.DEV;
// 黑名单登录拦截器 - (适用于大部分页面不需要登录,少部分页面需要登录)
const navigateToInterceptor = {
// 注意,这里的url是 '/' 开头的,如 '/pages/index/index',跟 'pages.json' 里面的 path 不同
invoke({ url }: { url: string }) {
console.log(url) // /pages/route-interceptor/index?name=feige&age=30
const path = url.split('?')[0]
let needLoginPages: string[] = []
console.log(url); // /pages/route-interceptor/index?name=feige&age=30
const path = url.split("?")[0];
let needLoginPages: string[] = [];
// 为了防止开发时出现BUG,这里每次都获取一下。生产环境可以移到函数外,性能更好
if (isDev) {
needLoginPages = getNeedLoginPages()
needLoginPages = getNeedLoginPages();
} else {
needLoginPages = _needLoginPages
needLoginPages = _needLoginPages;
}
console.log(needLoginPages.includes(path))
console.log(needLoginPages.includes(path));
if (needLoginPages.includes(path)) {
const isLogin = isLogined()
const isLogin = isLogined();
if (isLogin) {
return true
return true;
}
const redirectRoute = `${loginRoute}?redirect=${encodeURIComponent(url)}`
uni.navigateTo({ url: redirectRoute })
return false
const redirectRoute = `${loginRoute}?redirect=${encodeURIComponent(url)}`;
uni.navigateTo({ url: redirectRoute });
return false;
}
return true
return true;
},
}
};
export const routeInterceptor = {
install() {
uni.addInterceptor('navigateTo', navigateToInterceptor)
uni.addInterceptor('reLaunch', navigateToInterceptor)
uni.addInterceptor('redirectTo', navigateToInterceptor)
uni.addInterceptor("navigateTo", navigateToInterceptor);
uni.addInterceptor("reLaunch", navigateToInterceptor);
uni.addInterceptor("redirectTo", navigateToInterceptor);
},
}
};
......@@ -9,9 +9,11 @@
<style lang="scss">
.default-layout {
height: 100vh;
/* #ifdef H5 */
padding-bottom: 50px;
overflow: auto;
/* #endif */
}
</style>
import { createI18n } from 'vue-i18n'
import { createI18n } from "vue-i18n";
import en from './en.json'
import zhHans from './zh-Hans.json' // 简体中文
import en from "./en.json";
import zhHans from "./zh-Hans.json"; // 简体中文
const messages = {
en,
'zh-Hans': zhHans, // key 不能乱写,查看截图 screenshots/i18n.png
}
"zh-Hans": zhHans, // key 不能乱写,查看截图 screenshots/i18n.png
};
const i18n = createI18n({
locale: uni.getLocale(), // 获取已设置的语言,fallback 语言需要再 manifest.config.ts 中设置
messages,
})
});
console.log(uni.getLocale())
console.log(i18n.global.locale)
console.log(uni.getLocale());
console.log(i18n.global.locale);
/**
* 非 vue 文件使用这个方法
......@@ -22,16 +22,16 @@ console.log(i18n.global.locale)
*/
export const translate = (localeKey: string) => {
if (!localeKey) {
console.error(`[i18n] Function translate(), localeKey param is required`)
return ''
console.error(`[i18n] Function translate(), localeKey param is required`);
return "";
}
const locale = uni.getLocale()
console.log('locale:', locale)
const locale = uni.getLocale();
console.log("locale:", locale);
const message = messages[locale]
const message = messages[locale];
if (Object.keys(message).includes(localeKey)) {
return message[localeKey]
return message[localeKey];
}
return localeKey
}
export default i18n
return localeKey;
};
export default i18n;
import { createSSRApp } from 'vue'
import uvUI from '@climblee/uv-ui'
import App from './App.vue'
import store from './store'
import { routeInterceptor, requestInterceptor } from './interceptors'
import i18n from './locale/index'
import 'virtual:svg-icons-register'
import 'virtual:uno.css'
import '@/style/index.scss'
import { createSSRApp } from "vue";
import uvUI from "@climblee/uv-ui";
import App from "./App.vue";
import { requestInterceptor, routeInterceptor } from "./interceptors";
import i18n from "./locale/index";
import store from "./store";
import "virtual:svg-icons-register";
import "virtual:uno.css";
import "@/style/index.scss";
// production mock server
// 线上报错,TODO: fix me
......@@ -18,13 +22,13 @@ import '@/style/index.scss'
// }
export function createApp() {
const app = createSSRApp(App)
app.use(store)
app.use(i18n)
app.use(uvUI)
app.use(routeInterceptor)
app.use(requestInterceptor)
const app = createSSRApp(App);
app.use(store);
app.use(i18n);
app.use(uvUI);
app.use(routeInterceptor);
app.use(requestInterceptor);
return {
app,
}
};
}
......@@ -6,8 +6,12 @@
<template>
<view class="text-center">
<view class="m-8">http://localhost:9000/#/pages-sub/demo/index</view>
<view class="text-green-500">分包页面demo</view>
<view class="m-8">
http://localhost:9000/#/pages-sub/demo/index
</view>
<view class="text-green-500">
分包页面demo
</view>
</view>
</template>
......
......@@ -9,47 +9,70 @@
<template>
<view class="p-6 text-center">
<view class="my-2">使用的是 laf 云后台</view>
<view class="text-green-400">我的推荐码,可以获得佣金</view>
<view class="my-2">
使用的是 laf 云后台
</view>
<view class="text-green-400">
我的推荐码,可以获得佣金
</view>
<!-- #ifdef H5 -->
<view class="my-2">
<a class="my-2" :href="recommendUrl" target="_blank">{{ recommendUrl }}</a>
<a class="my-2"
:href="recommendUrl"
target="_blank">
{{ recommendUrl }}
</a>
</view>
<!-- #endif -->
<!-- #ifndef H5 -->
<view class="my-2 text-left text-sm">{{ recommendUrl }}</view>
<view class="my-2 text-left text-sm">
{{ recommendUrl }}
</view>
<!-- #endif -->
<!-- http://localhost:9000/#/pages/index/request -->
<wd-button @click="run" class="my-6">发送请求</wd-button>
<wd-button class="my-6" @click="run">
发送请求
</wd-button>
<view class="h-12">
<view v-if="loading">loading...</view>
<view v-if="loading">
loading...
</view>
<block v-else>
<view class="text-xl">请求数据如下</view>
<view class="text-green leading-8">{{ JSON.stringify(data) }}</view>
<view class="text-xl">
请求数据如下
</view>
<view class="text-green leading-8">
{{ JSON.stringify(data) }}
</view>
</block>
</view>
<wd-button type="error" @click="reset" class="my-6" :disabled="!data">重置数据</wd-button>
<wd-button class="my-6"
:disabled="!data"
type="error"
@click="reset">
重置数据
</wd-button>
</view>
</template>
<script lang="ts" setup>
import { getFooAPI, postFooAPI, IFooItem } from '@/service/foo'
import { getFooAPI, IFooItem } from "@/service/foo";
const recommendUrl = ref('http://laf.run/signup?code=ohaOgIX')
const recommendUrl = ref("http://laf.run/signup?code=ohaOgIX");
// const initialData = {
// name: 'initialData',
// id: '1234',
// }
const initialData = undefined
const initialData = undefined;
// 适合少部分全局性的接口————多个页面都需要的请求接口,额外编写一个 Service 层
const { loading, error, data, run } = useRequest<IFooItem>(() => getFooAPI('菲鸽'), {
const { loading, error, data, run } = useRequest<IFooItem>(() => getFooAPI("菲鸽"), {
initialData,
})
});
const reset = () => {
data.value = initialData
}
data.value = initialData;
};
</script>
......@@ -10,33 +10,55 @@
<template>
<view class="p-6 text-center">
<!-- http://localhost:9000/#/pages/index/request -->
<wd-button @click="getFoo" class="my-6">发送请求</wd-button>
<wd-button class="my-6" @click="getFoo">
发送请求
</wd-button>
<view class="h-12">
<view v-if="loading1">loading...</view>
<view v-if="loading1">
loading...
</view>
<block v-else>
<view class="text-xl">请求数据如下</view>
<view class="text-green leading-8">{{ JSON.stringify(data1) }}</view>
<view class="text-xl">
请求数据如下
</view>
<view class="text-green leading-8">
{{ JSON.stringify(data1) }}
</view>
</block>
</view>
<wd-button @click="getBar" class="my-6">发送请求2</wd-button>
<wd-button class="my-6" @click="getBar">
发送请求2
</wd-button>
<view class="h-12">
<view v-if="loading2">loading...</view>
<view v-if="loading2">
loading...
</view>
<block v-else>
<view class="text-xl">请求数据如下</view>
<view class="text-green leading-8">{{ JSON.stringify(data2) }}</view>
<view class="text-xl">
请求数据如下
</view>
<view class="text-green leading-8">
{{ JSON.stringify(data2) }}
</view>
</block>
</view>
<wd-button type="error" @click="reset" class="my-6" :disabled="!data1 || !data2">
<wd-button class="my-6"
:disabled="!data1 || !data2"
type="error"
@click="reset">
重置数据
</wd-button>
<wd-button type="success" @click="getAllData" class="my-6 ml-2" :disabled="!!data1 || !!data2">
<wd-button class="my-6 ml-2"
:disabled="!!data1 || !!data2"
type="success"
@click="getAllData">
同时发送请求
</wd-button>
</view>
</template>
<script lang="ts" setup>
import { getFooAPI, postFooAPI, IFooItem } from '@/service/foo'
import { getFooAPI, IFooItem, postFooAPI } from "@/service/foo";
// 适合少部分全局性的接口————多个页面都需要的请求接口,额外编写一个 Service 层
const {
......@@ -44,19 +66,19 @@ const {
error: err1,
data: data1,
run: getFoo,
} = useRequest<IFooItem>(() => getFooAPI('菲鸽'))
} = useRequest<IFooItem>(() => getFooAPI("菲鸽"));
const {
loading: loading2,
error: err2,
data: data2,
run: getBar,
} = useRequest<IFooItem>(() => postFooAPI('菲鸽222'))
} = useRequest<IFooItem>(() => postFooAPI("菲鸽222"));
const reset = () => {
data1.value = undefined
data2.value = undefined
}
data1.value = undefined;
data2.value = undefined;
};
const getAllData = () => {
getFoo()
getBar()
}
getFoo();
getBar();
};
</script>
......@@ -9,20 +9,30 @@
<template>
<view class="p-4 text-center">
<wd-button @click="run">选择图片并上传</wd-button>
<view v-if="loading" class="text-blue h-10">上传...</view>
<wd-button @click="run">
选择图片并上传
</wd-button>
<view v-if="loading" class="text-blue h-10">
上传...
</view>
<template v-else>
<view class="m-2">上传后返回的接口数据:</view>
<view class="m-2">{{ data }}</view>
<view class="m-2">
上传后返回的接口数据:
</view>
<view class="m-2">
{{ data }}
</view>
<view class="h-80 w-full">
<image v-if="data" :src="data || data" mode="scaleToFill" />
<image v-if="data"
mode="scaleToFill"
:src="data || data" />
</view>
</template>
</view>
</template>
<script lang="ts" setup>
const { loading, data, run } = useUpload({ user: '菲鸽' })
const { loading, data, run } = useUpload({ user: "菲鸽" });
</script>
<style lang="scss" scoped>
......
......@@ -10,12 +10,20 @@
<template>
<view class="mt-4">
进过多次测试发现,粘贴的css代码块在如下情况时会出现格式化问题:
<view class="ml-4">粘贴的css代码块中类名上面不包含空行(与大小写无关)</view>
<view class="ml-4 text-green-600">1. 中间有空行的,正常,不用处理;</view>
<view class="ml-4">
粘贴的css代码块中类名上面不包含空行(与大小写无关)
</view>
<view class="ml-4 text-green-600">
1. 中间有空行的,正常,不用处理;
</view>
<view class="ml-4 text-red-600">
2. 中间没有空行的,格式化异常,通过 ctrl+Z,ctrl+S 可以搞定
</view>
<image src="./css.png" mode="scaleToFill" class="css-img mt-2" width="688" height="885" />
<image class="css-img mt-2"
height="885"
mode="scaleToFill"
src="./css.png"
width="688" />
</view>
</template>
......@@ -25,6 +33,7 @@
<style lang="scss" scoped>
// 最初的代码如下(版本1)
/*
.test{
background: #FFF;
......@@ -35,6 +44,7 @@
*/
// 中间有空行可以正常格式化(版本2)
/*
.test{
background: #FFF;
......
......@@ -6,13 +6,15 @@
</route>
<template>
<view class="center mt-8 text-green-600">enum 使用,script setup 里面这样写不会报错</view>
<view class="center mt-8 text-green-600">
enum 使用,script setup 里面这样写不会报错
</view>
</template>
<script lang="ts" setup>
type T = TestEnum.A
const a = 'a' as T
console.log(a)
const a = "a" as T;
console.log(a);
</script>
<style lang="scss" scoped>
......
......@@ -13,10 +13,12 @@
当前环境所使用的环境文件
<text class="text-red-500 ml-4">{{ VITE_ENV_FILE }}</text>
</view>
<view class="text-red-500 mt-8 ml-4">环境变量的使用与 --mode 参数配合使用</view>
<view class="text-red-500 mt-8 ml-4">
环境变量的使用与 --mode 参数配合使用
</view>
</template>
<script lang="ts" setup>
const isDev = import.meta.env.DEV
const { VITE_ENV_FILE } = import.meta.env
const isDev = import.meta.env.DEV;
const { VITE_ENV_FILE } = import.meta.env;
</script>
......@@ -9,35 +9,51 @@
<template>
<view class="mt-6">
<button @click="getFoo" class="my-4" type="primary">测试 GET 请求</button>
<view class="text-xl">请求数据如下</view>
<view class="text-green h-10">{{ JSON.stringify(data) }}</view>
<view class="text-xl">完整数据</view>
<view class="text-green h-20">{{ JSON.stringify(originalData) }}</view>
<button class="my-8" type="warn" @click="reset">一键清空数据</button>
<button class="my-4"
type="primary"
@click="getFoo">
测试 GET 请求
</button>
<view class="text-xl">
请求数据如下
</view>
<view class="text-green h-10">
{{ JSON.stringify(data) }}
</view>
<view class="text-xl">
完整数据
</view>
<view class="text-green h-20">
{{ JSON.stringify(originalData) }}
</view>
<button class="my-8"
type="warn"
@click="reset">
一键清空数据
</button>
</view>
</template>
<script lang="ts" setup>
import { getMockAPI } from '@/service/mock'
import { getMockAPI } from "@/service/mock";
onLoad(() => {
getFoo()
})
getFoo();
});
const originalData = ref<IResData<any>>()
const data = ref()
const originalData = ref<IResData<any>>();
const data = ref();
const getFoo = async () => {
const res = await getMockAPI('菲鸽')
data.value = res.data
originalData.value = res
}
const res = await getMockAPI("菲鸽");
data.value = res.data;
originalData.value = res;
};
const reset = () => {
data.value = undefined
originalData.value = undefined
}
data.value = undefined;
originalData.value = undefined;
};
</script>
<style lang="scss" scoped>
......
......@@ -6,36 +6,36 @@
</route>
<template>
<view class="text-green">微信分享页</view>
<view class="text-green-500">请在微信小程序中体验,或者开发者工具</view>
<view class="text-green">
微信分享页
</view>
<view class="text-green-500">
请在微信小程序中体验,或者开发者工具
</view>
<view>1) 默认是不激活”发送给朋友“和”分享到朋友圈“的,如下图</view>
<image
src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/wx-share-before.png"
mode="widthFix"
/>
<image mode="widthFix"
src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/wx-share-before.png" />
<view>2) 增加了onShareAppMessage和onShareTimeline后,就可以微信分享了,如下图</view>
<image
src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/wx-share-after.png"
mode="widthFix"
/>
<image mode="widthFix"
src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/wx-share-after.png" />
</template>
<script lang="ts" setup>
import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
import { onShareAppMessage, onShareTimeline } from "@dcloudio/uni-app";
/** 激活“分享给好友” */
onShareAppMessage((options: Page.ShareAppMessageOption): Page.CustomShareContent => {
console.log('options:', options)
console.log("options:", options);
return {
title: '自定义分享标题',
desc: 'unibest 演示示例',
path: '/pages/index/index?id=xxx',
}
})
title: "自定义分享标题",
desc: "unibest 演示示例",
path: "/pages/index/index?id=xxx",
};
});
/** 激活“分享到朋友圈”, 注意:需要先激活“分享给好友” */
onShareTimeline((): Page.ShareTimelineContent => {
return {
title: '自定义分享标题',
query: 'a=1&b=2',
}
})
title: "自定义分享标题",
query: "a=1&b=2",
};
});
</script>
......@@ -5,15 +5,14 @@
</route>
<template>
<uni-nav-bar
title="自定义导航栏"
left-icon="left"
@clickLeft="goBack"
<uni-nav-bar :border="false"
class="fixed w-full"
:border="false"
left-icon="left"
:status-bar="true"
></uni-nav-bar>
<view class="h-11" :style="{ paddingTop: safeAreaInsets?.top + 'px' }"></view>
title="自定义导航栏"
@click-left="goBack">
</uni-nav-bar>
<view class="h-11" :style="{ paddingTop: `${safeAreaInsets?.top }px` }"></view>
<view>
<fly-content :line="20" />
</view>
......@@ -21,8 +20,8 @@
<script lang="ts" setup>
const goBack = () => {
uni.navigateBack()
}
uni.navigateBack();
};
// 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync()
const { safeAreaInsets } = uni.getSystemInfoSync();
</script>
......@@ -6,15 +6,21 @@
<template>
<fly-navbar />
<view class="bg-green-300 min-h-20" :style="{ paddingTop: safeAreaInsets?.top + 'px' }">
<view class="p-4">自定义导航栏,设置"navigationStyle":"custom"</view>
<view class="p-4">通常页面顶部有一个图片或背景色</view>
<view class="p-4">本实例没有导航栏,但是需要返回</view>
<view class="bg-green-300 min-h-20" :style="{ paddingTop: `${safeAreaInsets?.top }px` }">
<view class="p-4">
自定义导航栏,设置"navigationStyle":"custom"
</view>
<view class="p-4">
通常页面顶部有一个图片或背景色
</view>
<view class="p-4">
本实例没有导航栏,但是需要返回
</view>
</view>
<fly-content :line="20" />
</template>
<script lang="ts" setup>
// 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync()
const { safeAreaInsets } = uni.getSystemInfoSync();
</script>
......@@ -7,34 +7,52 @@
<template>
<view class="flex justify-center items-center text-blue-500 mt-4 mb-4">
<view class="w-20">Count: {{ countStore.count }}</view>
<button class="ml-2 mr-2" @click="countStore.decrement">-1</button>
<button class="ml-2 mr-2" @click="countStore.increment">+1</button>
<button class="ml-2 mr-2" @click="countStore.reset">重置</button>
<view class="w-20">
Count: {{ countStore.count }}
</view>
<button class="ml-2 mr-2" @click="countStore.decrement">
-1
</button>
<button class="ml-2 mr-2" @click="countStore.increment">
+1
</button>
<button class="ml-2 mr-2" @click="countStore.reset">
重置
</button>
</view>
<view class="m-8 text-4 leading-8">
<view class="text-center">{{ userStore.userInfo }}</view>
<view class="text-center">请观察小程序的store,可以看到是可以正常设置的</view>
<button @click="setUserInfo">设置UserInfo</button>
<button @click="clearUserInfo" class="mt-4">清除UserInfo</button>
<button @click="resetUserStore" class="mt-4">reset UserStore</button>
<view class="text-center">
{{ userStore.userInfo }}
</view>
<view class="text-center">
请观察小程序的store,可以看到是可以正常设置的
</view>
<button @click="setUserInfo">
设置UserInfo
</button>
<button class="mt-4" @click="clearUserInfo">
清除UserInfo
</button>
<button class="mt-4" @click="resetUserStore">
reset UserStore
</button>
</view>
</template>
<script lang="ts" setup>
import { useCountStore, useUserStore } from '@/store'
import { useCountStore, useUserStore } from "@/store";
const countStore = useCountStore()
const countStore = useCountStore();
const userStore = useUserStore()
const userStore = useUserStore();
const setUserInfo = () => {
userStore.setUserInfo({ nickname: '菲鸽', avatar: '', token: 'abcdef' })
}
userStore.setUserInfo({ nickname: "菲鸽", avatar: "", token: "abcdef" });
};
const clearUserInfo = () => {
userStore.clearUserInfo()
}
userStore.clearUserInfo();
};
const resetUserStore = () => {
userStore.reset()
}
userStore.reset();
};
</script>
......@@ -10,57 +10,87 @@
<template>
<view class="mt-6">
<!-- http://localhost:9100/#/pages/index/request -->
<button @click="getFoo" class="my-4">测试 GET 请求</button>
<view class="text-xl">请求数据如下</view>
<view class="text-green h-10">{{ JSON.stringify(data) }}</view>
<view class="text-xl">完整数据</view>
<view class="text-green h-20">{{ JSON.stringify(originalData) }}</view>
<button @click="postFoo" class="my-4">测试 POST 请求</button>
<view class="text-xl">请求数据如下</view>
<view class="text-green h-10">{{ JSON.stringify(data2) }}</view>
<button class="my-4" @click="getFoo">
测试 GET 请求
</button>
<view class="text-xl">
请求数据如下
</view>
<view class="text-green h-10">
{{ JSON.stringify(data) }}
</view>
<view class="text-xl">
完整数据
</view>
<view class="text-green h-20">
{{ JSON.stringify(originalData) }}
</view>
<button class="my-4" @click="postFoo">
测试 POST 请求
</button>
<view class="text-xl">
请求数据如下
</view>
<view class="text-green h-10">
{{ JSON.stringify(data2) }}
</view>
<button class="my-8" type="warn" @click="reset">一键清空数据</button>
<button class="my-8"
type="warn"
@click="reset">
一键清空数据
</button>
<view class="my-2">使用的是 laf 云后台</view>
<view class="text-green-400">我的推荐码,可以获得佣金</view>
<view class="my-2">
使用的是 laf 云后台
</view>
<view class="text-green-400">
我的推荐码,可以获得佣金
</view>
<!-- #ifdef H5 -->
<view class="my-2 text-center">
<a class="my-2 text-center" :href="recommendUrl" target="_blank">{{ recommendUrl }}</a>
<a class="my-2 text-center"
:href="recommendUrl"
target="_blank">
{{ recommendUrl }}
</a>
</view>
<!-- #endif -->
<!-- #ifndef H5 -->
<view class="my-2 text-left text-sm">{{ recommendUrl }}</view>
<view class="my-2 text-left text-sm">
{{ recommendUrl }}
</view>
<!-- #endif -->
</view>
</template>
<script lang="ts" setup>
import { getFooAPI, postFooAPI, IFooItem } from '@/service/foo'
import { getFooAPI, IFooItem, postFooAPI } from "@/service/foo";
const recommendUrl = ref('http://laf.run/signup?code=ohaOgIX')
const recommendUrl = ref("http://laf.run/signup?code=ohaOgIX");
onLoad(() => {
getFoo()
postFoo()
})
const originalData = ref<IResData<IFooItem>>()
const data = ref<IFooItem>()
getFoo();
postFoo();
});
const originalData = ref<IResData<IFooItem>>();
const data = ref<IFooItem>();
const getFoo = async () => {
const res = await getFooAPI('菲鸽')
data.value = res.data
originalData.value = res
}
const res = await getFooAPI("菲鸽");
data.value = res.data;
originalData.value = res;
};
const data2 = ref<IFooItem>()
const data2 = ref<IFooItem>();
const postFoo = async () => {
const res = await postFooAPI('菲鸽2')
data2.value = res.data
}
const res = await postFooAPI("菲鸽2");
data2.value = res.data;
};
const reset = () => {
data.value = undefined
data2.value = undefined
originalData.value = undefined
}
data.value = undefined;
data2.value = undefined;
originalData.value = undefined;
};
</script>
......@@ -9,18 +9,24 @@
<template>
<view class="mt-6">
<view class="text-2xl my-2 text-red-600">1-普通请求</view>
<view class="text-2xl my-2 text-red-600">
1-普通请求
</view>
<RequestComp />
<view class="text-2xl my-2 text-red-600">2-上传图片</view>
<view class="text-2xl my-2 text-red-600">
2-上传图片
</view>
<UploadComp />
<view class="text-2xl my-2 text-red-600">3-并发请求</view>
<view class="text-2xl my-2 text-red-600">
3-并发请求
</view>
<Request2Comp />
</view>
</template>
<script lang="ts" setup>
import RequestComp from './components/request.vue'
import Request2Comp from './components/request2.vue'
import UploadComp from './components/upload.vue'
import Request2Comp from "./components/request2.vue";
import RequestComp from "./components/request.vue";
import UploadComp from "./components/upload.vue";
</script>
......@@ -11,15 +11,19 @@
用户是否已登录:
<text>{{ !!userStore?.userInfo?.token }}</text>
</view>
<view class="text-gray">未登录不能来本页面</view>
<view class="text-gray">已登录才能来本页面</view>
<view class="text-gray">
未登录不能来本页面
</view>
<view class="text-gray">
已登录才能来本页面
</view>
</view>
</template>
<script lang="ts" setup>
import { useUserStore } from '@/store'
import { useUserStore } from "@/store";
const userStore = useUserStore()
const userStore = useUserStore();
</script>
<style lang="scss" scoped>
......
......@@ -9,32 +9,40 @@
<template>
<view class="p-4">
<view class="text-center m-4">svg 多种使用方法</view>
<image src="/static/svg/task.svg" mode="scaleToFill" class="h-20 w-20" />
<image :src="iconUrl" mode="scaleToFill" class="h-20 w-20" />
<image :src="iconUrl2" mode="scaleToFill" class="h-20 w-20" />
<view class="text-center m-4">
svg 多种使用方法
</view>
<image class="h-20 w-20"
mode="scaleToFill"
src="/static/svg/task.svg" />
<image class="h-20 w-20"
mode="scaleToFill"
:src="iconUrl" />
<image class="h-20 w-20"
mode="scaleToFill"
:src="iconUrl2" />
<!-- {{ iconRaw }} -->
<view class="text-center m-4 text-blue-500">目前发现,小程序和APP只支持 image 方式</view>
<view class="text-center m-4 text-blue-500">下面的几种方式,都不支持</view>
<view class="text-center m-4 text-blue-500">
目前发现,小程序和APP只支持 image 方式
</view>
<view class="text-center m-4 text-blue-500">
下面的几种方式,都不支持
</view>
<!-- #ifdef H5 -->
<TaskComponent class="h-20 w-20" />
<SvgIcon name="task" class="h-20 w-20"></SvgIcon>
<SvgIcon name="dir-task2" class="h-20 w-20"></SvgIcon>
<SvgIcon class="h-20 w-20" name="task"></SvgIcon>
<SvgIcon class="h-20 w-20" name="dir-task2"></SvgIcon>
<!-- #endif -->
</view>
</template>
<script lang="ts" setup>
// eslint-disable-next-line import/no-duplicates
import iconUrl from './task.svg'
// eslint-disable-next-line import/no-duplicates
import iconUrl2 from './task.svg?url'
// eslint-disable-next-line import/no-duplicates
import iconRaw from './task.svg?raw'
import iconUrl from "./task.svg";
import TaskComponent from "./task.svg?component";
// #ifdef H5
// 小程序不支持 component 方式引入,运行会报错,APP不报错,但是不生效
// eslint-disable-next-line import/no-duplicates
import TaskComponent from './task.svg?component'
import iconUrl2 from "./task.svg?url";
// #endif
</script>
......
......@@ -18,38 +18,40 @@
<template>
<!-- #ifdef MP-WEIXIN -->
<view class="fly-navbar" :style="{ paddingTop: safeAreaInsets?.top + 'px' }">
<view class="fly-navbar" :style="{ paddingTop: `${safeAreaInsets?.top }px` }">
<!-- 1/3,多于1个页面,用返回图标 -->
<navigator v-if="pages.length > 1" open-type="navigateBack" class="left-icon">
<navigator v-if="pages.length > 1"
class="left-icon"
open-type="navigateBack">
<view class="i-carbon-chevron-left text-current"></view>
</navigator>
<!-- 2/3,只有1个页面,如果不是tabbar,需要首页图标 -->
<!-- 这种情况一般出现在用户直接打开分享出去的详情页面,或者使用redirectTo等API -->
<navigator
v-else-if="!isTabbar"
open-type="switchTab"
url="/pages/index/index"
<navigator v-else-if="!isTabbar"
class="left-icon"
>
open-type="switchTab"
url="/pages/index/index">
<view class="i-carbon-home text-current"></view>
</navigator>
<!-- 3/3,如果当前页就是tabbar页,不用去首页,也就是什么图标都不需要 -->
<view class="title">{{ '我是标题' }}</view>
<view class="title">
{{ '我是标题' }}
</view>
</view>
<!-- #endif -->
<scroll-view
enable-back-to-top
scroll-y
<scroll-view id="scroller"
class="scroll-view-bg flex-1 h-full"
id="scroller"
enable-back-to-top
refresher-enabled
@scrolltolower="onScrollToLower"
@refresherrefresh="onRefresherRefresh"
:refresher-triggered="isTriggered"
>
<view class="top-section" :style="{ paddingTop: safeAreaInsets?.top + 'px' }">
<view class="pt-1">顶部区域</view>
scroll-y
@refresherrefresh="onRefresherRefresh"
@scrolltolower="onScrollToLower">
<view class="top-section" :style="{ paddingTop: `${safeAreaInsets?.top }px` }">
<view class="pt-1">
顶部区域
</view>
<view>可以是标题,也可以是个人中心头像等</view>
<view>建议本区域高度不低于200rpx</view>
</view>
......@@ -65,32 +67,32 @@
</template>
<script lang="ts" setup>
import { onPullDownRefresh } from '@dcloudio/uni-app'
import useNavbarWeixin from '@/hooks/useNavbarWeixin'
import useNavbarWeixin from "@/hooks/useNavbarWeixin";
import { onPullDownRefresh } from "@dcloudio/uni-app";
const { pages, isTabbar, onScrollToLower, safeAreaInsets } = useNavbarWeixin()
const { pages, isTabbar, onScrollToLower, safeAreaInsets } = useNavbarWeixin();
// 发现原生下拉刷新效果并不好,在微信里面只有顶部导航栏下拉才生效,页面区域下拉不生效,体验不好,结合自定义下拉刷新效果很好
onPullDownRefresh(() => {
setTimeout(function fn() {
console.log('refresh - onPullDownRefresh')
setTimeout(() => {
console.log("refresh - onPullDownRefresh");
// 关闭动画
uni.stopPullDownRefresh()
}, 1000)
})
uni.stopPullDownRefresh();
}, 1000);
});
// 当前下拉刷新状态
const isTriggered = ref(false)
const isTriggered = ref(false);
// 自定义下拉刷新被触发
const onRefresherRefresh = async () => {
// 开始动画
isTriggered.value = true
setTimeout(function fn() {
console.log('refresh - onRefresherRefresh')
isTriggered.value = true;
setTimeout(() => {
console.log("refresh - onRefresherRefresh");
// 关闭动画
isTriggered.value = false
}, 1000)
}
isTriggered.value = false;
}, 1000);
};
</script>
<style lang="scss">
......
......@@ -7,23 +7,46 @@
<template>
<view class="m-4">
<uni-icons type="contact" size="30"></uni-icons>
<uni-icons type="contact" size="30" color="red"></uni-icons>
<uni-icons type="contact" size="30" class="text-green"></uni-icons>
<uni-icons type="contact" size="30" color="red" class="text-green"></uni-icons>
<uni-icons type="contact" size="30" color="red" class="text-green"></uni-icons>
<uni-icons type="contact" color="red" class="text-green w-4"></uni-icons>
<uni-icons type="contact" color="red" class="text-green w-8"></uni-icons>
<uni-icons :type="iconName" :color="colorName" class="text-green w-8"></uni-icons>
<uni-icons size="30" type="contact"></uni-icons>
<uni-icons color="red"
size="30"
type="contact">
</uni-icons>
<uni-icons class="text-green"
size="30"
type="contact">
</uni-icons>
<uni-icons class="text-green"
color="red"
size="30"
type="contact">
</uni-icons>
<uni-icons class="text-green"
color="red"
size="30"
type="contact">
</uni-icons>
<uni-icons class="text-green w-4"
color="red"
type="contact">
</uni-icons>
<uni-icons class="text-green w-8"
color="red"
type="contact">
</uni-icons>
<uni-icons class="text-green w-8"
:color="colorName"
:type="iconName">
</uni-icons>
</view>
</template>
<script lang="ts" setup>
const iconName = ref<string>('contact')
const colorName = ref<string>('red')
const iconName = ref<string>("contact");
const colorName = ref<string>("red");
onLoad(() => {
setTimeout(() => {
iconName.value = 'chat'
colorName.value = 'green'
}, 1000)
})
iconName.value = "chat";
colorName.value = "green";
}, 1000);
});
</script>
......@@ -12,16 +12,20 @@
<uni-badge text="99"></uni-badge>
<uni-rate :value="3" />
<view>
<button @click="open">打开弹窗</button>
<uni-popup ref="popup" type="bottom" border-radius="10px 10px 0 0">
<button @click="open">
打开弹窗
</button>
<uni-popup ref="popup"
border-radius="10px 10px 0 0"
type="bottom">
底部弹出 Popup 自定义圆角
</uni-popup>
</view>
</template>
<script lang="ts" setup>
const popup = ref()
const popup = ref();
const open = () => {
popup.value?.open()
}
popup.value?.open();
};
</script>
export const icon = 'i-carbon-3d-cursor'
export const icon = "i-carbon-3d-cursor";
export const nest = {
nest: {
icon: 'i-carbon-3d-ica',
icon: "i-carbon-3d-ica",
},
}
};
......@@ -19,19 +19,25 @@
<button class="i-carbon-sun dark:i-carbon-moon" />
<view class="h-10"></view>
<view class="i-carbon-user-avatar text-red" />
<view :class="`i-carbon-user-avatar`" />
<view class="i-carbon-user-avatar" />
<view class="ml-2"></view>
<view :class="iconName" />
<view :class="iconName2" />
<view :class="iconName3" />
<view class="my-4 text-red">经过测试,动态图片从别的文件导入无法生效</view>
<wd-tabbar-item title="首页" icon="home"></wd-tabbar-item>
<wd-tabbar-item :value="2" icon="cart" title="分类">
<view class="my-4 text-red">
经过测试,动态图片从别的文件导入无法生效
</view>
<wd-tabbar-item icon="home" title="首页"></wd-tabbar-item>
<wd-tabbar-item icon="cart"
title="分类"
:value="2">
<template #icon>
<view :class="iconName2" />
</template>
</wd-tabbar-item>
<wd-tabbar-item :value="2" icon="cart" title="分类">
<wd-tabbar-item icon="cart"
title="分类"
:value="2">
<template #icon>
<view :class="iconName3" />
</template>
......@@ -40,24 +46,24 @@
</template>
<script lang="ts" setup>
import { icon, nest } from './unocss-icon'
import { icon2, nest2 } from './unocss-icon.json'
import { icon, icon2, nest, nest2 } from "./unocss-icon";
// 只需要把外面的在这里写一遍就能生效了!注释掉也是生效的,但是必须要有
// 'i-carbon-3d-cursor-alt'
const iconName = ref<string>('i-carbon-car')
const iconName2 = ref<string>('i-carbon-car')
const iconName3 = ref<string>('i-carbon-car')
const iconName = ref<string>("i-carbon-car");
const iconName2 = ref<string>("i-carbon-car");
const iconName3 = ref<string>("i-carbon-car");
onLoad(() => {
setTimeout(() => {
iconName.value = 'i-carbon-4k'
iconName2.value = icon
iconName3.value = icon2
}, 1000)
iconName.value = "i-carbon-4k";
iconName2.value = icon;
iconName3.value = icon2;
}, 1000);
setTimeout(() => {
console.log(nest.nest.icon, nest2.nest2.icon)
iconName2.value = nest.nest.icon
iconName3.value = nest2.nest2.icon
}, 2000)
})
console.log(nest.nest.icon, nest2.nest2.icon);
iconName2.value = nest.nest.icon;
iconName3.value = nest2.nest2.icon;
}, 2000);
});
</script>
......@@ -7,9 +7,17 @@
<template>
<view class="flex flex-col justify-center items-center text-5 h-12 leading-12 mt-20">
<view class="text-green-500">文字颜色 text-light-50</view>
<view class="text-red-500">文字颜色 text-red-500</view>
<view class="bg-green-500 mt-4">背景色 bg-light-50</view>
<view class="bg-red-500 mt-4">背景色 bg-red-500</view>
<view class="text-green-500">
文字颜色 text-light-50
</view>
<view class="text-red-500">
文字颜色 text-red-500
</view>
<view class="bg-green-500 mt-4">
背景色 bg-light-50
</view>
<view class="bg-red-500 mt-4">
背景色 bg-red-500
</view>
</view>
</template>
......@@ -9,17 +9,25 @@
<template>
<view class="p-4 text-center">
<wd-button @click="chooseImage">选择图片并上传</wd-button>
<view class="m-2">上传后返回的图片地址:</view>
<view class="m-2">{{ imgStr }}</view>
<wd-button @click="chooseImage">
选择图片并上传
</wd-button>
<view class="m-2">
上传后返回的图片地址:
</view>
<view class="m-2">
{{ imgStr }}
</view>
<view class="h-80 w-full">
<image v-if="imgStr" :src="imgStr" mode="scaleToFill" />
<image v-if="imgStr"
mode="scaleToFill"
:src="imgStr" />
</view>
</view>
</template>
<script lang="ts" setup>
const imgStr = ref('')
const imgStr = ref("");
const chooseImage = () => {
// #ifdef MP-WEIXIN
......@@ -27,49 +35,49 @@ const chooseImage = () => {
// 微信小程序在2023年10月17日之后,使用本API需要配置隐私协议
uni.chooseMedia({
count: 1,
mediaType: ['image'],
mediaType: [ "image" ],
success: (res) => {
console.log(res)
const tempFilePath = res.tempFiles[0].tempFilePath
console.log(res);
const tempFilePath = res.tempFiles[0].tempFilePath;
uni.uploadFile({
url: 'https://ukw0y1.laf.run/upload',
url: "https://ukw0y1.laf.run/upload",
filePath: tempFilePath,
name: 'file',
name: "file",
formData: {
user: '菲鸽',
user: "菲鸽",
},
success: (uploadFileRes) => {
console.log(typeof uploadFileRes.data)
const data = JSON.parse(uploadFileRes.data)
imgStr.value = data.data.url
console.log(typeof uploadFileRes.data);
const data = JSON.parse(uploadFileRes.data);
imgStr.value = data.data.url;
},
})
});
},
})
});
// #endif
// #ifndef MP-WEIXIN
uni.chooseImage({
count: 1,
success: (res) => {
console.log(res)
const tempFilePath = res.tempFilePaths[0]
console.log(res);
const tempFilePath = res.tempFilePaths[0];
uni.uploadFile({
url: 'https://ukw0y1.laf.run/upload',
url: "https://ukw0y1.laf.run/upload",
filePath: tempFilePath,
name: 'file',
name: "file",
formData: {
user: '菲鸽',
user: "菲鸽",
},
success: (uploadFileRes) => {
console.log(typeof uploadFileRes.data)
const data = JSON.parse(uploadFileRes.data)
imgStr.value = data.data.url
console.log(typeof uploadFileRes.data);
const data = JSON.parse(uploadFileRes.data);
imgStr.value = data.data.url;
},
})
});
},
})
});
// #endif
}
};
</script>
<style lang="scss" scoped>
......
......@@ -9,20 +9,30 @@
<template>
<view class="p-4 text-center">
<wd-button @click="run">选择图片并上传</wd-button>
<view v-if="loading" class="text-blue h-10">上传...</view>
<wd-button @click="run">
选择图片并上传
</wd-button>
<view v-if="loading" class="text-blue h-10">
上传...
</view>
<template v-else>
<view class="m-2">上传后返回的图片地址:</view>
<view class="m-2">{{ data }}</view>
<view class="m-2">
上传后返回的图片地址:
</view>
<view class="m-2">
{{ data }}
</view>
<view class="h-80 w-full">
<image v-if="data" :src="data" mode="scaleToFill" />
<image v-if="data"
mode="scaleToFill"
:src="data" />
</view>
</template>
</view>
</template>
<script lang="ts" setup>
const { loading, data, run } = useUpload<string>({ user: '菲鸽' })
const { loading, data, run } = useUpload<string>({ user: "菲鸽" });
</script>
<style lang="scss" scoped>
......
......@@ -6,24 +6,43 @@
<template>
<view class="mt-10">
<uv-button type="primary" @click="remakeQc">重新生成二维码</uv-button>
<uv-button type="primary" @click="remakeQc">
重新生成二维码
</uv-button>
<view class="center mt-8">
<uv-qrcode
ref="qrcode"
size="200px"
value="https://h5.uvui.cn"
<uv-qrcode ref="qrcode"
:options="options"
></uv-qrcode>
size="200px"
value="https://h5.uvui.cn">
</uv-qrcode>
</view>
<view class="m-4 flex">
<uv-icon name="home"></uv-icon>
<uv-icon name="home" color="red"></uv-icon>
<uv-icon name="home" class="text-green"></uv-icon>
<uv-icon name="home" color="red" class="text-green"></uv-icon>
<uv-icon name="home" color="red" class="text-green" size="20"></uv-icon>
<uv-icon name="home" color="red" class="text-green w-10 h-10" size="20"></uv-icon>
<uv-icon name="home" color="red" class="text-green w-20 h-20"></uv-icon>
<uv-icon name="home" color="red" class="text-green w-10" size="20"></uv-icon>
<uv-icon color="red" name="home"></uv-icon>
<uv-icon class="text-green" name="home"></uv-icon>
<uv-icon class="text-green"
color="red"
name="home">
</uv-icon>
<uv-icon class="text-green"
color="red"
name="home"
size="20">
</uv-icon>
<uv-icon class="text-green w-10 h-10"
color="red"
name="home"
size="20">
</uv-icon>
<uv-icon class="text-green w-20 h-20"
color="red"
name="home">
</uv-icon>
<uv-icon class="text-green w-10"
color="red"
name="home"
size="20">
</uv-icon>
<uv-icon :name="iconName"></uv-icon>
</view>
......@@ -42,7 +61,9 @@
</text>
</view>
</uv-popup>
<button @click="open">打开</button>
<button @click="open">
打开
</button>
</view>
</template>
......@@ -51,46 +72,46 @@ const content = `<div>
<p style="color:red;" >露从今夜白,月是故乡明</p>
<img src="https://cdn.uviewui.com/uview/swiper/2.jpg" />
</div>
`
`;
console.log(uni.$uv.os())
console.log(uni.$uv.sys())
console.log(uni.$uv.trim(' abc ')) // 去除两端空格
console.log(uni.$uv.random(1, 3)) // 获取随机数
const qrcode = ref(null)
console.log(uni.$uv.os());
console.log(uni.$uv.sys());
console.log(uni.$uv.trim(" abc ")); // 去除两端空格
console.log(uni.$uv.random(1, 3)); // 获取随机数
const qrcode = ref(null);
const options = reactive({
size: 300,
useDynamicSize: false,
margin: 10,
backgroundColor: '#fff',
backgroundColor: "#fff",
// 指定二维码前景,一般可在中间放logo
foregroundImageSrc: '/static/logo.svg',
})
foregroundImageSrc: "/static/logo.svg",
});
const remakeQc = () => {
qrcode.value.remake({
success: () => {
console.log('生成成功')
console.log("生成成功");
},
fail: (err) => {
console.log(err)
console.log(err);
},
})
}
});
};
const iconName = ref<string>('level')
const iconName = ref<string>("level");
onLoad(() => {
setTimeout(() => {
iconName.value = 'chat'
}, 1000)
})
iconName.value = "chat";
}, 1000);
});
const popup = ref()
const popup = ref();
const open = () => {
popup.value?.open()
}
popup.value?.open();
};
const change = (e) => {
console.log('弹窗状态改变:', e)
}
console.log("弹窗状态改变:", e);
};
</script>
<style lang="scss" scoped>
......
......@@ -7,16 +7,18 @@
<template>
<view class="text-5 h-8 leading-8">
<view class="text-red-500">在非正式版小程序里面已经集成了VConsole</view>
<view class="text-blue-500 mb-2">开启方式如下面</view>
<image
src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/vconsole-1.png"
mode="widthFix"
/>
<view class="text-blue-500 m-2">然后页面上会出现一个 `vConsole` 的调试按钮,如下图</view>
<image
src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/vconsole-2.png"
mode="widthFix"
/>
<view class="text-red-500">
在非正式版小程序里面已经集成了VConsole
</view>
<view class="text-blue-500 mb-2">
开启方式如下面
</view>
<image mode="widthFix"
src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/vconsole-1.png" />
<view class="text-blue-500 m-2">
然后页面上会出现一个 `vConsole` 的调试按钮,如下图
</view>
<image mode="widthFix"
src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/vconsole-2.png" />
</view>
</template>
......@@ -10,18 +10,27 @@
<template>
<view class="center pt-4 flex-col">
<wd-button>主要按钮</wd-button>
<wd-button type="success">成功按钮</wd-button>
<wd-button type="info">信息按钮</wd-button>
<wd-button type="warning">警告按钮</wd-button>
<wd-button type="error">危险按钮</wd-button>
<wd-button type="success">
成功按钮
</wd-button>
<wd-button type="info">
信息按钮
</wd-button>
<wd-button type="warning">
警告按钮
</wd-button>
<wd-button type="error">
危险按钮
</wd-button>
<view class="h-10"></view>
<wd-button @click="handleClick">展示幕帘</wd-button>
<wd-curtain
<wd-button @click="handleClick">
展示幕帘
</wd-button>
<wd-curtain src="https://via.placeholder.com/400x200.png/3c9cff/fff"
:value="value"
:width="300"
src="https://via.placeholder.com/400x200.png/3c9cff/fff"
@close="handleClose"
></wd-curtain>
@close="handleClose">
</wd-curtain>
<view class="mt-4">
可以通过 unocss class 类改颜色,也可以通过 color 属性修改颜色,同时存在时以 color 为优先
</view>
......@@ -30,61 +39,73 @@
</view>
<view class="flex m-4">
<wd-icon name="add-circle"></wd-icon>
<wd-icon name="add-circle" color="red"></wd-icon>
<wd-icon color="red" name="add-circle"></wd-icon>
<wd-icon class="text-green" name="add-circle"></wd-icon>
<wd-icon class="text-green" name="add-circle" color="red"></wd-icon>
<wd-icon class="text-green w-10 h-10" name="add-circle" color="red"></wd-icon>
<wd-icon class="text-green"
color="red"
name="add-circle">
</wd-icon>
<wd-icon class="text-green w-10 h-10"
color="red"
name="add-circle">
</wd-icon>
<wd-icon :name="iconName"></wd-icon>
</view>
<view @click="closeOutside" class="mt-4">
<wd-popover v-model="show" content="popover content" @change="handleChange">
<view class="mt-4" @click="closeOutside">
<wd-popover v-model="show"
content="popover content"
@change="handleChange">
<wd-button>点击展示</wd-button>
</wd-popover>
</view>
<view class="mt-4">
<wd-button @click="showModal">点击显示Modal</wd-button>
<wd-button @click="showToast">点击显示toast</wd-button>
<wd-button @click="showModal">
点击显示Modal
</wd-button>
<wd-button @click="showToast">
点击显示toast
</wd-button>
</view>
</view>
</template>
<script lang="ts" setup>
import { useQueue, useMessage, useToast } from 'wot-design-uni'
import { useMessage, useQueue, useToast } from "wot-design-uni";
const { closeOutside } = useQueue()
const message = useMessage()
const toast = useToast()
const show = ref<boolean>(false)
const { closeOutside } = useQueue();
const message = useMessage();
const toast = useToast();
const show = ref<boolean>(false);
function handleChange({ show }) {
console.log(show)
console.log(show);
}
const showModal = () => {
// 顺便测试 message 的使用
message.show('显示隐藏切换')
}
message.show("显示隐藏切换");
};
const showToast = () => {
// 顺便测试 message 的使用
toast.success('unibest 你值得拥有')
}
const value = ref<boolean>(false)
toast.success("unibest 你值得拥有");
};
const value = ref<boolean>(false);
function handleClick() {
value.value = true
value.value = true;
}
function handleClose() {
value.value = false
value.value = false;
}
const iconName = ref<string>('add-circle')
const iconName = ref<string>("add-circle");
onLoad(() => {
setTimeout(() => {
iconName.value = 'check'
}, 1000)
})
iconName.value = "check";
}, 1000);
});
</script>
<style lang="scss" scoped>
......
......@@ -7,22 +7,22 @@
<template>
<view class="bg-slate-100 min-h-full box-border pb-1">
<view class="tab-container sticky top-0 bg-white px-4 center h-12 z-1">
<view
class="w-full text-center h-10 leading-10 rounded-md"
:class="{ 'bg-green-300': idx === currIdx }"
v-for="(tab, idx) in tabList"
<view v-for="(tab, idx) in tabList"
:key="tab.id"
>
<view class="font-800" @click="currIdx = idx">{{ tab.title }}</view>
class="w-full text-center h-10 leading-10 rounded-md"
:class="{ 'bg-green-300': idx === currIdx }">
<view class="font-800" @click="currIdx = idx">
{{ tab.title }}
</view>
</view>
</view>
<view class="bg-slate-100 px-4 pt-3">
<view class="list-container">
<view v-for="item in currContentList" :key="item.path" class="mb-3">
<view
class="flex bg-white items-center justify-between p-3 mb-2"
@click="goDetailPage(item.path)"
>
<view v-for="item in currContentList"
:key="item.path"
class="mb-3">
<view class="flex bg-white items-center justify-between p-3 mb-2"
@click="goDetailPage(item.path)">
<text class="flex-1 text-4 text-dark">{{ item.title }}</text>
<text class="i-carbon-chevron-right"></text>
</view>
......@@ -33,78 +33,78 @@
</template>
<script setup lang="ts" name="TestIndex">
import pagesJson from '@/pages.json'
import pagesJson from "@/pages.json";
const handleTitle = (str?: string) => {
if (!str) {
return '标题'
return "标题";
}
if (/%.*%/.test(str)) {
return '多语言'
return "多语言";
}
return str
}
return str;
};
/** 基本功能 */
const baseDemos = pagesJson.pages
.filter((e) => e.path.startsWith('pages/demo/base') && !e.hide)
.filter((e) => e.path.startsWith("pages/demo/base") && !e.hide)
.map((e) => ({
title: handleTitle(e.style?.navigationBarTitleText),
path: e.path,
}))
}));
/** 页面功能 */
const pageDemos = pagesJson.pages
.filter((e) => e.path.startsWith('pages/demo/page') && !e.hide)
.filter((e) => e.path.startsWith("pages/demo/page") && !e.hide)
.map((e) => ({
title: handleTitle(e.style?.navigationBarTitleText),
path: e.path,
}))
}));
const routeInterceptionList = [
{
title: '说明页面',
path: 'pages/demo/route-interceptor/index',
title: "说明页面",
path: "pages/demo/route-interceptor/index",
},
{
title: '单独登录页面',
path: 'pages/demo/route-interceptor/login-page?name=feige&age=30',
title: "单独登录页面",
path: "pages/demo/route-interceptor/login-page?name=feige&age=30",
},
{
title: '登录弹窗',
path: 'pages/demo/route-interceptor/login-model?name=feige&age=30',
title: "登录弹窗",
path: "pages/demo/route-interceptor/login-model?name=feige&age=30",
},
{
title: '静默登录',
path: 'pages/demo/route-interceptor/login-auto?name=feige&age=30',
title: "静默登录",
path: "pages/demo/route-interceptor/login-auto?name=feige&age=30",
},
]
];
const tabList = reactive([
{
id: 1,
title: '基础功能',
title: "基础功能",
list: baseDemos,
},
{
id: 2,
title: '登录拦截',
title: "登录拦截",
list: routeInterceptionList,
},
{
id: 3,
title: '页面功能',
title: "页面功能",
list: pageDemos,
},
])
const currIdx = ref(0)
]);
const currIdx = ref(0);
const currContentList = computed(() => {
return tabList[currIdx.value].list
})
return tabList[currIdx.value].list;
});
const goDetailPage = (path: string) => {
const url = `/${path}`
const url = `/${path}`;
uni.navigateTo({
url,
})
}
});
};
</script>
<style>
......
......@@ -6,11 +6,18 @@
</route>
<template>
<view class="mt-4 h-10 text-center">动态时钟</view>
<view class="mt-4 h-10 text-center">
动态时钟
</view>
<view class="clock-box">
<view class="clock" :style="{ '--ds': ds, '--dm': dm, '--dh': dh }">
<view class="clock-pane">
<text class="clock-num" :style="{ '--i': n }" v-for="n in 12" :key="n">{{ n }}</text>
<text v-for="n in 12"
:key="n"
class="clock-num"
:style="{ '--i': n }">
{{ n }}
</text>
</view>
<view class="clock-hour"></view>
<view class="clock-min"></view>
......@@ -20,13 +27,13 @@
</template>
<script lang="ts" setup>
const d = new Date()
const h = d.getHours()
const m = d.getMinutes()
const s = d.getSeconds()
const ds = ref(s)
const dm = ref(m + s / 60)
const dh = ref(h + m / 60 + s / 3600)
const d = new Date();
const h = d.getHours();
const m = d.getMinutes();
const s = d.getSeconds();
const ds = ref(s);
const dm = ref(m + s / 60);
const dh = ref(h + m / 60 + s / 3600);
</script>
<style lang="scss">
......@@ -37,6 +44,8 @@ const dh = ref(h + m / 60 + s / 3600)
}
.clock {
--step: 60s;
position: relative;
display: flex;
align-items: center;
......@@ -46,7 +55,6 @@ const dh = ref(h + m / 60 + s / 3600)
font-size: 24px;
border-radius: 20px;
box-shadow: 2px 2px 20px #0000001a;
--step: 60s;
}
.clock::before {
......
......@@ -6,14 +6,25 @@
</route>
<template>
<view class="mt-4 h-10 text-center">动态时钟</view>
<view class="mt-4 h-10 text-center">
动态时钟
</view>
<view class="clock-box">
<view class="clock" :style="{ '--ds': ds, '--dm': dm, '--dh': dh }">
<view class="clock-pane">
<text class="clock-num" :style="{ '--i': n }" v-for="n in 12" :key="n">{{ n }}</text>
<text v-for="n in 12"
:key="n"
class="clock-num"
:style="{ '--i': n }">
{{ n }}
</text>
</view>
<view class="clock-scales">
<text class="clock-scale" :style="{ '--i': n }" v-for="n in 60" :key="n"></text>
<text v-for="n in 60"
:key="n"
class="clock-scale"
:style="{ '--i': n }">
</text>
</view>
<view class="clock-hour"></view>
......@@ -24,13 +35,13 @@
</template>
<script lang="ts" setup>
const d = new Date()
const h = d.getHours()
const m = d.getMinutes()
const s = d.getSeconds()
const ds = ref(s)
const dm = ref(m + s / 60)
const dh = ref(h + m / 60 + s / 3600)
const d = new Date();
const h = d.getHours();
const m = d.getMinutes();
const s = d.getSeconds();
const ds = ref(s);
const dm = ref(m + s / 60);
const dh = ref(h + m / 60 + s / 3600);
</script>
<style lang="scss">
......@@ -41,6 +52,8 @@ const dh = ref(h + m / 60 + s / 3600)
}
.clock {
--step: 60s;
position: relative;
display: flex;
align-items: center;
......@@ -50,7 +63,6 @@ const dh = ref(h + m / 60 + s / 3600)
font-size: 24px;
border-radius: 20px;
box-shadow: 2px 2px 20px #0000001a;
--step: 60s;
}
.clock-pane {
......
import { useEcharts } from '@/hooks/useEcharts'
import { ref } from 'vue'
import { ref } from "vue";
import { useEcharts } from "@/hooks/useEcharts";
// 折线图
export const useLineEcharts = (): any => {
......@@ -8,7 +9,7 @@ export const useLineEcharts = (): any => {
// 应用 这个类型的图表时,只需在 .vue 文件中通过 set 修复数据即可,或者简单的样式修改,如果样式过于复杂,可以重新建立一个 linkHookB 等等
const option = ref({
xAxis: {
data: [12, 13, 10, 13, 9, 23, 21, 32, 12, 15, 13, 10],
data: [ 12, 13, 10, 13, 9, 23, 21, 32, 12, 15, 13, 10 ],
boundaryGap: false,
axisTick: {
show: false,
......@@ -16,12 +17,12 @@ export const useLineEcharts = (): any => {
axisLine: {
show: true,
lineStyle: {
color: '#0C4787',
color: "#0C4787",
},
},
axisLabel: {
show: true,
color: '#000000',
color: "#000000",
},
},
grid: {
......@@ -32,11 +33,11 @@ export const useLineEcharts = (): any => {
containLabel: true,
},
tooltip: {
trigger: 'axis',
trigger: "axis",
axisPointer: {
type: 'cross',
type: "cross",
},
padding: [5, 10],
padding: [ 5, 10 ],
},
yAxis: {
axisTick: {
......@@ -48,29 +49,29 @@ export const useLineEcharts = (): any => {
axisLine: {
show: true,
lineStyle: {
color: '#0C4787',
color: "#0C4787",
},
},
axisLabel: {
show: true,
color: '#000000',
color: "#000000",
},
},
series: {
smooth: true,
type: 'line',
data: [12, 13, 10, 13, 9, 23, 21, 32, 12, 15, 13, 10],
type: "line",
data: [ 12, 13, 10, 13, 9, 23, 21, 32, 12, 15, 13, 10 ],
animationDuration: 2800,
animationEasing: 'cubicInOut',
symbol: 'circle',
color: '#fed42b',
animationEasing: "cubicInOut",
symbol: "circle",
color: "#fed42b",
symbolSize: 8,
lineStyle: {
color: '#fed42b', // 改变折线颜色
color: "#fed42b", // 改变折线颜色
},
areaStyle: {
color: {
type: 'linear',
type: "linear",
x: 0,
y: 0,
x2: 0,
......@@ -78,38 +79,38 @@ export const useLineEcharts = (): any => {
colorStops: [
{
offset: 0,
color: '#fed42b', // 0% 处的颜色
color: "#fed42b", // 0% 处的颜色
},
{
offset: 1,
color: 'rgba(254, 212, 43, 0.1)', // 100% 处的颜色
color: "rgba(254, 212, 43, 0.1)", // 100% 处的颜色
},
],
global: false, // 缺省为 false
},
},
},
})
return useEcharts(option)
}
});
return useEcharts(option);
};
// 柱状图
export const useBarEcharts = (): any => {
const option = ref({
xAxis: {
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
data: [ "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" ],
axisTick: {
show: false,
},
axisLine: {
show: true,
lineStyle: {
color: '#0C4787',
color: "#0C4787",
},
},
axisLabel: {
show: true,
color: '#000000',
color: "#000000",
},
},
grid: {
......@@ -120,11 +121,11 @@ export const useBarEcharts = (): any => {
containLabel: true,
},
tooltip: {
trigger: 'axis',
trigger: "axis",
axisPointer: {
type: 'cross',
type: "cross",
},
padding: [5, 10],
padding: [ 5, 10 ],
},
yAxis: {
axisTick: {
......@@ -136,25 +137,25 @@ export const useBarEcharts = (): any => {
axisLine: {
show: true,
lineStyle: {
color: '#0C4787',
color: "#0C4787",
},
},
axisLabel: {
show: true,
color: '#000000',
color: "#000000",
},
},
series: {
type: 'bar',
data: [120, 200, 150, 80, 70, 110, 130],
type: "bar",
data: [ 120, 200, 150, 80, 70, 110, 130 ],
animationDuration: 2800,
animationEasing: 'cubicInOut',
color: '#fed42b',
animationEasing: "cubicInOut",
color: "#fed42b",
barWidth: 10,
itemStyle: {
barBorderRadius: [3, 3, 0, 0],
barBorderRadius: [ 3, 3, 0, 0 ],
},
},
})
return useEcharts(option)
}
});
return useEcharts(option);
};
......@@ -20,64 +20,72 @@
<view style="width: 100%; height: 200px">
<l-echart ref="barChartRef" />
</view>
<button @click="changeLineChartData">切换折线图1数据</button>
<button @click="changeBarChartData">改变柱状图样式</button>
<button @click="changeLineChartData">
切换折线图1数据
</button>
<button @click="changeBarChartData">
改变柱状图样式
</button>
</template>
<script setup lang="ts">
import { onMounted } from 'vue'
import { useBarEcharts, useLineEcharts } from './echartsData'
import { set } from 'lodash-es'
const [lineChartRef, lineOption, lineDraw] = useLineEcharts()
const [lineChartRef2, lineOption2, lineDraw2] = useLineEcharts()
const [barChartRef, barOption, barDraw] = useBarEcharts()
import { onMounted } from "vue";
import { set } from "lodash-es";
import { useBarEcharts, useLineEcharts } from "./echartsData";
const [ lineChartRef, lineOption, lineDraw ] = useLineEcharts();
const [ lineChartRef2, lineOption2, lineDraw2 ] = useLineEcharts();
const [ barChartRef, barOption, barDraw ] = useBarEcharts();
// 初始化 折线图表1
const initLineChart = () => {
set(lineOption.value, 'series.data', [120, 132, 101, 134, 90, 230, 210, 220, 182, 191, 234, 290])
lineDraw()
}
set(lineOption.value, "series.data", [ 120, 132, 101, 134, 90, 230, 210, 220, 182, 191, 234, 290 ]);
lineDraw();
};
// 初始化 折线图表2
const initLineChart2 = () => {
set(
lineOption2.value,
'series.data',
[220, 182, 191, 234, 290, 330, 310, 320, 302, 301, 334, 390],
)
lineDraw2()
}
"series.data",
[ 220, 182, 191, 234, 290, 330, 310, 320, 302, 301, 334, 390 ],
);
lineDraw2();
};
// 初始化 柱状图表
const initBarChart = () => {
set(barOption.value, 'series.data', [120, 200, 150, 80, 70, 110, 130])
barDraw()
}
set(barOption.value, "series.data", [ 120, 200, 150, 80, 70, 110, 130 ]);
barDraw();
};
// 切换折线图数据
const changeLineChartData = () => {
set(lineOption.value, 'series.data', [324, 332, 301, 334, 390, 330, 320, 302, 301, 334, 390, 330])
lineDraw()
}
set(lineOption.value, "series.data", [ 324, 332, 301, 334, 390, 330, 320, 302, 301, 334, 390, 330 ]);
lineDraw();
};
// 改变柱状图样式
const changeBarChartData = () => {
set(barOption.value, 'series.color', '#5677fc')
barDraw()
}
set(barOption.value, "series.color", "#5677fc");
barDraw();
};
onMounted(() => {
initLineChart()
initLineChart2()
initBarChart()
})
initLineChart();
initLineChart2();
initBarChart();
});
</script>
<style>
/* 暗黑模式 start */
.wot-theme-dark {
--theme-bg-color: #222;
color: #f5f5f5;
background: #222;
--theme-bg-color: #222;
}
</style>
......@@ -9,66 +9,68 @@
<template>
<view>
<movable-area class="movable-area">
<movable-view
:style="`--size:${ballSize}px`"
class="movable-view"
<movable-view class="movable-view"
direction="all"
:style="`--size:${ballSize}px`"
:x="x"
:y="y"
@change="onChange"
@touchend.prevent="onTouchEnd"
>
@touchend.prevent="onTouchEnd">
<view class="w-full h-full rounded-full bg-green-400"></view>
</movable-view>
</movable-area>
<view>页面其他元素</view>
<view>可以正常触发点击事件吗?答案是可以的</view>
<button @click="onClick">按钮</button>
<button @click="onClick">
按钮
</button>
<view>{{ x }}</view>
<view>{{ y }}</view>
<view @click="onSet">点击设置</view>
<view @click="onSet">
点击设置
</view>
</view>
</template>
<script lang="ts" setup name="FloatingBubble">
const { windowHeight, windowWidth } = uni.getSystemInfoSync()
const { windowHeight, windowWidth } = uni.getSystemInfoSync();
const ballSize = 60
const x = ref(windowWidth - ballSize) // 靠右侧
const y = ref(windowHeight - ballSize - 20) // 距离底部20px
const ballSize = 60;
const x = ref(windowWidth - ballSize); // 靠右侧
const y = ref(windowHeight - ballSize - 20); // 距离底部20px
const middleX = (windowWidth - ballSize) / 2
const middleX = (windowWidth - ballSize) / 2;
const onChange = (e) => {
const { x: _x, y: _y } = e.detail
x.value = _x
y.value = _y
}
const { x: _x, y: _y } = e.detail;
x.value = _x;
y.value = _y;
};
// TODO: 期望最终落点不靠左右两边时,会自动回到两边,有一定的动画效果
const onTouchEnd = (e) => {
console.log('onTouchEnd', e)
console.log("onTouchEnd", e);
// TODO:为啥这里设置的不生效了,原生不会移动到设置的地方,onSet里面可以。这里直接执行onSet也不行
// 这里被我解决了
const tid = setTimeout(() => {
if (x.value < middleX) {
x.value = 0
x.value = 0;
} else {
x.value = windowWidth - ballSize
x.value = windowWidth - ballSize;
}
clearTimeout(tid)
}, 0)
}
clearTimeout(tid);
}, 0);
};
const onClick = () => {
uni.showToast({
title: 'yes',
icon: 'none',
})
}
title: "yes",
icon: "none",
});
};
const onSet = () => {
x.value = 100
y.value = 100
}
x.value = 100;
y.value = 100;
};
</script>
<style lang="scss">
......
......@@ -14,16 +14,26 @@
<view>1. 页面标题多语言不生效</view>
<view>2. 多语言传递的参数不生效,如下 heavy</view>
</view>
<view class="text-green-500">多语言测试</view>
<view class="m-4">{{ $t('app.name') }}</view>
<view class="m-4">{{ $t('weight', { heavy: 100 }) }}</view>
<view class="text-green-500">
多语言测试
</view>
<view class="m-4">
{{ $t('app.name') }}
</view>
<view class="m-4">
{{ $t('weight', { heavy: 100 }) }}
</view>
<view class="text-green-500 mt-12">切换语言</view>
<view class="text-green-500 mt-12">
切换语言
</view>
<view class="uni-list">
<radio-group @change="radioChange" class="radio-group">
<label class="uni-list-cell uni-list-cell-pd" v-for="item in languages" :key="item.value">
<radio-group class="radio-group" @change="radioChange">
<label v-for="item in languages"
:key="item.value"
class="uni-list-cell uni-list-cell-pd">
<view>
<radio :value="item.value" :checked="item.value === current" />
<radio :checked="item.value === current" :value="item.value" />
</view>
<view>{{ item.name }}</view>
</label>
......@@ -31,34 +41,36 @@
</view>
<!-- http://localhost:9100/#/pages/index/i18n -->
<button @click="testI18n" class="mt-20 mb-44">测试弹窗</button>
<button class="mt-20 mb-44" @click="testI18n">
测试弹窗
</button>
</view>
</template>
<script lang="ts" setup>
import i18n from '@/locale/index'
import { testI18n } from '@/utils/index'
import i18n from "@/locale/index";
import { testI18n } from "@/utils/index";
const current = ref(uni.getLocale())
const current = ref(uni.getLocale());
const languages = [
{
value: 'zh-Hans',
name: '中文',
checked: 'true',
value: "zh-Hans",
name: "中文",
checked: "true",
},
{
value: 'en',
name: '英文',
value: "en",
name: "英文",
},
]
];
const radioChange = (evt) => {
// console.log(evt)
current.value = evt.detail.value
current.value = evt.detail.value;
// 下面2句缺一不可!!!
uni.setLocale(evt.detail.value)
i18n.global.locale = evt.detail.value
}
uni.setLocale(evt.detail.value);
i18n.global.locale = evt.detail.value;
};
</script>
<style lang="scss">
......
......@@ -5,10 +5,6 @@
}
</route>
<script setup lang="ts">
import testBgImg from './test-bg.png'
</script>
<template>
<view class="m-4 text-center">
<view class="mb-2 text-orange-500">
......@@ -18,24 +14,24 @@ import testBgImg from './test-bg.png'
微信小程序有包体积的限制,图片通常使用线上地址,不用本地图片就用不上这个插件了。
</view>
<!-- #ifdef MP -->
<image
src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/imgmin-bg.png"
mode="scaleToFill"
/>
<image mode="scaleToFill"
src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/imgmin-bg.png" />
<!-- #endif -->
<!-- #ifndef MP -->
<image :src="testBgImg" mode="scaleToFill" />
<image mode="scaleToFill" :src="testBgImg" />
<!-- #endif -->
<view class="mb-4">对比图如下2图,如果看不清请看代码原图</view>
<image
src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/imgmin-before.png"
<view class="mb-4">
对比图如下2图,如果看不清请看代码原图
</view>
<image class="w-full"
mode="widthFix"
class="w-full"
/>
<image
src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/imgmin-after.png"
src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/imgmin-before.png" />
<image class="w-full"
mode="widthFix"
class="w-full"
/>
src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/imgmin-after.png" />
</view>
</template>
<script setup lang="ts">
import testBgImg from "./test-bg.png";
</script>
......@@ -9,13 +9,11 @@
<view class="text-center">
<view class="container">
<view class="prize-list" :style="styleObj">
<view
class="prize-item"
v-for="(item, index) in prizeList"
<view v-for="(item, index) in prizeList"
:key="item.id"
:style="prizeStyle(index)"
>
<image :src="item.pic" class="gift-img" />
class="prize-item"
:style="prizeStyle(index)">
<image class="gift-img" :src="item.pic" />
<text class="gift-name">{{ item.name }}</text>
</view>
</view>
......@@ -25,11 +23,11 @@
</template>
<script lang="ts" setup>
import { ref, computed } from 'vue'
import { computed, ref } from "vue";
// TODO: fix 微信小程序里面会报错
// import targetImg from 'https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/ui.png'
let isLeaved = false
let isLeaved = false;
// onBackPress(({ from }: { from: 'backbutton' | 'navigateBack' }) => {
// console.log('onBackPress', from)
// isLeaved = true
......@@ -37,76 +35,76 @@ let isLeaved = false
// })
// onBackPress 有兼容性问题,统一使用 onUnload,测试验证OK
onUnload(() => {
isLeaved = true
console.log('onUnload', isLeaved)
})
isLeaved = true;
console.log("onUnload", isLeaved);
});
// 后台配置的奖品数据
const prizeList = [
{
id: 0,
name: '双肩包',
pic: 'https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/backpack.jpeg',
name: "双肩包",
pic: "https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/backpack.jpeg",
},
{
id: 1,
name: '积木',
pic: 'https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/jimu.jpg',
name: "积木",
pic: "https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/jimu.jpg",
},
{
id: 2,
name: '红包',
pic: 'https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/red-envelope.jpg',
name: "红包",
pic: "https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/red-envelope.jpg",
},
{
id: 3,
name: '茶具',
pic: 'https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/tea-set.jpg',
name: "茶具",
pic: "https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/tea-set.jpg",
},
{
id: 4,
name: '可爱脸',
pic: 'https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/tushetou.jpg',
name: "可爱脸",
pic: "https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/tushetou.jpg",
},
{
id: 5,
name: '挖掘机',
pic: 'https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/wajueji.jpg',
name: "挖掘机",
pic: "https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/wajueji.jpg",
},
{
id: 6,
name: '无辜脸',
pic: 'https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/xiaolian.jpg',
name: "无辜脸",
pic: "https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/xiaolian.jpg",
},
{
id: 7,
name: '烟灰缸',
pic: 'https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/yanhuigang.jpg',
name: "烟灰缸",
pic: "https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/yanhuigang.jpg",
},
]
let isRunning = false // 是否正在抽奖
const baseRunAngle = 360 * 5 // 总共转动角度 至少5圈
let prizeId = 0 // 中奖id
];
let isRunning = false; // 是否正在抽奖
const baseRunAngle = 360 * 5; // 总共转动角度 至少5圈
let prizeId = 0; // 中奖id
// 平均每个奖品角度
const rotateAngle = computed(() => {
const _degree = 360 / prizeList.length
return _degree
})
const _degree = 360 / prizeList.length;
return _degree;
});
// 要执行总角度数
const totalRunAngle = ref(baseRunAngle - (prizeId + 0.5) * rotateAngle.value)
const totalRunAngle = ref(baseRunAngle - (prizeId + 0.5) * rotateAngle.value);
// 计算绘制转盘背景
const bgColor = (() => {
const [c1, c2] = ['#5352b3', '#363589']
const [ c1, c2 ] = [ "#5352b3", "#363589" ];
// repeating-conic-gradient(red 0 15deg, blue 15deg 30deg);
return `background: repeating-conic-gradient(${c1} 0 ${rotateAngle.value}deg,
${c2} ${rotateAngle.value}deg ${2 * rotateAngle.value}deg);`
})()
${c2} ${rotateAngle.value}deg ${2 * rotateAngle.value}deg);`;
})();
const styleObj = ref(bgColor)
const styleObj = ref(bgColor);
// 每个奖品布局
const prizeStyle = computed(() => {
const _degree = rotateAngle.value
const _degree = rotateAngle.value;
return (i) => {
// 外框大小设置为90vw,里面是一半,45vw
return `
......@@ -114,51 +112,51 @@ const prizeStyle = computed(() => {
height: 45vw;
transform: rotate(${_degree * i + _degree / 2}deg);
transform-origin: 50% 100%;
`
}
})
`;
};
});
// 获取随机数
const getRandomNum = () => {
const num = Math.floor(Math.random() * prizeList.length)
return num
}
const num = Math.floor(Math.random() * prizeList.length);
return num;
};
const stopRun = () => {
isRunning = false
isRunning = false;
if (isLeaved) {
console.log('已经离开页面了,不用显示弹窗')
return
console.log("已经离开页面了,不用显示弹窗");
return;
}
const prizeName = prizeList.find((e) => e.id === prizeId)!.name
const prizeName = prizeList.find((e) => e.id === prizeId)!.name;
uni.showModal({
title: `恭喜你中奖 ${prizeName}`,
success() {
styleObj.value = `${bgColor} transform: rotate(0deg);`
styleObj.value = `${bgColor} transform: rotate(0deg);`;
},
})
}
});
};
const startRun = () => {
console.log(isRunning, totalRunAngle.value)
console.log(isRunning, totalRunAngle.value);
// 设置动效
styleObj.value = `${bgColor} transform: rotate(${totalRunAngle.value}deg); transition: all 4s ease;`
setTimeout(stopRun, 4000)
}
styleObj.value = `${bgColor} transform: rotate(${totalRunAngle.value}deg); transition: all 4s ease;`;
setTimeout(stopRun, 4000);
};
const start = () => {
if (!isRunning) {
isRunning = true
isRunning = true;
console.log('开始抽奖,后台请求中奖奖品')
console.log("开始抽奖,后台请求中奖奖品");
// 请求返回的奖品编号 这里使用随机数
prizeId = getRandomNum()
totalRunAngle.value = baseRunAngle - (prizeId + 0.5) * rotateAngle.value
console.log('中奖ID>>>', prizeId, prizeList[prizeId], totalRunAngle.value)
prizeId = getRandomNum();
totalRunAngle.value = baseRunAngle - (prizeId + 0.5) * rotateAngle.value;
console.log("中奖ID>>>", prizeId, prizeList[prizeId], totalRunAngle.value);
nextTick(() => {
startRun()
})
startRun();
});
}
}
};
</script>
<style lang="scss">
......
......@@ -7,14 +7,12 @@
<template>
<view>
<view class="container">
<view
<view v-for="(item, index) in prizeList"
:key="index"
class="gift-item"
:class="{ active: currentIndex === index }"
v-for="(item, index) in prizeList"
:key="index"
@click="start(index)"
>
<image :src="item.pic" class="gift-img" />
@click="start(index)">
<image class="gift-img" :src="item.pic" />
<text v-if="index !== 4" class="gift-name">{{ item.name }}</text>
</view>
</view>
......@@ -22,9 +20,9 @@
</template>
<script lang="ts" setup>
import { ref, computed } from 'vue'
import { computed, ref } from "vue";
let isLeaved = false
let isLeaved = false;
// onBackPress(({ from }: { from: 'backbutton' | 'navigateBack' }) => {
// console.log('onBackPress', from)
// isLeaved = true
......@@ -33,135 +31,135 @@ let isLeaved = false
// onBackPress 有兼容性问题,统一使用 onUnload,测试验证OK
onUnload(() => {
isLeaved = true
console.log('onUnload', isLeaved)
})
isLeaved = true;
console.log("onUnload", isLeaved);
});
const currentIndex = ref(0) // 当前位置
const currentIndex = ref(0); // 当前位置
// 后台配置的奖品数据
const prizeList = [
{
id: 0,
name: '双肩包',
pic: 'https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/backpack.jpeg',
name: "双肩包",
pic: "https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/backpack.jpeg",
},
{
id: 1,
name: '积木',
pic: 'https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/jimu.jpg',
name: "积木",
pic: "https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/jimu.jpg",
},
{
id: 2,
name: '红包',
pic: 'https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/red-envelope.jpg',
name: "红包",
pic: "https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/red-envelope.jpg",
},
{
id: 3,
name: '茶具',
pic: 'https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/tea-set.jpg',
name: "茶具",
pic: "https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/tea-set.jpg",
},
{
id: 5,
name: '可爱脸',
pic: 'https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/tushetou.jpg',
name: "可爱脸",
pic: "https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/tushetou.jpg",
},
{
id: 6,
name: '挖掘机',
pic: 'https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/wajueji.jpg',
name: "挖掘机",
pic: "https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/wajueji.jpg",
},
{
id: 7,
name: '无辜脸',
pic: 'https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/xiaolian.jpg',
name: "无辜脸",
pic: "https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/xiaolian.jpg",
},
{
id: 8,
name: '烟灰缸',
pic: 'https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/yanhuigang.jpg',
name: "烟灰缸",
pic: "https://oss.laf.run/ukw0y1-site/hello-unibest-images/lottery/prizes/yanhuigang.jpg",
},
]
];
const startBtn = {
id: 4,
name: '开始按钮',
pic: 'https://img2.baidu.com/it/u=1497996119,382735686&fm=253',
}
name: "开始按钮",
pic: "https://img2.baidu.com/it/u=1497996119,382735686&fm=253",
};
// 九宫格中间位置插入开始按钮
prizeList.splice(4, 0, startBtn)
prizeList.splice(4, 0, startBtn);
// 奖品高亮顺序
const prizeSort = [0, 1, 2, 5, 8, 7, 6, 3]
const prizeSort = [ 0, 1, 2, 5, 8, 7, 6, 3 ];
// 获取随机数
const getRandomNum = () => prizeSort[Math.floor(Math.random() * prizeSort.length)]
const getRandomNum = () => prizeSort[Math.floor(Math.random() * prizeSort.length)];
let isRunning = false // 是否正在抽奖
let speed = 10 // 抽奖转动速度
let timerIns = null // 定时器实例
let currentRunCount = 0 // 已跑次数
const totalRunCount = 32 // 总共跑动次数,8的倍数即可
let prizeId = 0 // 中奖id(0-8,不能是4)
let isRunning = false; // 是否正在抽奖
let speed = 10; // 抽奖转动速度
let timerIns = null; // 定时器实例
let currentRunCount = 0; // 已跑次数
const totalRunCount = 32; // 总共跑动次数,8的倍数即可
let prizeId = 0; // 中奖id(0-8,不能是4)
// 要执行总步数
const totalRunStep = computed(() => {
return totalRunCount + prizeSort.indexOf(prizeId)
})
return totalRunCount + prizeSort.indexOf(prizeId);
});
const stopRun = () => {
// eslint-disable-next-line no-unused-expressions
timerIns && clearTimeout(timerIns)
}
timerIns && clearTimeout(timerIns);
};
const startRun = () => {
stopRun()
console.log(currentRunCount, totalRunStep.value)
stopRun();
console.log(currentRunCount, totalRunStep.value);
// 要执行总步数
// 已走步数超过
if (currentRunCount > totalRunStep.value) {
isRunning = false
isRunning = false;
if (isLeaved) {
console.log('已经离开页面了,不用显示弹窗')
return
console.log("已经离开页面了,不用显示弹窗");
return;
}
const prizeName = prizeList.find((e) => e.id === prizeId)!.name
const prizeName = prizeList.find((e) => e.id === prizeId)!.name;
uni.showModal({
title: `恭喜你中奖 ${prizeName}`,
})
return
});
return;
}
currentIndex.value = prizeSort[currentRunCount % 8]
currentIndex.value = prizeSort[currentRunCount % 8];
// 如果当前步数超过了2/3则速度慢下来
if (currentRunCount > Math.floor((totalRunCount * 2) / 3)) {
speed += Math.floor(currentRunCount / 3)
console.log('速度>>>>', speed)
speed += Math.floor(currentRunCount / 3);
console.log("速度>>>>", speed);
}
timerIns = setTimeout(() => {
currentRunCount++
startRun()
}, speed)
}
currentRunCount++;
startRun();
}, speed);
};
const start = (i) => {
if (i === 4 && !isRunning) {
// 重置数据
currentRunCount = 0
speed = 100
isRunning = true
currentRunCount = 0;
speed = 100;
isRunning = true;
console.log('开始抽奖,后台请求中奖奖品')
console.log("开始抽奖,后台请求中奖奖品");
// 请求返回的奖品编号 这里使用随机数 但不能为4
// const prizeId = getRandomNum()
// console.log('中奖ID>>>', prizeId, prizeList[prizeId])
// prizeId = prizeId
// 模拟接口延时返回 如果接口突然报错如何处理?直接调用stopRun()方法停止转动
setTimeout(() => {
prizeId = getRandomNum()
console.log('中奖ID>>>', prizeId, prizeList[prizeId])
prizeId = getRandomNum();
console.log("中奖ID>>>", prizeId, prizeList[prizeId]);
// 拿到数据才可以跑
}, 2000)
startRun()
}, 2000);
startRun();
}
}
};
</script>
<style lang="scss">
.container {
......
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!