Commit 7efe0ec2 by Jaxon

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

1 parent a4bc4cbc
Showing 152 changed files with 1768 additions and 1761 deletions
...@@ -3,3 +3,4 @@ public ...@@ -3,3 +3,4 @@ public
__tests__ __tests__
coverage coverage
miniprogram_npm miniprogram_npm
uni_modules
...@@ -36,33 +36,33 @@ ...@@ -36,33 +36,33 @@
"source.fixAll.stylelint": "explicit", "source.fixAll.stylelint": "explicit",
"source.organizeImports": "never" "source.organizeImports": "never"
}, },
"editor.defaultFormatter": "esbenp.prettier-vscode", "editor.defaultFormatter": "dbaeumer.vscode-eslint",
"[html]": { "[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode" "editor.defaultFormatter": "dbaeumer.vscode-eslint"
}, },
"[css]": { "[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode" "editor.defaultFormatter": "dbaeumer.vscode-eslint"
}, },
"[scss]": { "[scss]": {
"editor.defaultFormatter": "esbenp.prettier-vscode" "editor.defaultFormatter": "dbaeumer.vscode-eslint"
}, },
"[javascript]": { "[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode" "editor.defaultFormatter": "dbaeumer.vscode-eslint"
}, },
"[typescript]": { "[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode" "editor.defaultFormatter": "dbaeumer.vscode-eslint"
}, },
"[json]": { "[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode" "editor.defaultFormatter": "dbaeumer.vscode-eslint"
}, },
"[markdown]": { "[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode" "editor.defaultFormatter": "dbaeumer.vscode-eslint"
}, },
"[jsonc]": { "[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode" "editor.defaultFormatter": "dbaeumer.vscode-eslint"
}, },
"[vue]": { "[vue]": {
"editor.defaultFormatter": "esbenp.prettier-vscode" "editor.defaultFormatter": "dbaeumer.vscode-eslint"
}, },
// extensions // extensions
"extensions.ignoreRecommendations": true, "extensions.ignoreRecommendations": true,
...@@ -107,19 +107,22 @@ ...@@ -107,19 +107,22 @@
"**/.git/subtree-cache/**": true, "**/.git/subtree-cache/**": true,
"**/.vscode/**": true, "**/.vscode/**": true,
"**/node_modules/**": true, "**/node_modules/**": true,
"**/uni_modules/**": true,
"**/miniprogram_npm/**": true,
"**/tmp/**": true, "**/tmp/**": true,
"**/bower_components/**": true, "**/bower_components/**": true,
"**/dist/**": true, "**/dist/**": true,
"**/yarn.lock": true "**/yarn.lock": true
}, },
"typescript.tsserver.exclude": ["**/node_modules", "**/dist", "**/.turbo"], "typescript.tsserver.exclude": ["**/node_modules", "**/dist", "**/.turbo","**/uni_modules","**/miniprogram_npm"],
// search // search
"search.searchEditor.singleClickBehaviour": "peekDefinition", "search.searchEditor.singleClickBehaviour": "peekDefinition",
"search.followSymlinks": false, "search.followSymlinks": false,
// 在使用搜索功能时,将这些文件夹/文件排除在外 // 在使用搜索功能时,将这些文件夹/文件排除在外
"search.exclude": { "search.exclude": {
"**/uni_modules": true,
"**/miniprogram_npm":true, "**/miniprogram_npm":true,
"**/node_modules": true, "**/node_modules": true,
"**/*.log": true, "**/*.log": true,
...@@ -226,5 +229,15 @@ ...@@ -226,5 +229,15 @@
"vue.server.hybridMode": true, "vue.server.hybridMode": true,
"typescript.tsdk": "node_modules/typescript/lib", "typescript.tsdk": "node_modules/typescript/lib",
"oxc.enable": false, "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"
]
} }
...@@ -15,14 +15,14 @@ ...@@ -15,14 +15,14 @@
padding-bottom: env(safe-area-inset-bottom); padding-bottom: env(safe-area-inset-bottom);
} }
.safeAreaNewPaddingBttom{ .safeAreaNewPaddingBttom{
padding-bottom: constant(safe-area-inset-bottom); padding-bottom: constant(safe-area-inset-bottom);
} }
.safeAreaOldMarginBttom { .safeAreaOldMarginBttom {
margin-bottom: env(safe-area-inset-bottom); margin-bottom: env(safe-area-inset-bottom);
} }
.safeAreaNewMarginBttom{ .safeAreaNewMarginBttom{
margin-bottom: constant(safe-area-inset-bottom); margin-bottom: constant(safe-area-inset-bottom);
} }
.no-data { .no-data {
...@@ -82,4 +82,4 @@ page { ...@@ -82,4 +82,4 @@ page {
padding: 0 24rpx; padding: 0 24rpx;
font-size: 24rpx; font-size: 24rpx;
color: #999; color: #999;
}
\ No newline at end of file \ No newline at end of file
}
---
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 // manifest.config.ts
import { defineManifestConfig } from '@uni-helper/vite-plugin-uni-manifest' import { defineManifestConfig } from "@uni-helper/vite-plugin-uni-manifest";
import path from 'node:path' import { loadEnv } from "vite";
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('manifest.config.ts')
// console.log(env) // console.log(env)
const { const {
VITE_APP_TITLE, VITE_APP_TITLE,
VITE_UNI_APPID, VITE_UNI_APPID,
VITE_WX_APPID, VITE_WX_APPID,
VITE_APP_PUBLIC_BASE, VITE_APP_PUBLIC_BASE,
VITE_FALLBACK_LOCALE, VITE_FALLBACK_LOCALE,
} = env } = env;
export default defineManifestConfig({ export default defineManifestConfig({
name: VITE_APP_TITLE, name: VITE_APP_TITLE,
appid: VITE_UNI_APPID, appid: VITE_UNI_APPID,
description: '', description: "",
versionName: '1.0.0', versionName: "1.0.0",
versionCode: '100', versionCode: "100",
transformPx: false, transformPx: false,
locale: VITE_FALLBACK_LOCALE, // 'zh-Hans' locale: VITE_FALLBACK_LOCALE, // 'zh-Hans'
h5: { h5: {
router: { router: {
base: VITE_APP_PUBLIC_BASE, base: VITE_APP_PUBLIC_BASE,
},
}, },
}, /* 5+App特有相关 */
/* 5+App特有相关 */ "app-plus": {
'app-plus': { usingComponents: true,
usingComponents: true, nvueStyleCompiler: "uni-app",
nvueStyleCompiler: 'uni-app', compilerVersion: 3,
compilerVersion: 3, splashscreen: {
splashscreen: { alwaysShowBeforeRender: true,
alwaysShowBeforeRender: true, waiting: true,
waiting: true, autoclose: true,
autoclose: true, delay: 0,
delay: 0, },
/* 模块配置 */
modules: {},
/* 应用发布信息 */
distribute: {
/* android打包配置 */
android: {
minSdkVersion: 30,
targetSdkVersion: 30,
abiFilters: [ "armeabi-v7a", "arm64-v8a" ],
permissions: [
'<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>',
'<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>',
'<uses-permission android:name="android.permission.VIBRATE"/>',
'<uses-permission android:name="android.permission.READ_LOGS"/>',
'<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>',
'<uses-feature android:name="android.hardware.camera.autofocus"/>',
'<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>',
'<uses-permission android:name="android.permission.CAMERA"/>',
'<uses-permission android:name="android.permission.GET_ACCOUNTS"/>',
'<uses-permission android:name="android.permission.READ_PHONE_STATE"/>',
'<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>',
'<uses-permission android:name="android.permission.WAKE_LOCK"/>',
'<uses-permission android:name="android.permission.FLASHLIGHT"/>',
'<uses-feature android:name="android.hardware.camera"/>',
'<uses-permission android:name="android.permission.WRITE_SETTINGS"/>',
],
},
/* ios打包配置 */
ios: {},
/* SDK配置 */
sdkConfigs: {},
/* 图标配置 */
icons: {
android: {},
ios: {},
},
},
}, },
/* 模块配置 */ /* 快应用特有相关 */
modules: {}, quickapp: {},
/* 应用发布信息 */ /* 小程序特有相关 */
distribute: { "mp-weixin": {
/* android打包配置 */ appid: VITE_WX_APPID,
android: { setting: {
minSdkVersion: 30, urlCheck: false,
targetSdkVersion: 30, },
abiFilters: ['armeabi-v7a', 'arm64-v8a'], usingComponents: true,
permissions: [ // __usePrivacyCheck__: true,
'<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>',
'<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>',
'<uses-permission android:name="android.permission.VIBRATE"/>',
'<uses-permission android:name="android.permission.READ_LOGS"/>',
'<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>',
'<uses-feature android:name="android.hardware.camera.autofocus"/>',
'<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>',
'<uses-permission android:name="android.permission.CAMERA"/>',
'<uses-permission android:name="android.permission.GET_ACCOUNTS"/>',
'<uses-permission android:name="android.permission.READ_PHONE_STATE"/>',
'<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>',
'<uses-permission android:name="android.permission.WAKE_LOCK"/>',
'<uses-permission android:name="android.permission.FLASHLIGHT"/>',
'<uses-feature android:name="android.hardware.camera"/>',
'<uses-permission android:name="android.permission.WRITE_SETTINGS"/>',
],
},
/* ios打包配置 */
ios: {},
/* SDK配置 */
sdkConfigs: {},
/* 图标配置 */
icons: {
android: {},
ios: {},
},
}, },
}, "mp-alipay": {
/* 快应用特有相关 */ usingComponents: true,
quickapp: {},
/* 小程序特有相关 */
'mp-weixin': {
appid: VITE_WX_APPID,
setting: {
urlCheck: false,
}, },
usingComponents: true, "mp-baidu": {
// __usePrivacyCheck__: true, usingComponents: true,
}, },
'mp-alipay': { "mp-toutiao": {
usingComponents: true, usingComponents: true,
}, },
'mp-baidu': { uniStatistics: {
usingComponents: true, enable: false,
}, },
'mp-toutiao': { vueVersion: "3",
usingComponents: true, });
},
uniStatistics: {
enable: false,
},
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", "name": "unibest",
"type": "commonjs",
"version": "1.5.0", "version": "1.5.0",
"description": "unibest - 最好的 uniapp 开发模板", "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": { "author": {
"name": "feige996", "name": "feige996",
"zhName": "菲鸽", "zhName": "菲鸽",
...@@ -10,17 +15,8 @@ ...@@ -10,17 +15,8 @@
"github": "https://github.com/feige996", "github": "https://github.com/feige996",
"gitee": "https://gitee.com/feige996" "gitee": "https://gitee.com/feige996"
}, },
"license": "MIT", "type": "commonjs",
"repository": "https://github.com/feige996/unibest",
"repository-gitee": "https://gitee.com/feige996/unibest", "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": { "scripts": {
"dev:app": "uni -p app", "dev:app": "uni -p app",
"dev:app-android": "uni -p app-android", "dev:app-android": "uni -p app-android",
...@@ -66,20 +62,6 @@ ...@@ -66,20 +62,6 @@
"prepare": "node ./shell/postinstall.js & git init && husky install ", "prepare": "node ./shell/postinstall.js & git init && husky install ",
"type-check": "vue-tsc --noEmit" "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": { "dependencies": {
"@climblee/uv-ui": "^1.1.20", "@climblee/uv-ui": "^1.1.20",
"@dcloudio/uni-app": "3.0.0-4000820240401001", "@dcloudio/uni-app": "3.0.0-4000820240401001",
...@@ -109,8 +91,6 @@ ...@@ -109,8 +91,6 @@
"z-paging": "^2.7.8" "z-paging": "^2.7.8"
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^18.4.3",
"@commitlint/config-conventional": "^18.4.3",
"@dcloudio/types": "^3.4.8", "@dcloudio/types": "^3.4.8",
"@dcloudio/uni-automator": "3.0.0-4000820240401001", "@dcloudio/uni-automator": "3.0.0-4000820240401001",
"@dcloudio/uni-cli-shared": "3.0.0-4000820240401001", "@dcloudio/uni-cli-shared": "3.0.0-4000820240401001",
...@@ -120,8 +100,6 @@ ...@@ -120,8 +100,6 @@
"@ttou/uv-typings": "^1.10.2", "@ttou/uv-typings": "^1.10.2",
"@types/node": "^20.11.5", "@types/node": "^20.11.5",
"@types/wechat-miniprogram": "^3.4.7", "@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/uni-ui-types": "^0.5.11",
"@uni-helper/vite-plugin-uni-components": "^0.0.8", "@uni-helper/vite-plugin-uni-components": "^0.0.8",
"@uni-helper/vite-plugin-uni-layouts": "^0.1.7", "@uni-helper/vite-plugin-uni-layouts": "^0.1.7",
...@@ -132,16 +110,7 @@ ...@@ -132,16 +110,7 @@
"@vue/runtime-core": "^3.3.13", "@vue/runtime-core": "^3.3.13",
"@vue/tsconfig": "^0.1.3", "@vue/tsconfig": "^0.1.3",
"autoprefixer": "^10.4.16", "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-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": "^8.4.32",
"postcss-html": "^1.5.0", "postcss-html": "^1.5.0",
"postcss-scss": "^4.0.9", "postcss-scss": "^4.0.9",
...@@ -155,7 +124,6 @@ ...@@ -155,7 +124,6 @@
"stylelint-config-standard-scss": "^12.0.0", "stylelint-config-standard-scss": "^12.0.0",
"stylelint-prettier": "^5.0.0", "stylelint-prettier": "^5.0.0",
"terser": "^5.26.0", "terser": "^5.26.0",
"typescript": "^4.9.4",
"unocss": "^0.58.9", "unocss": "^0.58.9",
"unocss-applet": "^0.7.8", "unocss-applet": "^0.7.8",
"unplugin-auto-import": "^0.17.2", "unplugin-auto-import": "^0.17.2",
...@@ -167,5 +135,14 @@ ...@@ -167,5 +135,14 @@
"vite-plugin-vue-setup-extend": "^0.4.0", "vite-plugin-vue-setup-extend": "^0.4.0",
"vite-svg-loader": "^5.1.0", "vite-svg-loader": "^5.1.0",
"vue-tsc": "^1.8.25" "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({ export default defineUniPages({
globalStyle: { globalStyle: {
navigationStyle: 'default', navigationStyle: "default",
navigationBarTitleText: 'unibest', navigationBarTitleText: "unibest",
navigationBarBackgroundColor: '#f8f8f8', navigationBarBackgroundColor: "#f8f8f8",
navigationBarTextStyle: 'black', navigationBarTextStyle: "black",
backgroundColor: '#FFFFFF', backgroundColor: "#FFFFFF",
h5: { h5: {
// navigationStyle: 'custom', // navigationStyle: 'custom',
},
}, },
}, easycom: {
easycom: { autoscan: true,
autoscan: true, custom: {
custom: { "^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue",
'^uni-(.*)': '@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue', "^uv-(.*)": "@climblee/uv-ui/components/uv-$1/uv-$1.vue",
'^uv-(.*)': '@climblee/uv-ui/components/uv-$1/uv-$1.vue', "^wd-(.*)": "wot-design-uni/components/wd-$1/wd-$1.vue",
'^wd-(.*)': 'wot-design-uni/components/wd-$1/wd-$1.vue', "^(?!z-paging-refresh|z-paging-load-more)z-paging(.*)":
'^(?!z-paging-refresh|z-paging-load-more)z-paging(.*)': "z-paging/components/z-paging$1/z-paging$1.vue",
'z-paging/components/z-paging$1/z-paging$1.vue', },
}, },
}, tabBar: {
tabBar: { color: "#999999",
color: '#999999', selectedColor: "#018d71",
selectedColor: '#018d71', backgroundColor: "#F8F8F8",
backgroundColor: '#F8F8F8', borderStyle: "black",
borderStyle: 'black', height: "50px",
height: '50px', fontSize: "10px",
fontSize: '10px', iconWidth: "24px",
iconWidth: '24px', spacing: "3px",
spacing: '3px', list: [
list: [ {
{ iconPath: "static/tabbar/home.png",
iconPath: 'static/tabbar/home.png', selectedIconPath: "static/tabbar/homeHL.png",
selectedIconPath: 'static/tabbar/homeHL.png', pagePath: "pages/index/index",
pagePath: 'pages/index/index', text: "首页",
text: '首页', },
}, {
{ iconPath: "static/tabbar/example.png",
iconPath: 'static/tabbar/example.png', selectedIconPath: "static/tabbar/exampleHL.png",
selectedIconPath: 'static/tabbar/exampleHL.png', pagePath: "pages/demo/index",
pagePath: 'pages/demo/index', text: "示例",
text: '示例', },
}, ],
], },
}, });
})
...@@ -7,15 +7,15 @@ ...@@ -7,15 +7,15 @@
*/ */
// eslint-disable-next-line @typescript-eslint/no-var-requires // 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)) { if (fs.existsSync(filePath)) {
// console.log(`${filePath}存在`) // console.log(`${filePath}存在`)
} else { } else {
// console.log(`${filePath}不存在,需要创建`) // console.log(`${filePath}不存在,需要创建`)
fs.writeFile(filePath, '{}\n', {}, () => { fs.writeFile(filePath, "{}\n", {}, () => {
// console.log(`${filePath}已经成功创建,并写入{}`) // console.log(`${filePath}已经成功创建,并写入{}`)
}) });
} }
/// <reference types='@dcloudio/types' /> // / <reference types='@dcloudio/types' />
import 'vue' import "vue";
declare module '@vue/runtime-core' { declare module "@vue/runtime-core" {
type Hooks = App.AppInstance & Page.PageInstance type Hooks = App.AppInstance & Page.PageInstance
interface ComponentCustomOptions extends Hooks {}
} }
<script setup lang="ts"> <script setup lang="ts">
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app' import { onHide, onLaunch, onShow } from "@dcloudio/uni-app";
onLaunch(() => { onLaunch(() => {
console.log('App Launch') console.log("App Launch");
}) });
onShow(() => { onShow(() => {
console.log('App Show') console.log("App Show");
}) });
onHide(() => { onHide(() => {
console.log('App Hide') console.log("App Hide");
}) });
</script> </script>
<style lang="scss"> <style lang="scss">
......
<!-- 本文件会自动导入 --> <!-- 本文件会自动导入 -->
<template> <template>
<view> <view>
<view>components 里面的 AppTest.vue 组件</view> <view>components 里面的 AppTest.vue 组件</view>
<slot /> <slot />
</view> </view>
</template> </template>
<template> <template>
<svg aria-hidden="true"> <svg aria-hidden="true">
<use :href="symbolId" :fill="color" /> <use :fill="color" :href="symbolId" />
</svg> </svg>
</template> </template>
<script lang="ts" setup name="SvgIcon"> <script lang="ts" setup name="SvgIcon">
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
prefix?: string
name: string
color?: string color?: string
name: string
prefix?: string
}>(), }>(),
{ {
prefix: 'icon', prefix: "icon",
name: '', name: "",
color: '#333', color: "#333",
}, },
) );
const symbolId = computed(() => `#${props.prefix}-${props.name}`) const symbolId = computed(() => `#${props.prefix}-${props.name}`);
</script> </script>
<template> <template>
<view> <view>
<view>components 里面的 app-test-dir/AppTest.vue 组件</view> <view>components 里面的 app-test-dir/AppTest.vue 组件</view>
<slot /> <slot />
</view> </view>
</template> </template>
<template> <template>
<view class="fly-content"> <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"
很多内容,这里是第{{ n }}行 :key="n"
class="h-10 leading-10 text-center"
title="3">
很多内容,这里是第{{ n }}行
</view>
</view> </view>
</view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
withDefaults(defineProps<{ line?: number }>(), { line: 10 }) withDefaults(defineProps<{ line?: number }>(), { line: 10 });
</script> </script>
<template> <template>
<view class="text-green-500">header</view> <view class="text-green-500">
header
</view>
</template> </template>
<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-mask" />
<view class="fly-login-content px-4"> <view class="fly-login-content px-4">
<view class="font-bold h-16 leading-16">获取您的昵称、头像</view> <view class="font-bold h-16 leading-16">
<view 获取您的昵称、头像
class="rounded-full bg-light-600 w-6 h-6 text-center absolute top-4 right-4" </view>
@click="onClose" <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 class="i-carbon-close text-gray-700" />
</view> </view>
<view <view class="flex items-center h-16 leading-16 border-b-gray-400 border-b-solid border-[1rpx]">
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"
<text class="mr-4 flex-shrink-0">头像</text> open-type="chooseAvatar"
<button @chooseavatar="onChooseAvatar">
class="bg-transparent flex items-center after:b-none w-full h-12 leading-12" <image class="w-8 h-8 rounded-full" :src="avatarUrl"></image>
open-type="chooseAvatar" <text class="ml-auto i-carbon-chevron-right"></text>
@chooseavatar="onChooseAvatar" </button>
> </view>
<image class="w-8 h-8 rounded-full" :src="avatarUrl"></image>
<text class="ml-auto i-carbon-chevron-right"></text>
</button>
</view>
<view <view class="flex items-center h-16 leading-16 border-b-gray-400 border-b-solid border-1 mt-4">
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 placeholder="请输入昵称"
<text class="mr-4 flex-shrink-0">昵称</text> type="nickname"
<input type="nickname" placeholder="请输入昵称" @change="onChange" @blur="onChange" /> @blur="onChange"
</view> @change="onChange" />
</view>
<button <button class="text-center leading-12 w-40 my-4"
size="default" size="default"
type="default" style="color: #fff; background-color: #1aad19; border-color: #1aad19"
style="color: #fff; background-color: #1aad19; border-color: #1aad19" type="default"
class="text-center leading-12 w-40 my-4" @click="onSubmit">
@click="onSubmit" 确定
> </button>
确定 </view>
</button>
</view> </view>
</view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { useUserStore } from '@/store' import { useUserStore } from "@/store";
import defaultAvatarUrl from './defaultAvatar.png'
const emit = defineEmits(['update:modelValue']) import defaultAvatarUrl from "./defaultAvatar.png";
defineProps<{ modelValue: boolean }>()
const userStore = useUserStore() defineProps<{ modelValue: boolean }>();
const emit = defineEmits([ "update:modelValue" ]);
const userStore = useUserStore();
const avatarUrl = ref(defaultAvatarUrl) const avatarUrl = ref(defaultAvatarUrl);
const nickname = ref('') const nickname = ref("");
const onClose = () => { const onClose = () => {
emit('update:modelValue', false) emit("update:modelValue", false);
} };
const onChooseAvatar = (e) => { const onChooseAvatar = (e) => {
const { avatarUrl: url } = e.detail const { avatarUrl: url } = e.detail;
avatarUrl.value = url avatarUrl.value = url;
// 这里就要上传,加快速度,提升体验(用户多次选择头像就多次上传吧,总有取舍) // 这里就要上传,加快速度,提升体验(用户多次选择头像就多次上传吧,总有取舍)
console.log(url) console.log(url);
} };
const onChange = (e) => { const onChange = (e) => {
const { value } = e.detail const { value } = e.detail;
nickname.value = value nickname.value = value;
console.log(value) console.log(value);
} };
const onSubmit = () => { const onSubmit = () => {
// 1、上传刚刚的图片,并返回网络地址 // 1、上传刚刚的图片,并返回网络地址
// 2、把用户信息存起来 // 2、把用户信息存起来
if (avatarUrl.value === defaultAvatarUrl) { if (avatarUrl.value === defaultAvatarUrl) {
uni.showToast({ uni.showToast({
title: '请选择头像', title: "请选择头像",
icon: 'none', icon: "none",
}) });
return return;
} }
if (!nickname.value) { if (!nickname.value) {
uni.showToast({ uni.showToast({
title: '请填写昵称', title: "请填写昵称",
icon: 'none', icon: "none",
}) });
return return;
} }
emit('update:modelValue', false) emit("update:modelValue", false);
console.log('保存用户信息') console.log("保存用户信息");
userStore.setUserInfo({ nickname: nickname.value, avatar: avatarUrl.value }) userStore.setUserInfo({ nickname: nickname.value, avatar: avatarUrl.value });
} };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
......
<template> <template>
<!-- 自定义导航栏: 默认透明不可见, scroll-view 滚动到 50 时展示 --> <!-- 自定义导航栏: 默认透明不可见, scroll-view 滚动到 50 时展示 -->
<view class="fly-navbar" :style="{ paddingTop: safeAreaInsets?.top + 'px' }"> <view class="fly-navbar" :style="{ paddingTop: `${safeAreaInsets?.top }px` }">
<!-- 1/3,多于1个页面,用返回图标 --> <!-- 1/3,多于1个页面,用返回图标 -->
<navigator v-if="pages.length > 1" open-type="navigateBack" class="left-icon"> <navigator v-if="pages.length > 1"
<view class="bg-gray-500/80 rounded-full w-8 h-8 flex items-center justify-center"> class="left-icon"
<button class="i-carbon-chevron-left text-white w-7 h-7"></button> open-type="navigateBack">
</view> <view class="bg-gray-500/80 rounded-full w-8 h-8 flex items-center justify-center">
</navigator> <button class="i-carbon-chevron-left text-white w-7 h-7"></button>
<!-- 2/3,只有1个页面,如果不是tabbar,需要首页图标 --> </view>
<!-- 这种情况一般出现在用户直接打开分享出去的详情页面,或者使用redirectTo等API --> </navigator>
<navigator <!-- 2/3,只有1个页面,如果不是tabbar,需要首页图标 -->
v-else-if="!isTabbar" <!-- 这种情况一般出现在用户直接打开分享出去的详情页面,或者使用redirectTo等API -->
open-type="switchTab" <navigator v-else-if="!isTabbar"
url="/pages/index/index" class="left-icon"
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"> <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> <button class="i-carbon-home text-white w-6 h-6"></button>
</view> </view>
</navigator> </navigator>
<!-- 3/3,如果当前页就是tabbar页,不用去首页,也就是什么图标都不需要 --> <!-- 3/3,如果当前页就是tabbar页,不用去首页,也就是什么图标都不需要 -->
<view class="title">{{ title || '' }}</view> <view class="title">
</view> {{ title || '' }}
</view>
</view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { getIsTabbar } from '@/utils/index' import { getIsTabbar } from "@/utils/index";
defineProps<{ title?: string }>() defineProps<{ title?: string }>();
// 获取页面栈 // 获取页面栈
const pages = getCurrentPages() const pages = getCurrentPages();
const isTabbar = getIsTabbar() const isTabbar = getIsTabbar();
console.log({ isTabbar, pagesLen: pages.length }) console.log({ isTabbar, pagesLen: pages.length });
// 获取屏幕边界到安全区域距离 // 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync() const { safeAreaInsets } = uni.getSystemInfoSync();
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
......
This diff could not be displayed because it is too large.
<template> <template>
<view class="chartsview"> <view class="chartsview">
<view class="charts-error"></view> <view class="charts-error"></view>
<view class="charts-font">{{ errorMessage == null ? '请点击重试' : errorMessage }}</view> <view class="charts-font">
</view> {{ errorMessage === null ? '请点击重试' : errorMessage }}
</view>
</view>
</template> </template>
<script> <script>
export default { export default {
name: 'qiun-error', name: "QiunError",
props: { props: {
errorMessage: { errorMessage: {
type: String, type: String,
default: null, default: null,
},
}, },
}, data() {
data() { return {};
return {} },
}, };
}
</script> </script>
<style> <style>
......
<template> <template>
<view class="container loading1"> <view class="container loading1">
<view class="shape shape1"></view> <view class="shape shape1"></view>
<view class="shape shape2"></view> <view class="shape shape2"></view>
<view class="shape shape3"></view> <view class="shape shape3"></view>
<view class="shape shape4"></view> <view class="shape shape4"></view>
</view> </view>
</template> </template>
<script> <script>
export default { export default {
name: 'loading1', name: "Loading1",
data() { data() {
return {} return {};
}, },
} };
</script> </script>
<style scoped="true"> <style scoped="true">
......
<template> <template>
<view class="container loading2"> <view class="container loading2">
<view class="shape shape1"></view> <view class="shape shape1"></view>
<view class="shape shape2"></view> <view class="shape shape2"></view>
<view class="shape shape3"></view> <view class="shape shape3"></view>
<view class="shape shape4"></view> <view class="shape shape4"></view>
</view> </view>
</template> </template>
<script> <script>
export default { export default {
name: 'loading2', name: "Loading2",
data() { data() {
return {} return {};
}, },
} };
</script> </script>
<style scoped="true"> <style scoped="true">
...@@ -25,18 +25,13 @@ export default { ...@@ -25,18 +25,13 @@ export default {
.container.loading2 { .container.loading2 {
transform: rotate(10deg); transform: rotate(10deg);
transform: rotate(10deg); animation: rotation 1s infinite;
} }
.container.loading2 .shape { .container.loading2 .shape {
border-radius: 5px; border-radius: 5px;
} }
.container.loading2 {
animation: rotation 1s infinite;
animation: rotation 1s infinite;
}
.container .shape { .container .shape {
position: absolute; position: absolute;
width: 10px; width: 10px;
...@@ -67,117 +62,97 @@ export default { ...@@ -67,117 +62,97 @@ export default {
.loading2 .shape1 { .loading2 .shape1 {
animation: animation2shape1 0.5s ease 0s infinite alternate; animation: animation2shape1 0.5s ease 0s infinite alternate;
animation: animation2shape1 0.5s ease 0s infinite alternate;
} }
@keyframes animation2shape1 { @keyframes animation2shape1 {
from { from {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
to { to {
transform: translate(20px, 20px); transform: translate(20px, 20px);
transform: translate(20px, 20px);
} }
} }
@keyframes animation2shape1 { @keyframes animation2shape1 {
from { from {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
to { to {
transform: translate(20px, 20px); transform: translate(20px, 20px);
transform: translate(20px, 20px);
} }
} }
.loading2 .shape2 { .loading2 .shape2 {
animation: animation2shape2 0.5s ease 0s infinite alternate; animation: animation2shape2 0.5s ease 0s infinite alternate;
animation: animation2shape2 0.5s ease 0s infinite alternate;
} }
@keyframes animation2shape2 { @keyframes animation2shape2 {
from { from {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
to { to {
transform: translate(-20px, 20px); transform: translate(-20px, 20px);
transform: translate(-20px, 20px);
} }
} }
@keyframes animation2shape2 { @keyframes animation2shape2 {
from { from {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
to { to {
transform: translate(-20px, 20px); transform: translate(-20px, 20px);
transform: translate(-20px, 20px);
} }
} }
.loading2 .shape3 { .loading2 .shape3 {
animation: animation2shape3 0.5s ease 0s infinite alternate; animation: animation2shape3 0.5s ease 0s infinite alternate;
animation: animation2shape3 0.5s ease 0s infinite alternate;
} }
@keyframes animation2shape3 { @keyframes animation2shape3 {
from { from {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
to { to {
transform: translate(20px, -20px); transform: translate(20px, -20px);
transform: translate(20px, -20px);
} }
} }
@keyframes animation2shape3 { @keyframes animation2shape3 {
from { from {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
to { to {
transform: translate(20px, -20px); transform: translate(20px, -20px);
transform: translate(20px, -20px);
} }
} }
.loading2 .shape4 { .loading2 .shape4 {
animation: animation2shape4 0.5s ease 0s infinite alternate; animation: animation2shape4 0.5s ease 0s infinite alternate;
animation: animation2shape4 0.5s ease 0s infinite alternate;
} }
@keyframes animation2shape4 { @keyframes animation2shape4 {
from { from {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
to { to {
transform: translate(-20px, -20px); transform: translate(-20px, -20px);
transform: translate(-20px, -20px);
} }
} }
@keyframes animation2shape4 { @keyframes animation2shape4 {
from { from {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
to { to {
transform: translate(-20px, -20px); transform: translate(-20px, -20px);
transform: translate(-20px, -20px);
} }
} }
</style> </style>
<template> <template>
<view class="container loading3"> <view class="container loading3">
<view class="shape shape1"></view> <view class="shape shape1"></view>
<view class="shape shape2"></view> <view class="shape shape2"></view>
<view class="shape shape3"></view> <view class="shape shape3"></view>
<view class="shape shape4"></view> <view class="shape shape4"></view>
</view> </view>
</template> </template>
<script> <script>
export default { export default {
name: 'loading3', name: "Loading3",
data() { data() {
return {} return {};
}, },
} };
</script> </script>
<style scoped="true"> <style scoped="true">
...@@ -25,7 +25,6 @@ export default { ...@@ -25,7 +25,6 @@ export default {
.container.loading3 { .container.loading3 {
animation: rotation 1s infinite; animation: rotation 1s infinite;
animation: rotation 1s infinite;
} }
.container.loading3 .shape1 { .container.loading3 .shape1 {
...@@ -74,117 +73,97 @@ export default { ...@@ -74,117 +73,97 @@ export default {
.loading3 .shape1 { .loading3 .shape1 {
animation: animation3shape1 0.5s ease 0s infinite alternate; animation: animation3shape1 0.5s ease 0s infinite alternate;
animation: animation3shape1 0.5s ease 0s infinite alternate;
} }
@keyframes animation3shape1 { @keyframes animation3shape1 {
from { from {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
to { to {
transform: translate(5px, 5px); transform: translate(5px, 5px);
transform: translate(5px, 5px);
} }
} }
@keyframes animation3shape1 { @keyframes animation3shape1 {
from { from {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
to { to {
transform: translate(5px, 5px); transform: translate(5px, 5px);
transform: translate(5px, 5px);
} }
} }
.loading3 .shape2 { .loading3 .shape2 {
animation: animation3shape2 0.5s ease 0s infinite alternate; animation: animation3shape2 0.5s ease 0s infinite alternate;
animation: animation3shape2 0.5s ease 0s infinite alternate;
} }
@keyframes animation3shape2 { @keyframes animation3shape2 {
from { from {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
to { to {
transform: translate(-5px, 5px); transform: translate(-5px, 5px);
transform: translate(-5px, 5px);
} }
} }
@keyframes animation3shape2 { @keyframes animation3shape2 {
from { from {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
to { to {
transform: translate(-5px, 5px); transform: translate(-5px, 5px);
transform: translate(-5px, 5px);
} }
} }
.loading3 .shape3 { .loading3 .shape3 {
animation: animation3shape3 0.5s ease 0s infinite alternate; animation: animation3shape3 0.5s ease 0s infinite alternate;
animation: animation3shape3 0.5s ease 0s infinite alternate;
} }
@keyframes animation3shape3 { @keyframes animation3shape3 {
from { from {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
to { to {
transform: translate(5px, -5px); transform: translate(5px, -5px);
transform: translate(5px, -5px);
} }
} }
@keyframes animation3shape3 { @keyframes animation3shape3 {
from { from {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
to { to {
transform: translate(5px, -5px); transform: translate(5px, -5px);
transform: translate(5px, -5px);
} }
} }
.loading3 .shape4 { .loading3 .shape4 {
animation: animation3shape4 0.5s ease 0s infinite alternate; animation: animation3shape4 0.5s ease 0s infinite alternate;
animation: animation3shape4 0.5s ease 0s infinite alternate;
} }
@keyframes animation3shape4 { @keyframes animation3shape4 {
from { from {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
to { to {
transform: translate(-5px, -5px); transform: translate(-5px, -5px);
transform: translate(-5px, -5px);
} }
} }
@keyframes animation3shape4 { @keyframes animation3shape4 {
from { from {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
to { to {
transform: translate(-5px, -5px); transform: translate(-5px, -5px);
transform: translate(-5px, -5px);
} }
} }
</style> </style>
<template> <template>
<view class="container loading5"> <view class="container loading5">
<view class="shape shape1"></view> <view class="shape shape1"></view>
<view class="shape shape2"></view> <view class="shape shape2"></view>
<view class="shape shape3"></view> <view class="shape shape3"></view>
<view class="shape shape4"></view> <view class="shape shape4"></view>
</view> </view>
</template> </template>
<script> <script>
export default { export default {
name: 'loading5', name: "Loading5",
data() { data() {
return {} return {};
}, },
} };
</script> </script>
<style scoped="true"> <style scoped="true">
...@@ -63,44 +63,36 @@ export default { ...@@ -63,44 +63,36 @@ export default {
@keyframes animation5shape1 { @keyframes animation5shape1 {
0% { 0% {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
25% { 25% {
transform: translate(0, 15px); transform: translate(0, 15px);
transform: translate(0, 15px);
} }
50% { 50% {
transform: translate(15px, 15px); transform: translate(15px, 15px);
transform: translate(15px, 15px);
} }
75% { 75% {
transform: translate(15px, 0); transform: translate(15px, 0);
transform: translate(15px, 0);
} }
} }
@keyframes animation5shape1 { @keyframes animation5shape1 {
0% { 0% {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
25% { 25% {
transform: translate(0, 15px); transform: translate(0, 15px);
transform: translate(0, 15px);
} }
50% { 50% {
transform: translate(15px, 15px); transform: translate(15px, 15px);
transform: translate(15px, 15px);
} }
75% { 75% {
transform: translate(15px, 0); transform: translate(15px, 0);
transform: translate(15px, 0);
} }
} }
...@@ -111,44 +103,36 @@ export default { ...@@ -111,44 +103,36 @@ export default {
@keyframes animation5shape2 { @keyframes animation5shape2 {
0% { 0% {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
25% { 25% {
transform: translate(-15px, 0); transform: translate(-15px, 0);
transform: translate(-15px, 0);
} }
50% { 50% {
transform: translate(-15px, 15px); transform: translate(-15px, 15px);
transform: translate(-15px, 15px);
} }
75% { 75% {
transform: translate(0, 15px); transform: translate(0, 15px);
transform: translate(0, 15px);
} }
} }
@keyframes animation5shape2 { @keyframes animation5shape2 {
0% { 0% {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
25% { 25% {
transform: translate(-15px, 0); transform: translate(-15px, 0);
transform: translate(-15px, 0);
} }
50% { 50% {
transform: translate(-15px, 15px); transform: translate(-15px, 15px);
transform: translate(-15px, 15px);
} }
75% { 75% {
transform: translate(0, 15px); transform: translate(0, 15px);
transform: translate(0, 15px);
} }
} }
...@@ -159,44 +143,36 @@ export default { ...@@ -159,44 +143,36 @@ export default {
@keyframes animation5shape3 { @keyframes animation5shape3 {
0% { 0% {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
25% { 25% {
transform: translate(15px, 0); transform: translate(15px, 0);
transform: translate(15px, 0);
} }
50% { 50% {
transform: translate(15px, -15px); transform: translate(15px, -15px);
transform: translate(15px, -15px);
} }
75% { 75% {
transform: translate(0, -15px); transform: translate(0, -15px);
transform: translate(0, -15px);
} }
} }
@keyframes animation5shape3 { @keyframes animation5shape3 {
0% { 0% {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
25% { 25% {
transform: translate(15px, 0); transform: translate(15px, 0);
transform: translate(15px, 0);
} }
50% { 50% {
transform: translate(15px, -15px); transform: translate(15px, -15px);
transform: translate(15px, -15px);
} }
75% { 75% {
transform: translate(0, -15px); transform: translate(0, -15px);
transform: translate(0, -15px);
} }
} }
...@@ -207,44 +183,36 @@ export default { ...@@ -207,44 +183,36 @@ export default {
@keyframes animation5shape4 { @keyframes animation5shape4 {
0% { 0% {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
25% { 25% {
transform: translate(0, -15px); transform: translate(0, -15px);
transform: translate(0, -15px);
} }
50% { 50% {
transform: translate(-15px, -15px); transform: translate(-15px, -15px);
transform: translate(-15px, -15px);
} }
75% { 75% {
transform: translate(-15px, 0); transform: translate(-15px, 0);
transform: translate(-15px, 0);
} }
} }
@keyframes animation5shape4 { @keyframes animation5shape4 {
0% { 0% {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
25% { 25% {
transform: translate(0, -15px); transform: translate(0, -15px);
transform: translate(0, -15px);
} }
50% { 50% {
transform: translate(-15px, -15px); transform: translate(-15px, -15px);
transform: translate(-15px, -15px);
} }
75% { 75% {
transform: translate(-15px, 0); transform: translate(-15px, 0);
transform: translate(-15px, 0);
} }
} }
</style> </style>
<template> <template>
<view class="container loading6"> <view class="container loading6">
<view class="shape shape1"></view> <view class="shape shape1"></view>
<view class="shape shape2"></view> <view class="shape shape2"></view>
<view class="shape shape3"></view> <view class="shape shape3"></view>
<view class="shape shape4"></view> <view class="shape shape4"></view>
</view> </view>
</template> </template>
<script> <script>
export default { export default {
name: 'loading6', name: "Loading6",
data() { data() {
return {} return {};
}, },
} };
</script> </script>
<style scoped="true"> <style scoped="true">
.container { .container {
...@@ -24,7 +24,6 @@ export default { ...@@ -24,7 +24,6 @@ export default {
.container.loading6 { .container.loading6 {
animation: rotation 1s infinite; animation: rotation 1s infinite;
animation: rotation 1s infinite;
} }
.container.loading6 .shape { .container.loading6 .shape {
...@@ -63,197 +62,161 @@ export default { ...@@ -63,197 +62,161 @@ export default {
.loading6 .shape1 { .loading6 .shape1 {
animation: animation6shape1 2s linear 0s infinite normal; animation: animation6shape1 2s linear 0s infinite normal;
animation: animation6shape1 2s linear 0s infinite normal;
} }
@keyframes animation6shape1 { @keyframes animation6shape1 {
0% { 0% {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
25% { 25% {
transform: translate(0, 18px); transform: translate(0, 18px);
transform: translate(0, 18px);
} }
50% { 50% {
transform: translate(18px, 18px); transform: translate(18px, 18px);
transform: translate(18px, 18px);
} }
75% { 75% {
transform: translate(18px, 0); transform: translate(18px, 0);
transform: translate(18px, 0);
} }
} }
@keyframes animation6shape1 { @keyframes animation6shape1 {
0% { 0% {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
25% { 25% {
transform: translate(0, 18px); transform: translate(0, 18px);
transform: translate(0, 18px);
} }
50% { 50% {
transform: translate(18px, 18px); transform: translate(18px, 18px);
transform: translate(18px, 18px);
} }
75% { 75% {
transform: translate(18px, 0); transform: translate(18px, 0);
transform: translate(18px, 0);
} }
} }
.loading6 .shape2 { .loading6 .shape2 {
animation: animation6shape2 2s linear 0s infinite normal; animation: animation6shape2 2s linear 0s infinite normal;
animation: animation6shape2 2s linear 0s infinite normal;
} }
@keyframes animation6shape2 { @keyframes animation6shape2 {
0% { 0% {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
25% { 25% {
transform: translate(-18px, 0); transform: translate(-18px, 0);
transform: translate(-18px, 0);
} }
50% { 50% {
transform: translate(-18px, 18px); transform: translate(-18px, 18px);
transform: translate(-18px, 18px);
} }
75% { 75% {
transform: translate(0, 18px); transform: translate(0, 18px);
transform: translate(0, 18px);
} }
} }
@keyframes animation6shape2 { @keyframes animation6shape2 {
0% { 0% {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
25% { 25% {
transform: translate(-18px, 0); transform: translate(-18px, 0);
transform: translate(-18px, 0);
} }
50% { 50% {
transform: translate(-18px, 18px); transform: translate(-18px, 18px);
transform: translate(-18px, 18px);
} }
75% { 75% {
transform: translate(0, 18px); transform: translate(0, 18px);
transform: translate(0, 18px);
} }
} }
.loading6 .shape3 { .loading6 .shape3 {
animation: animation6shape3 2s linear 0s infinite normal; animation: animation6shape3 2s linear 0s infinite normal;
animation: animation6shape3 2s linear 0s infinite normal;
} }
@keyframes animation6shape3 { @keyframes animation6shape3 {
0% { 0% {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
25% { 25% {
transform: translate(18px, 0); transform: translate(18px, 0);
transform: translate(18px, 0);
} }
50% { 50% {
transform: translate(18px, -18px); transform: translate(18px, -18px);
transform: translate(18px, -18px);
} }
75% { 75% {
transform: translate(0, -18px); transform: translate(0, -18px);
transform: translate(0, -18px);
} }
} }
@keyframes animation6shape3 { @keyframes animation6shape3 {
0% { 0% {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
25% { 25% {
transform: translate(18px, 0); transform: translate(18px, 0);
transform: translate(18px, 0);
} }
50% { 50% {
transform: translate(18px, -18px); transform: translate(18px, -18px);
transform: translate(18px, -18px);
} }
75% { 75% {
transform: translate(0, -18px); transform: translate(0, -18px);
transform: translate(0, -18px);
} }
} }
.loading6 .shape4 { .loading6 .shape4 {
animation: animation6shape4 2s linear 0s infinite normal; animation: animation6shape4 2s linear 0s infinite normal;
animation: animation6shape4 2s linear 0s infinite normal;
} }
@keyframes animation6shape4 { @keyframes animation6shape4 {
0% { 0% {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
25% { 25% {
transform: translate(0, -18px); transform: translate(0, -18px);
transform: translate(0, -18px);
} }
50% { 50% {
transform: translate(-18px, -18px); transform: translate(-18px, -18px);
transform: translate(-18px, -18px);
} }
75% { 75% {
transform: translate(-18px, 0); transform: translate(-18px, 0);
transform: translate(-18px, 0);
} }
} }
@keyframes animation6shape4 { @keyframes animation6shape4 {
0% { 0% {
transform: translate(0, 0); transform: translate(0, 0);
transform: translate(0, 0);
} }
25% { 25% {
transform: translate(0, -18px); transform: translate(0, -18px);
transform: translate(0, -18px);
} }
50% { 50% {
transform: translate(-18px, -18px); transform: translate(-18px, -18px);
transform: translate(-18px, -18px);
} }
75% { 75% {
transform: translate(-18px, 0); transform: translate(-18px, 0);
transform: translate(-18px, 0);
} }
} }
</style> </style>
<template> <template>
<view> <view>
<Loading1 v-if="loadingType == 1" /> <Loading1 v-if="loadingType === 1" />
<Loading2 v-if="loadingType == 2" /> <Loading2 v-if="loadingType === 2" />
<Loading3 v-if="loadingType == 3" /> <Loading3 v-if="loadingType === 3" />
<Loading4 v-if="loadingType == 4" /> <Loading4 v-if="loadingType === 4" />
<Loading5 v-if="loadingType == 5" /> <Loading5 v-if="loadingType === 5" />
</view> </view>
</template> </template>
<script> <script>
import Loading1 from './loading1.vue' import Loading1 from "./loading1.vue";
import Loading2 from './loading2.vue' import Loading2 from "./loading2.vue";
import Loading3 from './loading3.vue' import Loading3 from "./loading3.vue";
import Loading4 from './loading4.vue' import Loading4 from "./loading4.vue";
import Loading5 from './loading5.vue' import Loading5 from "./loading5.vue";
export default { export default {
components: { Loading1, Loading2, Loading3, Loading4, Loading5 }, name: "QiunLoading",
name: 'qiun-loading', components: { Loading1, Loading2, Loading3, Loading4, Loading5 },
props: { props: {
loadingType: { loadingType: {
type: Number, type: Number,
default: 2, default: 2,
},
}, },
}, data() {
data() { return {};
return {} },
}, };
}
</script> </script>
<style></style> <style></style>
<template> <template>
<view class="qiun-title-bar"> <view class="qiun-title-bar">
<view class="qiun-title-dot"></view> <view class="qiun-title-dot"></view>
<view class="qiun-title-text">{{ title }}</view> <view class="qiun-title-text">
</view> {{ title }}
</view>
</view>
</template> </template>
<script> <script>
export default { export default {
name: 'title-bar', name: "TitleBar",
props: { props: {
title: { title: {
type: String, type: String,
default: '', default: "",
},
}, },
}, mounted() {},
mounted() {}, methods: {},
methods: {}, };
}
</script> </script>
<style> <style>
......
/// <reference types="vite/client" /> // / <reference types="vite/client" />
/// <reference types="vite-svg-loader" /> // / <reference types="vite-svg-loader" />
/* eslint-disable */
declare module '*.vue' { declare module "*.vue" {
import { DefineComponent } from 'vue' import { DefineComponent } from "vue";
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
const component: DefineComponent<{}, {}, any> const component: DefineComponent<{}, {}, any>;
export default component export default component;
} }
interface ImportMetaEnv { interface ImportMetaEnv {
......
/* eslint-disable import/first */
// 小程序中引入 echarts /* eslint-disable */
// #ifndef APP-PLUS || H5 import { ref } from "vue";
// eslint-disable-next-line @typescript-eslint/no-var-requires
const echarts = require('../uni_modules/lime-echart/static/echarts.min')
// #endif // #endif
// APP 与 H5 引入 echarts // APP 与 H5 引入 echarts
// #ifdef APP-PLUS || H5 // #ifdef APP-PLUS || H5
import * as echartsAppOrH5 from 'echarts' import * as echartsAppOrH5 from "echarts";
// #endif // #endif
import { ref } from 'vue' // 小程序中引入 echarts
// #ifndef APP-PLUS || H5
const echarts = require("../uni_modules/lime-echart/static/echarts.min");
// echarts 图表 Hooks // echarts 图表 Hooks
export const useEcharts = (options): any => { export const useEcharts = (options): any => {
// echarts 图实例 // echarts 图实例
const chartRef = ref(null) const chartRef = ref(null);
// echarts 图绘制函数 // echarts 图绘制函数
const draw = () => { const draw = () => {
setTimeout(async () => { setTimeout(async () => {
if (!chartRef.value) return if (!chartRef.value) return;
// #ifndef APP-PLUS || H5 // #ifndef APP-PLUS || H5
const chart = await chartRef.value.init(echarts) const chart = await chartRef.value.init(echarts);
chart.setOption(options.value) chart.setOption(options.value);
// #endif // #endif
// #ifdef APP-PLUS || H5 // #ifdef APP-PLUS || H5
const chartAPP = await chartRef.value.init(echartsAppOrH5) const chartAPP = await chartRef.value.init(echartsAppOrH5);
chartAPP.setOption(options.value) chartAPP.setOption(options.value);
// #endif // #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 pages = getCurrentPages();
const isTabbar = getIsTabbar() const isTabbar = getIsTabbar();
// 页面滚动到底部时的操作,通常用于加载更多数据 // 页面滚动到底部时的操作,通常用于加载更多数据
const onScrollToLower = () => {} const onScrollToLower = () => {};
// 获取屏幕边界到安全区域距离 // 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync() const { safeAreaInsets } = uni.getSystemInfoSync();
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
// 基于小程序的 Page 类型扩展 uni-app 的 Page // 基于小程序的 Page 类型扩展 uni-app 的 Page
type PageInstance = Page.PageInstance & WechatMiniprogram.Page.InstanceMethods<any> type PageInstance = Page.PageInstance & WechatMiniprogram.Page.InstanceMethods<any>
// 获取当前页面实例,数组最后一项 // 获取当前页面实例,数组最后一项
const pageInstance = getLastItem(getCurrentPages()) as PageInstance const pageInstance = getLastItem(getCurrentPages()) as PageInstance;
// 页面渲染完毕,绑定动画效果 // 页面渲染完毕,绑定动画效果
onReady(() => { onReady(() => {
// 动画效果,导航栏背景色 // 动画效果,导航栏背景色
pageInstance.animate( pageInstance.animate(
'.fly-navbar', ".fly-navbar",
[{ backgroundColor: 'transparent' }, { backgroundColor: '#f8f8f8' }], [ { backgroundColor: "transparent" }, { backgroundColor: "#f8f8f8" } ],
1000, 1000,
{ {
scrollSource: '#scroller', scrollSource: "#scroller",
timeRange: 1000, timeRange: 1000,
startScrollOffset: 0, startScrollOffset: 0,
endScrollOffset: 50, endScrollOffset: 50,
}, },
) );
// 动画效果,导航栏标题 // 动画效果,导航栏标题
pageInstance.animate( pageInstance.animate(
'.fly-navbar .title', ".fly-navbar .title",
[{ color: 'transparent' }, { color: '#000' }], [ { color: "transparent" }, { color: "#000" } ],
1000, 1000,
{ {
scrollSource: '#scroller', scrollSource: "#scroller",
timeRange: 1000, timeRange: 1000,
startScrollOffset: 0, startScrollOffset: 0,
endScrollOffset: 50, endScrollOffset: 50,
}, },
) );
// 动画效果,导航栏返回按钮 // 动画效果,导航栏返回按钮
pageInstance.animate('.fly-navbar .left-icon', [{ color: '#fff' }, { color: '#000' }], 1000, { pageInstance.animate(".fly-navbar .left-icon", [ { color: "#fff" }, { color: "#000" } ], 1000, {
scrollSource: '#scroller', scrollSource: "#scroller",
timeRange: 1000, timeRange: 1000,
startScrollOffset: 0, startScrollOffset: 0,
endScrollOffset: 50, endScrollOffset: 50,
}) });
}) });
// #endif // #endif
return { return {
pages, pages,
isTabbar, isTabbar,
onScrollToLower, onScrollToLower,
safeAreaInsets, safeAreaInsets,
} };
} };
export default useNavbarWeixin;
import { UnwrapRef } from 'vue'
type IUseRequestOptions<T> = { type IUseRequestOptions<T> = {
/** 是否立即执行,如果是则在onLoad执行 */ /** 是否立即执行,如果是则在onLoad执行 */
...@@ -16,29 +15,30 @@ type IUseRequestOptions<T> = { ...@@ -16,29 +15,30 @@ type IUseRequestOptions<T> = {
* @returns 返回一个对象{loading, error, data, run},包含请求的加载状态、错误信息、响应数据和手动触发请求的函数。 * @returns 返回一个对象{loading, error, data, run},包含请求的加载状态、错误信息、响应数据和手动触发请求的函数。
*/ */
export default function useRequest<T>( export default function useRequest<T>(
func: () => Promise<IResData<T>>, func: () => Promise<IResData<T>>,
options: IUseRequestOptions<T> = { immediate: true }, options: IUseRequestOptions<T>,
) { ) {
const loading = ref(false) options = options ?? { immediate: true };
const error = ref(false) const loading = ref(false);
const data = ref<T>(options.initialData) const error = ref(false);
const run = async () => { const data = ref<T>(options.initialData);
loading.value = true const run = async () => {
func() loading.value = true;
.then((res) => { func()
data.value = res.data as UnwrapRef<T> .then((res) => {
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 .finally(() => {
}) loading.value = false;
} });
};
onLoad(() => { onLoad(() => {
options.immediate && run() options.immediate && run();
}) });
return { loading, error, data, run } return { loading, error, data, run };
} }
// TODO: 别忘加更改环境变量的 VITE_UPLOAD_BASEURL 地址。 // 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 是一个定制化的请求钩子,用于处理上传图片。 * useUpload 是一个定制化的请求钩子,用于处理上传图片。
...@@ -7,61 +7,61 @@ const VITE_UPLOAD_BASEURL = import.meta.env.VITE_UPLOAD_BASEURL ...@@ -7,61 +7,61 @@ const VITE_UPLOAD_BASEURL = import.meta.env.VITE_UPLOAD_BASEURL
* @returns 返回一个对象{loading, error, data, run},包含请求的加载状态、错误信息、响应数据和手动触发请求的函数。 * @returns 返回一个对象{loading, error, data, run},包含请求的加载状态、错误信息、响应数据和手动触发请求的函数。
*/ */
export default function useUpload<T = string>(formData: Record<string, any> = {}) { export default function useUpload<T = string>(formData: Record<string, any> = {}) {
const loading = ref(false) const loading = ref(false);
const error = ref(false) const error = ref(false);
const data = ref<T>() const data = ref<T>();
const run = () => { const run = () => {
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
// 微信小程序从基础库 2.21.0 开始, wx.chooseImage 停止维护,请使用 uni.chooseMedia 代替。 // 微信小程序从基础库 2.21.0 开始, wx.chooseImage 停止维护,请使用 uni.chooseMedia 代替。
// 微信小程序在2023年10月17日之后,使用本API需要配置隐私协议 // 微信小程序在2023年10月17日之后,使用本API需要配置隐私协议
uni.chooseMedia({ uni.chooseMedia({
count: 1, count: 1,
mediaType: ['image'], mediaType: [ "image" ],
success: (res) => { success: (res) => {
loading.value = true loading.value = true;
const tempFilePath = res.tempFiles[0].tempFilePath const tempFilePath = res.tempFiles[0].tempFilePath;
uploadFile<T>({ tempFilePath, formData, data, error, loading }) uploadFile<T>({ tempFilePath, formData, data, error, loading });
}, },
fail: (err) => { fail: (err) => {
console.log('uni.chooseMedia err->', err) console.log("uni.chooseMedia err->", err);
error.value = true 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 });
},
fail: (err) => {
console.log("uni.chooseImage err->", err);
error.value = true;
},
});
// #endif // #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 })
},
fail: (err) => {
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 }) { function uploadFile<T>({ tempFilePath, formData, data, error, loading }) {
uni.uploadFile({ uni.uploadFile({
url: VITE_UPLOAD_BASEURL, url: VITE_UPLOAD_BASEURL,
filePath: tempFilePath, filePath: tempFilePath,
name: 'file', name: "file",
formData, formData,
success: (uploadFileRes) => { success: (uploadFileRes) => {
data.value = uploadFileRes.data as T data.value = uploadFileRes.data as T;
}, },
fail: (err) => { fail: (err) => {
console.log('uni.uploadFile err->', err) console.log("uni.uploadFile err->", err);
error.value = true error.value = true;
}, },
complete: () => { complete: () => {
loading.value = false loading.value = false;
}, },
}) });
} }
/* eslint-disable no-unused-vars */
export {}
declare module 'vue' {
declare module "vue" {
interface ComponentCustomProperties { interface ComponentCustomProperties {
$t: (key: string, opt?: Record<string, any>) => string $t: (key: string, opt?: Record<string, any>) => string
$tm: (key: string, opt?: Record<string, any>) => [] | { [p: string]: any } $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' import { useUserStore } from "@/store";
import qs from "qs";
export type CustomRequestOptions = UniApp.RequestOptions & { export type CustomRequestOptions = IUniUploadFileOptions;
query?: Record<string, any>
} & IUniUploadFileOptions // 添加uni.uploadFile参数类型
// 请求基地址 // 请求基地址
const baseURL = import.meta.env.VITE_SERVER_BASEURL const baseURL = import.meta.env.VITE_SERVER_BASEURL;
// 拦截器配置 // 拦截器配置
const httpInterceptor = { const httpInterceptor = {
// 拦截前触发 // 拦截前触发
invoke(options: CustomRequestOptions) { invoke(options: CustomRequestOptions) {
// 接口请求支持通过 query 参数配置 queryString // 接口请求支持通过 query 参数配置 queryString
if (options.query) { if (options.query) {
const queryStr = qs.stringify(options.query) const queryStr = qs.stringify(options.query);
if (options.url.includes('?')) { if (options.url.includes("?")) {
options.url += `&${queryStr}` options.url += `&${queryStr}`;
} else { } else {
options.url += `?${queryStr}` options.url += `?${queryStr}`;
} }
} }
// api 目前为 mock 接口,所以无需处理 // api 目前为 mock 接口,所以无需处理
if (!options.url.startsWith('http')) { if (!options.url.startsWith("http")) {
// 1. 非 http 开头需拼接地址 // 1. 非 http 开头需拼接地址
options.url = baseURL + options.url options.url = baseURL + options.url;
} }
// 2. 请求超时 // 2. 请求超时
options.timeout = 10000 // 10s options.timeout = 10_000; // 10s
// 3. 添加小程序端请求头标识 // 3. 添加小程序端请求头标识
options.header = { options.header = {
platform: 'mp-weixin', // 可选值与 uniapp 定义的平台一致,告诉后台来源 platform: "mp-weixin", // 可选值与 uniapp 定义的平台一致,告诉后台来源
...options.header, ...options.header,
} };
// 4. 添加 token 请求头标识 // 4. 添加 token 请求头标识
const userStore = useUserStore() const userStore = useUserStore();
const { token } = userStore.userInfo as unknown as IUserInfo const { token } = userStore.userInfo as unknown as IUserInfo;
if (token) { if (token) {
options.header.Authorization = `Bearer ${token}` options.header.Authorization = `Bearer ${token}`;
} }
}, },
} };
export const requestInterceptor = { export const requestInterceptor = {
install() { install() {
// 拦截 request 请求 // 拦截 request 请求
uni.addInterceptor('request', httpInterceptor) uni.addInterceptor("request", httpInterceptor);
// 拦截 uploadFile 文件上传 // 拦截 uploadFile 文件上传
uni.addInterceptor('uploadFile', httpInterceptor) uni.addInterceptor("uploadFile", httpInterceptor);
}, },
} };
...@@ -4,51 +4,51 @@ ...@@ -4,51 +4,51 @@
* 可以设置路由白名单,或者黑名单,看业务需要选哪一个 * 可以设置路由白名单,或者黑名单,看业务需要选哪一个
* 我这里应为大部分都可以随便进入,所以使用黑名单 * 我这里应为大部分都可以随便进入,所以使用黑名单
*/ */
import { useUserStore } from '@/store' import { useUserStore } from "@/store";
import { getNeedLoginPages, needLoginPages as _needLoginPages } from '@/utils' import { needLoginPages as _needLoginPages, getNeedLoginPages } from "@/utils";
// TODO Check // TODO Check
const loginRoute = '/pages/login/index' const loginRoute = "/pages/login/index";
const isLogined = () => { const isLogined = () => {
const userStore = useUserStore() const userStore = useUserStore();
return userStore.isLogined return userStore.isLogined;
} };
const isDev = import.meta.env.DEV const isDev = import.meta.env.DEV;
// 黑名单登录拦截器 - (适用于大部分页面不需要登录,少部分页面需要登录) // 黑名单登录拦截器 - (适用于大部分页面不需要登录,少部分页面需要登录)
const navigateToInterceptor = { const navigateToInterceptor = {
// 注意,这里的url是 '/' 开头的,如 '/pages/index/index',跟 'pages.json' 里面的 path 不同 // 注意,这里的url是 '/' 开头的,如 '/pages/index/index',跟 'pages.json' 里面的 path 不同
invoke({ url }: { url: string }) { invoke({ url }: { url: string }) {
console.log(url) // /pages/route-interceptor/index?name=feige&age=30 console.log(url); // /pages/route-interceptor/index?name=feige&age=30
const path = url.split('?')[0] const path = url.split("?")[0];
let needLoginPages: string[] = [] let needLoginPages: string[] = [];
// 为了防止开发时出现BUG,这里每次都获取一下。生产环境可以移到函数外,性能更好 // 为了防止开发时出现BUG,这里每次都获取一下。生产环境可以移到函数外,性能更好
if (isDev) { if (isDev) {
needLoginPages = getNeedLoginPages() needLoginPages = getNeedLoginPages();
} else { } else {
needLoginPages = _needLoginPages needLoginPages = _needLoginPages;
} }
console.log(needLoginPages.includes(path)) console.log(needLoginPages.includes(path));
if (needLoginPages.includes(path)) { if (needLoginPages.includes(path)) {
const isLogin = isLogined() const isLogin = isLogined();
if (isLogin) { if (isLogin) {
return true return true;
} }
const redirectRoute = `${loginRoute}?redirect=${encodeURIComponent(url)}` const redirectRoute = `${loginRoute}?redirect=${encodeURIComponent(url)}`;
uni.navigateTo({ url: redirectRoute }) uni.navigateTo({ url: redirectRoute });
return false return false;
} }
return true return true;
}, },
} };
export const routeInterceptor = { export const routeInterceptor = {
install() { install() {
uni.addInterceptor('navigateTo', navigateToInterceptor) uni.addInterceptor("navigateTo", navigateToInterceptor);
uni.addInterceptor('reLaunch', navigateToInterceptor) uni.addInterceptor("reLaunch", navigateToInterceptor);
uni.addInterceptor('redirectTo', navigateToInterceptor) uni.addInterceptor("redirectTo", navigateToInterceptor);
}, },
} };
<template> <template>
<view class="default-layout"> <view class="default-layout">
<slot /> <slot />
<wd-toast /> <wd-toast />
<wd-message-box /> <wd-message-box />
</view> </view>
</template> </template>
<style lang="scss"> <style lang="scss">
.default-layout { .default-layout {
height: 100vh; height: 100vh;
/* #ifdef H5 */ /* #ifdef H5 */
padding-bottom: 50px; padding-bottom: 50px;
overflow: auto; overflow: auto;
/* #endif */ /* #endif */
} }
</style> </style>
<template> <template>
<view class="text-center p-4"> <view class="text-center p-4">
<slot /> <slot />
<wd-toast /> <wd-toast />
<wd-message-box /> <wd-message-box />
</view> </view>
</template> </template>
import { createI18n } from 'vue-i18n' import { createI18n } from "vue-i18n";
import en from './en.json' import en from "./en.json";
import zhHans from './zh-Hans.json' // 简体中文 import zhHans from "./zh-Hans.json"; // 简体中文
const messages = { const messages = {
en, en,
'zh-Hans': zhHans, // key 不能乱写,查看截图 screenshots/i18n.png "zh-Hans": zhHans, // key 不能乱写,查看截图 screenshots/i18n.png
} };
const i18n = createI18n({ const i18n = createI18n({
locale: uni.getLocale(), // 获取已设置的语言,fallback 语言需要再 manifest.config.ts 中设置 locale: uni.getLocale(), // 获取已设置的语言,fallback 语言需要再 manifest.config.ts 中设置
messages, messages,
}) });
console.log(uni.getLocale()) console.log(uni.getLocale());
console.log(i18n.global.locale) console.log(i18n.global.locale);
/** /**
* 非 vue 文件使用这个方法 * 非 vue 文件使用这个方法
* @param { string } localeKey 多语言的key,eg: "app.name" * @param { string } localeKey 多语言的key,eg: "app.name"
*/ */
export const translate = (localeKey: string) => { export const translate = (localeKey: string) => {
if (!localeKey) { if (!localeKey) {
console.error(`[i18n] Function translate(), localeKey param is required`) console.error(`[i18n] Function translate(), localeKey param is required`);
return '' return "";
} }
const locale = uni.getLocale() const locale = uni.getLocale();
console.log('locale:', locale) console.log("locale:", locale);
const message = messages[locale] const message = messages[locale];
if (Object.keys(message).includes(localeKey)) { if (Object.keys(message).includes(localeKey)) {
return message[localeKey] return message[localeKey];
} }
return localeKey return localeKey;
} };
export default i18n export default i18n;
import { createSSRApp } from 'vue' import { createSSRApp } from "vue";
import uvUI from '@climblee/uv-ui'
import App from './App.vue' import uvUI from "@climblee/uv-ui";
import store from './store'
import { routeInterceptor, requestInterceptor } from './interceptors' import App from "./App.vue";
import i18n from './locale/index' import { requestInterceptor, routeInterceptor } from "./interceptors";
import 'virtual:svg-icons-register' import i18n from "./locale/index";
import 'virtual:uno.css' import store from "./store";
import '@/style/index.scss'
import "virtual:svg-icons-register";
import "virtual:uno.css";
import "@/style/index.scss";
// production mock server // production mock server
// 线上报错,TODO: fix me // 线上报错,TODO: fix me
...@@ -18,13 +22,13 @@ import '@/style/index.scss' ...@@ -18,13 +22,13 @@ import '@/style/index.scss'
// } // }
export function createApp() { export function createApp() {
const app = createSSRApp(App) const app = createSSRApp(App);
app.use(store) app.use(store);
app.use(i18n) app.use(i18n);
app.use(uvUI) app.use(uvUI);
app.use(routeInterceptor) app.use(routeInterceptor);
app.use(requestInterceptor) app.use(requestInterceptor);
return { return {
app, app,
} };
} }
...@@ -5,10 +5,14 @@ ...@@ -5,10 +5,14 @@
</route> </route>
<template> <template>
<view class="text-center"> <view class="text-center">
<view class="m-8">http://localhost:9000/#/pages-sub/demo/index</view> <view class="m-8">
<view class="text-green-500">分包页面demo</view> http://localhost:9000/#/pages-sub/demo/index
</view> </view>
<view class="text-green-500">
分包页面demo
</view>
</view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
......
...@@ -5,14 +5,14 @@ ...@@ -5,14 +5,14 @@
} }
</route> </route>
<template> <template>
<div> <div>
<h1>欢迎使用 unibest</h1> <h1>欢迎使用 unibest</h1>
<view class="h-10"></view> <view class="h-10"></view>
<AppTest>这个组件会自动导入</AppTest> <AppTest>这个组件会自动导入</AppTest>
<view class="h-10"></view> <view class="h-10"></view>
<AppTest2>这个组件会自动导入</AppTest2> <AppTest2>这个组件会自动导入</AppTest2>
<view class="text-red-700 mt-4"> <view class="text-red-700 mt-4">
不可滥用自动导入,不是全局要用的组件不建议放到 `src/components` 里面,会增加包的体积 不可滥用自动导入,不是全局要用的组件不建议放到 `src/components` 里面,会增加包的体积
</view> </view>
</div> </div>
</template> </template>
...@@ -8,48 +8,71 @@ ...@@ -8,48 +8,71 @@
</route> </route>
<template> <template>
<view class="p-6 text-center"> <view class="p-6 text-center">
<view class="my-2">使用的是 laf 云后台</view> <view class="my-2">
<view class="text-green-400">我的推荐码,可以获得佣金</view> 使用的是 laf 云后台
</view>
<view class="text-green-400">
我的推荐码,可以获得佣金
</view>
<!-- #ifdef H5 --> <!-- #ifdef H5 -->
<view class="my-2"> <view class="my-2">
<a class="my-2" :href="recommendUrl" target="_blank">{{ recommendUrl }}</a> <a class="my-2"
</view> :href="recommendUrl"
<!-- #endif --> target="_blank">
{{ recommendUrl }}
</a>
</view>
<!-- #endif -->
<!-- #ifndef H5 --> <!-- #ifndef H5 -->
<view class="my-2 text-left text-sm">{{ recommendUrl }}</view> <view class="my-2 text-left text-sm">
<!-- #endif --> {{ recommendUrl }}
</view>
<!-- #endif -->
<!-- http://localhost:9000/#/pages/index/request --> <!-- http://localhost:9000/#/pages/index/request -->
<wd-button @click="run" class="my-6">发送请求</wd-button> <wd-button class="my-6" @click="run">
<view class="h-12"> 发送请求
<view v-if="loading">loading...</view> </wd-button>
<block v-else> <view class="h-12">
<view class="text-xl">请求数据如下</view> <view v-if="loading">
<view class="text-green leading-8">{{ JSON.stringify(data) }}</view> loading...
</block> </view>
<block v-else>
<view class="text-xl">
请求数据如下
</view>
<view class="text-green leading-8">
{{ JSON.stringify(data) }}
</view>
</block>
</view>
<wd-button class="my-6"
:disabled="!data"
type="error"
@click="reset">
重置数据
</wd-button>
</view> </view>
<wd-button type="error" @click="reset" class="my-6" :disabled="!data">重置数据</wd-button>
</view>
</template> </template>
<script lang="ts" setup> <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 = { // const initialData = {
// name: 'initialData', // name: 'initialData',
// id: '1234', // id: '1234',
// } // }
const initialData = undefined const initialData = undefined;
// 适合少部分全局性的接口————多个页面都需要的请求接口,额外编写一个 Service 层 // 适合少部分全局性的接口————多个页面都需要的请求接口,额外编写一个 Service 层
const { loading, error, data, run } = useRequest<IFooItem>(() => getFooAPI('菲鸽'), { const { loading, error, data, run } = useRequest<IFooItem>(() => getFooAPI("菲鸽"), {
initialData, initialData,
}) });
const reset = () => { const reset = () => {
data.value = initialData data.value = initialData;
} };
</script> </script>
...@@ -8,55 +8,77 @@ ...@@ -8,55 +8,77 @@
</route> </route>
<template> <template>
<view class="p-6 text-center"> <view class="p-6 text-center">
<!-- http://localhost:9000/#/pages/index/request --> <!-- http://localhost:9000/#/pages/index/request -->
<wd-button @click="getFoo" class="my-6">发送请求</wd-button> <wd-button class="my-6" @click="getFoo">
<view class="h-12"> 发送请求
<view v-if="loading1">loading...</view> </wd-button>
<block v-else> <view class="h-12">
<view class="text-xl">请求数据如下</view> <view v-if="loading1">
<view class="text-green leading-8">{{ JSON.stringify(data1) }}</view> loading...
</block> </view>
<block v-else>
<view class="text-xl">
请求数据如下
</view>
<view class="text-green leading-8">
{{ JSON.stringify(data1) }}
</view>
</block>
</view>
<wd-button class="my-6" @click="getBar">
发送请求2
</wd-button>
<view class="h-12">
<view v-if="loading2">
loading...
</view>
<block v-else>
<view class="text-xl">
请求数据如下
</view>
<view class="text-green leading-8">
{{ JSON.stringify(data2) }}
</view>
</block>
</view>
<wd-button class="my-6"
:disabled="!data1 || !data2"
type="error"
@click="reset">
重置数据
</wd-button>
<wd-button class="my-6 ml-2"
:disabled="!!data1 || !!data2"
type="success"
@click="getAllData">
同时发送请求
</wd-button>
</view> </view>
<wd-button @click="getBar" class="my-6">发送请求2</wd-button>
<view class="h-12">
<view v-if="loading2">loading...</view>
<block v-else>
<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>
<wd-button type="success" @click="getAllData" class="my-6 ml-2" :disabled="!!data1 || !!data2">
同时发送请求
</wd-button>
</view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { getFooAPI, postFooAPI, IFooItem } from '@/service/foo' import { getFooAPI, IFooItem, postFooAPI } from "@/service/foo";
// 适合少部分全局性的接口————多个页面都需要的请求接口,额外编写一个 Service 层 // 适合少部分全局性的接口————多个页面都需要的请求接口,额外编写一个 Service 层
const { const {
loading: loading1, loading: loading1,
error: err1, error: err1,
data: data1, data: data1,
run: getFoo, run: getFoo,
} = useRequest<IFooItem>(() => getFooAPI('菲鸽')) } = useRequest<IFooItem>(() => getFooAPI("菲鸽"));
const { const {
loading: loading2, loading: loading2,
error: err2, error: err2,
data: data2, data: data2,
run: getBar, run: getBar,
} = useRequest<IFooItem>(() => postFooAPI('菲鸽222')) } = useRequest<IFooItem>(() => postFooAPI("菲鸽222"));
const reset = () => { const reset = () => {
data1.value = undefined data1.value = undefined;
data2.value = undefined data2.value = undefined;
} };
const getAllData = () => { const getAllData = () => {
getFoo() getFoo();
getBar() getBar();
} };
</script> </script>
...@@ -8,21 +8,31 @@ ...@@ -8,21 +8,31 @@
</route> </route>
<template> <template>
<view class="p-4 text-center"> <view class="p-4 text-center">
<wd-button @click="run">选择图片并上传</wd-button> <wd-button @click="run">
<view v-if="loading" class="text-blue h-10">上传...</view> 选择图片并上传
<template v-else> </wd-button>
<view class="m-2">上传后返回的接口数据:</view> <view v-if="loading" class="text-blue h-10">
<view class="m-2">{{ data }}</view> 上传...
<view class="h-80 w-full"> </view>
<image v-if="data" :src="data || data" mode="scaleToFill" /> <template v-else>
</view> <view class="m-2">
</template> 上传后返回的接口数据:
</view> </view>
<view class="m-2">
{{ data }}
</view>
<view class="h-80 w-full">
<image v-if="data"
mode="scaleToFill"
:src="data || data" />
</view>
</template>
</view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
const { loading, data, run } = useUpload({ user: '菲鸽' }) const { loading, data, run } = useUpload({ user: "菲鸽" });
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
......
...@@ -8,15 +8,23 @@ ...@@ -8,15 +8,23 @@
</route> </route>
<template> <template>
<view class="mt-4"> <view class="mt-4">
进过多次测试发现,粘贴的css代码块在如下情况时会出现格式化问题: 进过多次测试发现,粘贴的css代码块在如下情况时会出现格式化问题:
<view class="ml-4">粘贴的css代码块中类名上面不包含空行(与大小写无关)</view> <view class="ml-4">
<view class="ml-4 text-green-600">1. 中间有空行的,正常,不用处理;</view> 粘贴的css代码块中类名上面不包含空行(与大小写无关)
<view class="ml-4 text-red-600"> </view>
2. 中间没有空行的,格式化异常,通过 ctrl+Z,ctrl+S 可以搞定 <view class="ml-4 text-green-600">
1. 中间有空行的,正常,不用处理;
</view>
<view class="ml-4 text-red-600">
2. 中间没有空行的,格式化异常,通过 ctrl+Z,ctrl+S 可以搞定
</view>
<image class="css-img mt-2"
height="885"
mode="scaleToFill"
src="./css.png"
width="688" />
</view> </view>
<image src="./css.png" mode="scaleToFill" class="css-img mt-2" width="688" height="885" />
</view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
...@@ -25,6 +33,7 @@ ...@@ -25,6 +33,7 @@
<style lang="scss" scoped> <style lang="scss" scoped>
// 最初的代码如下(版本1) // 最初的代码如下(版本1)
/* /*
.test{ .test{
background: #FFF; background: #FFF;
...@@ -35,6 +44,7 @@ ...@@ -35,6 +44,7 @@
*/ */
// 中间有空行可以正常格式化(版本2) // 中间有空行可以正常格式化(版本2)
/* /*
.test{ .test{
background: #FFF; background: #FFF;
......
...@@ -6,13 +6,15 @@ ...@@ -6,13 +6,15 @@
</route> </route>
<template> <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> </template>
<script lang="ts" setup> <script lang="ts" setup>
type T = TestEnum.A type T = TestEnum.A
const a = 'a' as T const a = "a" as T;
console.log(a) console.log(a);
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
......
...@@ -5,18 +5,20 @@ ...@@ -5,18 +5,20 @@
</route> </route>
<template> <template>
<view class="mt-4 ml-4"> <view class="mt-4 ml-4">
当前环境 import.meta.env.DEV: 当前环境 import.meta.env.DEV:
<text class="text-red-500 ml-4">{{ isDev }}</text> <text class="text-red-500 ml-4">{{ isDev }}</text>
</view> </view>
<view class="mt-4 ml-4"> <view class="mt-4 ml-4">
当前环境所使用的环境文件 当前环境所使用的环境文件
<text class="text-red-500 ml-4">{{ VITE_ENV_FILE }}</text> <text class="text-red-500 ml-4">{{ VITE_ENV_FILE }}</text>
</view> </view>
<view class="text-red-500 mt-8 ml-4">环境变量的使用与 --mode 参数配合使用</view> <view class="text-red-500 mt-8 ml-4">
环境变量的使用与 --mode 参数配合使用
</view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
const isDev = import.meta.env.DEV const isDev = import.meta.env.DEV;
const { VITE_ENV_FILE } = import.meta.env const { VITE_ENV_FILE } = import.meta.env;
</script> </script>
...@@ -8,12 +8,12 @@ ...@@ -8,12 +8,12 @@
</route> </route>
<template> <template>
<view class="m-4"> <view class="m-4">
<text mr-2>iconfont:</text> <text mr-2>iconfont:</text>
<i class="iconfont icon-package text-primary"></i> <i class="iconfont icon-package text-primary"></i>
<i class="iconfont icon-chat text-primary"></i> <i class="iconfont icon-chat text-primary"></i>
<i class="iconfont icon-my text-primary"></i> <i class="iconfont icon-my text-primary"></i>
</view> </view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
......
...@@ -8,36 +8,52 @@ ...@@ -8,36 +8,52 @@
</route> </route>
<template> <template>
<view class="mt-6"> <view class="mt-6">
<button @click="getFoo" class="my-4" type="primary">测试 GET 请求</button> <button class="my-4"
<view class="text-xl">请求数据如下</view> type="primary"
<view class="text-green h-10">{{ JSON.stringify(data) }}</view> @click="getFoo">
<view class="text-xl">完整数据</view> 测试 GET 请求
<view class="text-green h-20">{{ JSON.stringify(originalData) }}</view> </button>
<button class="my-8" type="warn" @click="reset">一键清空数据</button> <view class="text-xl">
</view> 请求数据如下
</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> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { getMockAPI } from '@/service/mock' import { getMockAPI } from "@/service/mock";
onLoad(() => { onLoad(() => {
getFoo() getFoo();
}) });
const originalData = ref<IResData<any>>() const originalData = ref<IResData<any>>();
const data = ref() const data = ref();
const getFoo = async () => { const getFoo = async () => {
const res = await getMockAPI('菲鸽') const res = await getMockAPI("菲鸽");
data.value = res.data data.value = res.data;
originalData.value = res originalData.value = res;
} };
const reset = () => { const reset = () => {
data.value = undefined data.value = undefined;
originalData.value = undefined originalData.value = undefined;
} };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
......
...@@ -6,36 +6,36 @@ ...@@ -6,36 +6,36 @@
</route> </route>
<template> <template>
<view class="text-green">微信分享页</view> <view class="text-green">
<view class="text-green-500">请在微信小程序中体验,或者开发者工具</view> 微信分享页
<view>1) 默认是不激活”发送给朋友“和”分享到朋友圈“的,如下图</view> </view>
<image <view class="text-green-500">
src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/wx-share-before.png" 请在微信小程序中体验,或者开发者工具
mode="widthFix" </view>
/> <view>1) 默认是不激活”发送给朋友“和”分享到朋友圈“的,如下图</view>
<view>2) 增加了onShareAppMessage和onShareTimeline后,就可以微信分享了,如下图</view> <image mode="widthFix"
<image src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/wx-share-before.png" />
src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/wx-share-after.png" <view>2) 增加了onShareAppMessage和onShareTimeline后,就可以微信分享了,如下图</view>
mode="widthFix" <image mode="widthFix"
/> src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/wx-share-after.png" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app' import { onShareAppMessage, onShareTimeline } from "@dcloudio/uni-app";
/** 激活“分享给好友” */ /** 激活“分享给好友” */
onShareAppMessage((options: Page.ShareAppMessageOption): Page.CustomShareContent => { onShareAppMessage((options: Page.ShareAppMessageOption): Page.CustomShareContent => {
console.log('options:', options) console.log("options:", options);
return { return {
title: '自定义分享标题', title: "自定义分享标题",
desc: 'unibest 演示示例', desc: "unibest 演示示例",
path: '/pages/index/index?id=xxx', path: "/pages/index/index?id=xxx",
} };
}) });
/** 激活“分享到朋友圈”, 注意:需要先激活“分享给好友” */ /** 激活“分享到朋友圈”, 注意:需要先激活“分享给好友” */
onShareTimeline((): Page.ShareTimelineContent => { onShareTimeline((): Page.ShareTimelineContent => {
return { return {
title: '自定义分享标题', title: "自定义分享标题",
query: 'a=1&b=2', query: "a=1&b=2",
} };
}) });
</script> </script>
...@@ -5,24 +5,23 @@ ...@@ -5,24 +5,23 @@
</route> </route>
<template> <template>
<uni-nav-bar <uni-nav-bar :border="false"
title="自定义导航栏" class="fixed w-full"
left-icon="left" left-icon="left"
@clickLeft="goBack" :status-bar="true"
class="fixed w-full" title="自定义导航栏"
:border="false" @click-left="goBack">
:status-bar="true" </uni-nav-bar>
></uni-nav-bar> <view class="h-11" :style="{ paddingTop: `${safeAreaInsets?.top }px` }"></view>
<view class="h-11" :style="{ paddingTop: safeAreaInsets?.top + 'px' }"></view> <view>
<view> <fly-content :line="20" />
<fly-content :line="20" /> </view>
</view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
const goBack = () => { const goBack = () => {
uni.navigateBack() uni.navigateBack();
} };
// 获取屏幕边界到安全区域距离 // 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync() const { safeAreaInsets } = uni.getSystemInfoSync();
</script> </script>
...@@ -5,16 +5,22 @@ ...@@ -5,16 +5,22 @@
</route> </route>
<template> <template>
<fly-navbar /> <fly-navbar />
<view class="bg-green-300 min-h-20" :style="{ paddingTop: safeAreaInsets?.top + 'px' }"> <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 class="p-4">通常页面顶部有一个图片或背景色</view> 自定义导航栏,设置"navigationStyle":"custom"
<view class="p-4">本实例没有导航栏,但是需要返回</view> </view>
</view> <view class="p-4">
<fly-content :line="20" /> 通常页面顶部有一个图片或背景色
</view>
<view class="p-4">
本实例没有导航栏,但是需要返回
</view>
</view>
<fly-content :line="20" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
// 获取屏幕边界到安全区域距离 // 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync() const { safeAreaInsets } = uni.getSystemInfoSync();
</script> </script>
...@@ -6,35 +6,53 @@ ...@@ -6,35 +6,53 @@
</route> </route>
<template> <template>
<view class="flex justify-center items-center text-blue-500 mt-4 mb-4"> <view class="flex justify-center items-center text-blue-500 mt-4 mb-4">
<view class="w-20">Count: {{ countStore.count }}</view> <view class="w-20">
<button class="ml-2 mr-2" @click="countStore.decrement">-1</button> Count: {{ countStore.count }}
<button class="ml-2 mr-2" @click="countStore.increment">+1</button> </view>
<button class="ml-2 mr-2" @click="countStore.reset">重置</button> <button class="ml-2 mr-2" @click="countStore.decrement">
</view> -1
<view class="m-8 text-4 leading-8"> </button>
<view class="text-center">{{ userStore.userInfo }}</view> <button class="ml-2 mr-2" @click="countStore.increment">
<view class="text-center">请观察小程序的store,可以看到是可以正常设置的</view> +1
<button @click="setUserInfo">设置UserInfo</button> </button>
<button @click="clearUserInfo" class="mt-4">清除UserInfo</button> <button class="ml-2 mr-2" @click="countStore.reset">
<button @click="resetUserStore" class="mt-4">reset UserStore</button> 重置
</view> </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 class="mt-4" @click="clearUserInfo">
清除UserInfo
</button>
<button class="mt-4" @click="resetUserStore">
reset UserStore
</button>
</view>
</template> </template>
<script lang="ts" setup> <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 = () => { const setUserInfo = () => {
userStore.setUserInfo({ nickname: '菲鸽', avatar: '', token: 'abcdef' }) userStore.setUserInfo({ nickname: "菲鸽", avatar: "", token: "abcdef" });
} };
const clearUserInfo = () => { const clearUserInfo = () => {
userStore.clearUserInfo() userStore.clearUserInfo();
} };
const resetUserStore = () => { const resetUserStore = () => {
userStore.reset() userStore.reset();
} };
</script> </script>
...@@ -8,59 +8,89 @@ ...@@ -8,59 +8,89 @@
</route> </route>
<template> <template>
<view class="mt-6"> <view class="mt-6">
<!-- http://localhost:9100/#/pages/index/request --> <!-- http://localhost:9100/#/pages/index/request -->
<button @click="getFoo" class="my-4">测试 GET 请求</button> <button class="my-4" @click="getFoo">
<view class="text-xl">请求数据如下</view> 测试 GET 请求
<view class="text-green h-10">{{ JSON.stringify(data) }}</view> </button>
<view class="text-xl">完整数据</view> <view class="text-xl">
<view class="text-green h-20">{{ JSON.stringify(originalData) }}</view> 请求数据如下
<button @click="postFoo" class="my-4">测试 POST 请求</button> </view>
<view class="text-xl">请求数据如下</view> <view class="text-green h-10">
<view class="text-green h-10">{{ JSON.stringify(data2) }}</view> {{ 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="my-2">
<view class="text-green-400">我的推荐码,可以获得佣金</view> 使用的是 laf 云后台
<!-- #ifdef H5 --> </view>
<view class="my-2 text-center"> <view class="text-green-400">
<a class="my-2 text-center" :href="recommendUrl" target="_blank">{{ recommendUrl }}</a> 我的推荐码,可以获得佣金
</view> </view>
<!-- #endif --> <!-- #ifdef H5 -->
<view class="my-2 text-center">
<a class="my-2 text-center"
:href="recommendUrl"
target="_blank">
{{ recommendUrl }}
</a>
</view>
<!-- #endif -->
<!-- #ifndef H5 --> <!-- #ifndef H5 -->
<view class="my-2 text-left text-sm">{{ recommendUrl }}</view> <view class="my-2 text-left text-sm">
{{ recommendUrl }}
</view>
<!-- #endif --> <!-- #endif -->
</view> </view>
</template> </template>
<script lang="ts" setup> <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(() => { onLoad(() => {
getFoo() getFoo();
postFoo() postFoo();
}) });
const originalData = ref<IResData<IFooItem>>() const originalData = ref<IResData<IFooItem>>();
const data = ref<IFooItem>() const data = ref<IFooItem>();
const getFoo = async () => { const getFoo = async () => {
const res = await getFooAPI('菲鸽') const res = await getFooAPI("菲鸽");
data.value = res.data data.value = res.data;
originalData.value = res originalData.value = res;
} };
const data2 = ref<IFooItem>() const data2 = ref<IFooItem>();
const postFoo = async () => { const postFoo = async () => {
const res = await postFooAPI('菲鸽2') const res = await postFooAPI("菲鸽2");
data2.value = res.data data2.value = res.data;
} };
const reset = () => { const reset = () => {
data.value = undefined data.value = undefined;
data2.value = undefined data2.value = undefined;
originalData.value = undefined originalData.value = undefined;
} };
</script> </script>
...@@ -8,19 +8,25 @@ ...@@ -8,19 +8,25 @@
</route> </route>
<template> <template>
<view class="mt-6"> <view class="mt-6">
<view class="text-2xl my-2 text-red-600">1-普通请求</view> <view class="text-2xl my-2 text-red-600">
<RequestComp /> 1-普通请求
</view>
<RequestComp />
<view class="text-2xl my-2 text-red-600">2-上传图片</view> <view class="text-2xl my-2 text-red-600">
<UploadComp /> 2-上传图片
<view class="text-2xl my-2 text-red-600">3-并发请求</view> </view>
<Request2Comp /> <UploadComp />
</view> <view class="text-2xl my-2 text-red-600">
3-并发请求
</view>
<Request2Comp />
</view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import RequestComp from './components/request.vue' import Request2Comp from "./components/request2.vue";
import Request2Comp from './components/request2.vue' import RequestComp from "./components/request.vue";
import UploadComp from './components/upload.vue' import UploadComp from "./components/upload.vue";
</script> </script>
...@@ -6,20 +6,24 @@ ...@@ -6,20 +6,24 @@
</route> </route>
<template> <template>
<view class="mt-8 text-center"> <view class="mt-8 text-center">
<view class="leading-10"> <view class="leading-10">
用户是否已登录: 用户是否已登录:
<text>{{ !!userStore?.userInfo?.token }}</text> <text>{{ !!userStore?.userInfo?.token }}</text>
</view>
<view class="text-gray">
未登录不能来本页面
</view>
<view class="text-gray">
已登录才能来本页面
</view>
</view> </view>
<view class="text-gray">未登录不能来本页面</view>
<view class="text-gray">已登录才能来本页面</view>
</view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { useUserStore } from '@/store' import { useUserStore } from "@/store";
const userStore = useUserStore() const userStore = useUserStore();
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
......
...@@ -8,33 +8,41 @@ ...@@ -8,33 +8,41 @@
</route> </route>
<template> <template>
<view class="p-4"> <view class="p-4">
<view class="text-center m-4">svg 多种使用方法</view> <view class="text-center m-4">
<image src="/static/svg/task.svg" mode="scaleToFill" class="h-20 w-20" /> svg 多种使用方法
<image :src="iconUrl" mode="scaleToFill" class="h-20 w-20" /> </view>
<image :src="iconUrl2" mode="scaleToFill" class="h-20 w-20" /> <image class="h-20 w-20"
<!-- {{ iconRaw }} --> mode="scaleToFill"
<view class="text-center m-4 text-blue-500">目前发现,小程序和APP只支持 image 方式</view> src="/static/svg/task.svg" />
<view class="text-center m-4 text-blue-500">下面的几种方式,都不支持</view> <image class="h-20 w-20"
<!-- #ifdef H5 --> mode="scaleToFill"
<TaskComponent class="h-20 w-20" /> :src="iconUrl" />
<SvgIcon name="task" class="h-20 w-20"></SvgIcon> <image class="h-20 w-20"
<SvgIcon name="dir-task2" class="h-20 w-20"></SvgIcon> 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>
<!-- #ifdef H5 -->
<TaskComponent class="h-20 w-20" />
<SvgIcon class="h-20 w-20" name="task"></SvgIcon>
<SvgIcon class="h-20 w-20" name="dir-task2"></SvgIcon>
<!-- #endif --> <!-- #endif -->
</view> </view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
// eslint-disable-next-line import/no-duplicates
import iconUrl from './task.svg' import iconUrl from "./task.svg";
// eslint-disable-next-line import/no-duplicates import TaskComponent from "./task.svg?component";
import iconUrl2 from './task.svg?url'
// eslint-disable-next-line import/no-duplicates
import iconRaw from './task.svg?raw'
// #ifdef H5 // #ifdef H5
// 小程序不支持 component 方式引入,运行会报错,APP不报错,但是不生效 // 小程序不支持 component 方式引入,运行会报错,APP不报错,但是不生效
// eslint-disable-next-line import/no-duplicates import iconUrl2 from "./task.svg?url";
import TaskComponent from './task.svg?component'
// #endif // #endif
</script> </script>
......
...@@ -17,80 +17,82 @@ ...@@ -17,80 +17,82 @@
</route> </route>
<template> <template>
<!-- #ifdef MP-WEIXIN --> <!-- #ifdef MP-WEIXIN -->
<view class="fly-navbar" :style="{ paddingTop: safeAreaInsets?.top + 'px' }"> <view class="fly-navbar" :style="{ paddingTop: `${safeAreaInsets?.top }px` }">
<!-- 1/3,多于1个页面,用返回图标 --> <!-- 1/3,多于1个页面,用返回图标 -->
<navigator v-if="pages.length > 1" open-type="navigateBack" class="left-icon"> <navigator v-if="pages.length > 1"
<view class="i-carbon-chevron-left text-current"></view> class="left-icon"
</navigator> open-type="navigateBack">
<!-- 2/3,只有1个页面,如果不是tabbar,需要首页图标 --> <view class="i-carbon-chevron-left text-current"></view>
<!-- 这种情况一般出现在用户直接打开分享出去的详情页面,或者使用redirectTo等API --> </navigator>
<navigator <!-- 2/3,只有1个页面,如果不是tabbar,需要首页图标 -->
v-else-if="!isTabbar" <!-- 这种情况一般出现在用户直接打开分享出去的详情页面,或者使用redirectTo等API -->
open-type="switchTab" <navigator v-else-if="!isTabbar"
url="/pages/index/index" class="left-icon"
class="left-icon" open-type="switchTab"
> url="/pages/index/index">
<view class="i-carbon-home text-current"></view> <view class="i-carbon-home text-current"></view>
</navigator> </navigator>
<!-- 3/3,如果当前页就是tabbar页,不用去首页,也就是什么图标都不需要 --> <!-- 3/3,如果当前页就是tabbar页,不用去首页,也就是什么图标都不需要 -->
<view class="title">{{ '我是标题' }}</view> <view class="title">
</view> {{ '我是标题' }}
<!-- #endif --> </view>
<scroll-view
enable-back-to-top
scroll-y
class="scroll-view-bg flex-1 h-full"
id="scroller"
refresher-enabled
@scrolltolower="onScrollToLower"
@refresherrefresh="onRefresherRefresh"
:refresher-triggered="isTriggered"
>
<view class="top-section" :style="{ paddingTop: safeAreaInsets?.top + 'px' }">
<view class="pt-1">顶部区域</view>
<view>可以是标题,也可以是个人中心头像等</view>
<view>建议本区域高度不低于200rpx</view>
</view>
<view class="p-2 leading-6 bg-white">
注意,上面的导航栏渐变效果仅微信端支持,且上面的导航栏无法抽为组件引入使用,否则滚动效果没有了。如果不只是微信小程序使用,可以
onPageScroll 实现全端效果一样,另外如果是app端,还可以配置 titleNView。参考
https://uniapp.dcloud.net.cn/tutorial/page.html#onpagescroll 。
</view>
<view class="bg-white">
<fly-content :line="30" />
</view> </view>
</scroll-view> <!-- #endif -->
<scroll-view id="scroller"
class="scroll-view-bg flex-1 h-full"
enable-back-to-top
refresher-enabled
:refresher-triggered="isTriggered"
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>
<view class="p-2 leading-6 bg-white">
注意,上面的导航栏渐变效果仅微信端支持,且上面的导航栏无法抽为组件引入使用,否则滚动效果没有了。如果不只是微信小程序使用,可以
onPageScroll 实现全端效果一样,另外如果是app端,还可以配置 titleNView。参考
https://uniapp.dcloud.net.cn/tutorial/page.html#onpagescroll 。
</view>
<view class="bg-white">
<fly-content :line="30" />
</view>
</scroll-view>
</template> </template>
<script lang="ts" setup> <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(() => { onPullDownRefresh(() => {
setTimeout(function fn() { setTimeout(() => {
console.log('refresh - onPullDownRefresh') console.log("refresh - onPullDownRefresh");
// 关闭动画 // 关闭动画
uni.stopPullDownRefresh() uni.stopPullDownRefresh();
}, 1000) }, 1000);
}) });
// 当前下拉刷新状态 // 当前下拉刷新状态
const isTriggered = ref(false) const isTriggered = ref(false);
// 自定义下拉刷新被触发 // 自定义下拉刷新被触发
const onRefresherRefresh = async () => { const onRefresherRefresh = async () => {
// 开始动画 // 开始动画
isTriggered.value = true isTriggered.value = true;
setTimeout(function fn() { setTimeout(() => {
console.log('refresh - onRefresherRefresh') console.log("refresh - onRefresherRefresh");
// 关闭动画 // 关闭动画
isTriggered.value = false isTriggered.value = false;
}, 1000) }, 1000);
} };
</script> </script>
<style lang="scss"> <style lang="scss">
......
...@@ -6,24 +6,47 @@ ...@@ -6,24 +6,47 @@
</route> </route>
<template> <template>
<view class="m-4"> <view class="m-4">
<uni-icons type="contact" size="30"></uni-icons> <uni-icons size="30" type="contact"></uni-icons>
<uni-icons type="contact" size="30" color="red"></uni-icons> <uni-icons color="red"
<uni-icons type="contact" size="30" class="text-green"></uni-icons> size="30"
<uni-icons type="contact" size="30" color="red" class="text-green"></uni-icons> type="contact">
<uni-icons type="contact" size="30" color="red" class="text-green"></uni-icons> </uni-icons>
<uni-icons type="contact" color="red" class="text-green w-4"></uni-icons> <uni-icons class="text-green"
<uni-icons type="contact" color="red" class="text-green w-8"></uni-icons> size="30"
<uni-icons :type="iconName" :color="colorName" class="text-green w-8"></uni-icons> type="contact">
</view> </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> </template>
<script lang="ts" setup> <script lang="ts" setup>
const iconName = ref<string>('contact') const iconName = ref<string>("contact");
const colorName = ref<string>('red') const colorName = ref<string>("red");
onLoad(() => { onLoad(() => {
setTimeout(() => { setTimeout(() => {
iconName.value = 'chat' iconName.value = "chat";
colorName.value = 'green' colorName.value = "green";
}, 1000) }, 1000);
}) });
</script> </script>
...@@ -6,22 +6,26 @@ ...@@ -6,22 +6,26 @@
</route> </route>
<template> <template>
<uni-card> <uni-card>
<text>这是一个基础卡片示例,内容较少,此示例展示了一个没有任何属性不带阴影的卡片。</text> <text>这是一个基础卡片示例,内容较少,此示例展示了一个没有任何属性不带阴影的卡片。</text>
</uni-card> </uni-card>
<uni-badge text="99"></uni-badge> <uni-badge text="99"></uni-badge>
<uni-rate :value="3" /> <uni-rate :value="3" />
<view> <view>
<button @click="open">打开弹窗</button> <button @click="open">
<uni-popup ref="popup" type="bottom" border-radius="10px 10px 0 0"> 打开弹窗
底部弹出 Popup 自定义圆角 </button>
</uni-popup> <uni-popup ref="popup"
</view> border-radius="10px 10px 0 0"
type="bottom">
底部弹出 Popup 自定义圆角
</uni-popup>
</view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
const popup = ref() const popup = ref();
const open = () => { const open = () => {
popup.value?.open() popup.value?.open();
} };
</script> </script>
export const icon = 'i-carbon-3d-cursor' export const icon = "i-carbon-3d-cursor";
export const nest = { export const nest = {
nest: { nest: {
icon: 'i-carbon-3d-ica', icon: "i-carbon-3d-ica",
}, },
} };
...@@ -6,58 +6,64 @@ ...@@ -6,58 +6,64 @@
</route> </route>
<template> <template>
<view class="m-4"> <view class="m-4">
<view class="mb-2"> <view class="mb-2">
这里只装了carbon的图表库,网址: 这里只装了carbon的图表库,网址:
<a href="https://icones.js.org/collection/carbon" target="_blank"> <a href="https://icones.js.org/collection/carbon" target="_blank">
https://icones.js.org/collection/carbon https://icones.js.org/collection/carbon
</a> </a>
(非H5环境,请使用浏览器打开) (非H5环境,请使用浏览器打开)
</view> </view>
<view class="i-carbon-car" /> <view class="i-carbon-car" />
<view class="i-carbon-car text-red" /> <view class="i-carbon-car text-red" />
<button class="i-carbon-sun dark:i-carbon-moon" /> <button class="i-carbon-sun dark:i-carbon-moon" />
<view class="h-10"></view> <view class="h-10"></view>
<view class="i-carbon-user-avatar text-red" /> <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="ml-2"></view>
<view :class="iconName" /> <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="分类">
<template #icon>
<view :class="iconName2" /> <view :class="iconName2" />
</template>
</wd-tabbar-item>
<wd-tabbar-item :value="2" icon="cart" title="分类">
<template #icon>
<view :class="iconName3" /> <view :class="iconName3" />
</template> <view class="my-4 text-red">
</wd-tabbar-item> 经过测试,动态图片从别的文件导入无法生效
</view> </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 icon="cart"
title="分类"
:value="2">
<template #icon>
<view :class="iconName3" />
</template>
</wd-tabbar-item>
</view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { icon, nest } from './unocss-icon' import { icon, icon2, nest, nest2 } from "./unocss-icon";
import { icon2, nest2 } from './unocss-icon.json'
// 只需要把外面的在这里写一遍就能生效了!注释掉也是生效的,但是必须要有 // 只需要把外面的在这里写一遍就能生效了!注释掉也是生效的,但是必须要有
// 'i-carbon-3d-cursor-alt' // 'i-carbon-3d-cursor-alt'
const iconName = ref<string>('i-carbon-car') const iconName = ref<string>("i-carbon-car");
const iconName2 = ref<string>('i-carbon-car') const iconName2 = ref<string>("i-carbon-car");
const iconName3 = ref<string>('i-carbon-car') const iconName3 = ref<string>("i-carbon-car");
onLoad(() => { onLoad(() => {
setTimeout(() => { setTimeout(() => {
iconName.value = 'i-carbon-4k' iconName.value = "i-carbon-4k";
iconName2.value = icon iconName2.value = icon;
iconName3.value = icon2 iconName3.value = icon2;
}, 1000) }, 1000);
setTimeout(() => { setTimeout(() => {
console.log(nest.nest.icon, nest2.nest2.icon) console.log(nest.nest.icon, nest2.nest2.icon);
iconName2.value = nest.nest.icon iconName2.value = nest.nest.icon;
iconName3.value = nest2.nest2.icon iconName3.value = nest2.nest2.icon;
}, 2000) }, 2000);
}) });
</script> </script>
...@@ -6,10 +6,18 @@ ...@@ -6,10 +6,18 @@
</route> </route>
<template> <template>
<view class="flex flex-col justify-center items-center text-5 h-12 leading-12 mt-20"> <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-green-500">
<view class="text-red-500">文字颜色 text-red-500</view> 文字颜色 text-light-50
<view class="bg-green-500 mt-4">背景色 bg-light-50</view> </view>
<view class="bg-red-500 mt-4">背景色 bg-red-500</view> <view class="text-red-500">
</view> 文字颜色 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> </template>
...@@ -8,68 +8,76 @@ ...@@ -8,68 +8,76 @@
</route> </route>
<template> <template>
<view class="p-4 text-center"> <view class="p-4 text-center">
<wd-button @click="chooseImage">选择图片并上传</wd-button> <wd-button @click="chooseImage">
<view class="m-2">上传后返回的图片地址:</view> 选择图片并上传
<view class="m-2">{{ imgStr }}</view> </wd-button>
<view class="h-80 w-full"> <view class="m-2">
<image v-if="imgStr" :src="imgStr" mode="scaleToFill" /> 上传后返回的图片地址:
</view>
<view class="m-2">
{{ imgStr }}
</view>
<view class="h-80 w-full">
<image v-if="imgStr"
mode="scaleToFill"
:src="imgStr" />
</view>
</view> </view>
</view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
const imgStr = ref('') const imgStr = ref("");
const chooseImage = () => { const chooseImage = () => {
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
// 微信小程序从基础库 2.21.0 开始, wx.chooseImage 停止维护,请使用 uni.chooseMedia 代替。 // 微信小程序从基础库 2.21.0 开始, wx.chooseImage 停止维护,请使用 uni.chooseMedia 代替。
// 微信小程序在2023年10月17日之后,使用本API需要配置隐私协议 // 微信小程序在2023年10月17日之后,使用本API需要配置隐私协议
uni.chooseMedia({ uni.chooseMedia({
count: 1, count: 1,
mediaType: ['image'], mediaType: [ "image" ],
success: (res) => { success: (res) => {
console.log(res) console.log(res);
const tempFilePath = res.tempFiles[0].tempFilePath const tempFilePath = res.tempFiles[0].tempFilePath;
uni.uploadFile({ uni.uploadFile({
url: 'https://ukw0y1.laf.run/upload', url: "https://ukw0y1.laf.run/upload",
filePath: tempFilePath, filePath: tempFilePath,
name: 'file', name: "file",
formData: { formData: {
user: '菲鸽', user: "菲鸽",
},
success: (uploadFileRes) => {
console.log(typeof uploadFileRes.data);
const data = JSON.parse(uploadFileRes.data);
imgStr.value = data.data.url;
},
});
}, },
success: (uploadFileRes) => { });
console.log(typeof uploadFileRes.data) // #endif
const data = JSON.parse(uploadFileRes.data) // #ifndef MP-WEIXIN
imgStr.value = data.data.url uni.chooseImage({
count: 1,
success: (res) => {
console.log(res);
const tempFilePath = res.tempFilePaths[0];
uni.uploadFile({
url: "https://ukw0y1.laf.run/upload",
filePath: tempFilePath,
name: "file",
formData: {
user: "菲鸽",
},
success: (uploadFileRes) => {
console.log(typeof uploadFileRes.data);
const data = JSON.parse(uploadFileRes.data);
imgStr.value = data.data.url;
},
});
}, },
}) });
}, // #endif
}) };
// #endif
// #ifndef MP-WEIXIN
uni.chooseImage({
count: 1,
success: (res) => {
console.log(res)
const tempFilePath = res.tempFilePaths[0]
uni.uploadFile({
url: 'https://ukw0y1.laf.run/upload',
filePath: tempFilePath,
name: 'file',
formData: {
user: '菲鸽',
},
success: (uploadFileRes) => {
console.log(typeof uploadFileRes.data)
const data = JSON.parse(uploadFileRes.data)
imgStr.value = data.data.url
},
})
},
})
// #endif
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
......
...@@ -8,21 +8,31 @@ ...@@ -8,21 +8,31 @@
</route> </route>
<template> <template>
<view class="p-4 text-center"> <view class="p-4 text-center">
<wd-button @click="run">选择图片并上传</wd-button> <wd-button @click="run">
<view v-if="loading" class="text-blue h-10">上传...</view> 选择图片并上传
<template v-else> </wd-button>
<view class="m-2">上传后返回的图片地址:</view> <view v-if="loading" class="text-blue h-10">
<view class="m-2">{{ data }}</view> 上传...
<view class="h-80 w-full"> </view>
<image v-if="data" :src="data" mode="scaleToFill" /> <template v-else>
</view> <view class="m-2">
</template> 上传后返回的图片地址:
</view> </view>
<view class="m-2">
{{ data }}
</view>
<view class="h-80 w-full">
<image v-if="data"
mode="scaleToFill"
:src="data" />
</view>
</template>
</view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
const { loading, data, run } = useUpload<string>({ user: '菲鸽' }) const { loading, data, run } = useUpload<string>({ user: "菲鸽" });
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
......
...@@ -5,45 +5,66 @@ ...@@ -5,45 +5,66 @@
</route> </route>
<template> <template>
<view class="mt-10"> <view class="mt-10">
<uv-button type="primary" @click="remakeQc">重新生成二维码</uv-button> <uv-button type="primary" @click="remakeQc">
<view class="center mt-8"> 重新生成二维码
<uv-qrcode </uv-button>
ref="qrcode" <view class="center mt-8">
size="200px" <uv-qrcode ref="qrcode"
value="https://h5.uvui.cn" :options="options"
:options="options" size="200px"
></uv-qrcode> value="https://h5.uvui.cn">
</view> </uv-qrcode>
<view class="m-4 flex"> </view>
<uv-icon name="home"></uv-icon> <view class="m-4 flex">
<uv-icon name="home" color="red"></uv-icon> <uv-icon name="home"></uv-icon>
<uv-icon name="home" class="text-green"></uv-icon> <uv-icon color="red" name="home"></uv-icon>
<uv-icon name="home" color="red" class="text-green"></uv-icon> <uv-icon class="text-green" name="home"></uv-icon>
<uv-icon name="home" color="red" class="text-green" size="20"></uv-icon> <uv-icon class="text-green"
<uv-icon name="home" color="red" class="text-green w-10 h-10" size="20"></uv-icon> color="red"
<uv-icon name="home" color="red" class="text-green w-20 h-20"></uv-icon> name="home">
<uv-icon name="home" color="red" class="text-green w-10" size="20"></uv-icon> </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> <uv-icon :name="iconName"></uv-icon>
</view> </view>
<view class="m-4"> <view class="m-4">
<view>富文本也是支持的:</view> <view>富文本也是支持的:</view>
<uv-parse :content="content"></uv-parse> <uv-parse :content="content"></uv-parse>
</view> </view>
<uv-popup ref="popup" @change="change"> <uv-popup ref="popup" @change="change">
<view> <view>
<text> <text>
丙辰中秋,欢饮达旦,大醉,作此篇,兼怀子由。 明月几时有?把酒问青天。 丙辰中秋,欢饮达旦,大醉,作此篇,兼怀子由。 明月几时有?把酒问青天。
不知天上宫阙,今夕是何年。我欲乘风归去,又恐琼楼玉宇,高处不胜寒。起舞弄清影,何似在人间。 不知天上宫阙,今夕是何年。我欲乘风归去,又恐琼楼玉宇,高处不胜寒。起舞弄清影,何似在人间。
转朱阁,低绮户,照无眠。不应有恨,何事长向别时圆?人有悲欢离合,月有阴晴圆缺,此事古难全。 转朱阁,低绮户,照无眠。不应有恨,何事长向别时圆?人有悲欢离合,月有阴晴圆缺,此事古难全。
但愿人长久,千里共婵娟。 但愿人长久,千里共婵娟。
</text> </text>
</view> </view>
</uv-popup> </uv-popup>
<button @click="open">打开</button> <button @click="open">
</view> 打开
</button>
</view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
...@@ -51,46 +72,46 @@ const content = `<div> ...@@ -51,46 +72,46 @@ const content = `<div>
<p style="color:red;" >露从今夜白,月是故乡明</p> <p style="color:red;" >露从今夜白,月是故乡明</p>
<img src="https://cdn.uviewui.com/uview/swiper/2.jpg" /> <img src="https://cdn.uviewui.com/uview/swiper/2.jpg" />
</div> </div>
` `;
console.log(uni.$uv.os()) console.log(uni.$uv.os());
console.log(uni.$uv.sys()) console.log(uni.$uv.sys());
console.log(uni.$uv.trim(' abc ')) // 去除两端空格 console.log(uni.$uv.trim(" abc ")); // 去除两端空格
console.log(uni.$uv.random(1, 3)) // 获取随机数 console.log(uni.$uv.random(1, 3)); // 获取随机数
const qrcode = ref(null) const qrcode = ref(null);
const options = reactive({ const options = reactive({
size: 300, size: 300,
useDynamicSize: false, useDynamicSize: false,
margin: 10, margin: 10,
backgroundColor: '#fff', backgroundColor: "#fff",
// 指定二维码前景,一般可在中间放logo // 指定二维码前景,一般可在中间放logo
foregroundImageSrc: '/static/logo.svg', foregroundImageSrc: "/static/logo.svg",
}) });
const remakeQc = () => { const remakeQc = () => {
qrcode.value.remake({ qrcode.value.remake({
success: () => { success: () => {
console.log('生成成功') console.log("生成成功");
}, },
fail: (err) => { fail: (err) => {
console.log(err) console.log(err);
}, },
}) });
} };
const iconName = ref<string>('level') const iconName = ref<string>("level");
onLoad(() => { onLoad(() => {
setTimeout(() => { setTimeout(() => {
iconName.value = 'chat' iconName.value = "chat";
}, 1000) }, 1000);
}) });
const popup = ref() const popup = ref();
const open = () => { const open = () => {
popup.value?.open() popup.value?.open();
} };
const change = (e) => { const change = (e) => {
console.log('弹窗状态改变:', e) console.log("弹窗状态改变:", e);
} };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
......
...@@ -6,17 +6,19 @@ ...@@ -6,17 +6,19 @@
</route> </route>
<template> <template>
<view class="text-5 h-8 leading-8"> <view class="text-5 h-8 leading-8">
<view class="text-red-500">在非正式版小程序里面已经集成了VConsole</view> <view class="text-red-500">
<view class="text-blue-500 mb-2">开启方式如下面</view> 在非正式版小程序里面已经集成了VConsole
<image </view>
src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/vconsole-1.png" <view class="text-blue-500 mb-2">
mode="widthFix" 开启方式如下面
/> </view>
<view class="text-blue-500 m-2">然后页面上会出现一个 `vConsole` 的调试按钮,如下图</view> <image mode="widthFix"
<image src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/vconsole-1.png" />
src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/vconsole-2.png" <view class="text-blue-500 m-2">
mode="widthFix" 然后页面上会出现一个 `vConsole` 的调试按钮,如下图
/> </view>
</view> <image mode="widthFix"
src="https://oss.laf.run/ukw0y1-site/hello-unibest-images/vconsole-2.png" />
</view>
</template> </template>
...@@ -8,83 +8,104 @@ ...@@ -8,83 +8,104 @@
</route> </route>
<template> <template>
<view class="center pt-4 flex-col"> <view class="center pt-4 flex-col">
<wd-button>主要按钮</wd-button> <wd-button>主要按钮</wd-button>
<wd-button type="success">成功按钮</wd-button> <wd-button type="success">
<wd-button type="info">信息按钮</wd-button> 成功按钮
<wd-button type="warning">警告按钮</wd-button> </wd-button>
<wd-button type="error">危险按钮</wd-button> <wd-button type="info">
<view class="h-10"></view> 信息按钮
<wd-button @click="handleClick">展示幕帘</wd-button> </wd-button>
<wd-curtain <wd-button type="warning">
:value="value" 警告按钮
:width="300" </wd-button>
src="https://via.placeholder.com/400x200.png/3c9cff/fff" <wd-button type="error">
@close="handleClose" 危险按钮
></wd-curtain> </wd-button>
<view class="mt-4"> <view class="h-10"></view>
可以通过 unocss class 类改颜色,也可以通过 color 属性修改颜色,同时存在时以 color 为优先 <wd-button @click="handleClick">
</view> 展示幕帘
<view class="mt-4"> </wd-button>
可以通过 unocss class 类改颜色,也可以通过 color 属性修改颜色,同时存在时以 color 为优先 <wd-curtain src="https://via.placeholder.com/400x200.png/3c9cff/fff"
</view> :value="value"
<view class="flex m-4"> :width="300"
<wd-icon name="add-circle"></wd-icon> @close="handleClose">
<wd-icon name="add-circle" color="red"></wd-icon> </wd-curtain>
<wd-icon class="text-green" name="add-circle"></wd-icon> <view class="mt-4">
<wd-icon class="text-green" name="add-circle" color="red"></wd-icon> 可以通过 unocss class 类改颜色,也可以通过 color 属性修改颜色,同时存在时以 color 为优先
<wd-icon class="text-green w-10 h-10" name="add-circle" color="red"></wd-icon> </view>
<view class="mt-4">
可以通过 unocss class 类改颜色,也可以通过 color 属性修改颜色,同时存在时以 color 为优先
</view>
<view class="flex m-4">
<wd-icon name="add-circle"></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"
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> <wd-icon :name="iconName"></wd-icon>
</view> </view>
<view @click="closeOutside" class="mt-4"> <view class="mt-4" @click="closeOutside">
<wd-popover v-model="show" content="popover content" @change="handleChange"> <wd-popover v-model="show"
<wd-button>点击展示</wd-button> content="popover content"
</wd-popover> @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>
</view>
</view> </view>
<view class="mt-4">
<wd-button @click="showModal">点击显示Modal</wd-button>
<wd-button @click="showToast">点击显示toast</wd-button>
</view>
</view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { useQueue, useMessage, useToast } from 'wot-design-uni' import { useMessage, useQueue, useToast } from "wot-design-uni";
const { closeOutside } = useQueue() const { closeOutside } = useQueue();
const message = useMessage() const message = useMessage();
const toast = useToast() const toast = useToast();
const show = ref<boolean>(false) const show = ref<boolean>(false);
function handleChange({ show }) { function handleChange({ show }) {
console.log(show) console.log(show);
} }
const showModal = () => { const showModal = () => {
// 顺便测试 message 的使用 // 顺便测试 message 的使用
message.show('显示隐藏切换') message.show("显示隐藏切换");
} };
const showToast = () => { const showToast = () => {
// 顺便测试 message 的使用 // 顺便测试 message 的使用
toast.success('unibest 你值得拥有') toast.success("unibest 你值得拥有");
} };
const value = ref<boolean>(false) const value = ref<boolean>(false);
function handleClick() { function handleClick() {
value.value = true value.value = true;
} }
function handleClose() { function handleClose() {
value.value = false value.value = false;
} }
const iconName = ref<string>('add-circle') const iconName = ref<string>("add-circle");
onLoad(() => { onLoad(() => {
setTimeout(() => { setTimeout(() => {
iconName.value = 'check' iconName.value = "check";
}, 1000) }, 1000);
}) });
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
......
...@@ -5,106 +5,106 @@ ...@@ -5,106 +5,106 @@
</route> </route>
<template> <template>
<view class="bg-slate-100 min-h-full box-border pb-1"> <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="tab-container sticky top-0 bg-white px-4 center h-12 z-1">
<view <view v-for="(tab, idx) in tabList"
class="w-full text-center h-10 leading-10 rounded-md" :key="tab.id"
:class="{ 'bg-green-300': idx === currIdx }" class="w-full text-center h-10 leading-10 rounded-md"
v-for="(tab, idx) in tabList" :class="{ 'bg-green-300': idx === currIdx }">
:key="tab.id" <view class="font-800" @click="currIdx = idx">
> {{ tab.title }}
<view class="font-800" @click="currIdx = idx">{{ tab.title }}</view> </view>
</view> </view>
</view> </view>
<view class="bg-slate-100 px-4 pt-3"> <view class="bg-slate-100 px-4 pt-3">
<view class="list-container"> <view class="list-container">
<view v-for="item in currContentList" :key="item.path" class="mb-3"> <view v-for="item in currContentList"
<view :key="item.path"
class="flex bg-white items-center justify-between p-3 mb-2" class="mb-3">
@click="goDetailPage(item.path)" <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="flex-1 text-4 text-dark">{{ item.title }}</text>
<text class="i-carbon-chevron-right"></text> <text class="i-carbon-chevron-right"></text>
</view> </view>
</view>
</view>
</view> </view>
</view>
</view> </view>
</view>
</template> </template>
<script setup lang="ts" name="TestIndex"> <script setup lang="ts" name="TestIndex">
import pagesJson from '@/pages.json' import pagesJson from "@/pages.json";
const handleTitle = (str?: string) => { const handleTitle = (str?: string) => {
if (!str) { if (!str) {
return '标题' return "标题";
} }
if (/%.*%/.test(str)) { if (/%.*%/.test(str)) {
return '多语言' return "多语言";
} }
return str return str;
} };
/** 基本功能 */ /** 基本功能 */
const baseDemos = pagesJson.pages 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) => ({ .map((e) => ({
title: handleTitle(e.style?.navigationBarTitleText), title: handleTitle(e.style?.navigationBarTitleText),
path: e.path, path: e.path,
})) }));
/** 页面功能 */ /** 页面功能 */
const pageDemos = pagesJson.pages 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) => ({ .map((e) => ({
title: handleTitle(e.style?.navigationBarTitleText), title: handleTitle(e.style?.navigationBarTitleText),
path: e.path, path: e.path,
})) }));
const routeInterceptionList = [ const routeInterceptionList = [
{ {
title: '说明页面', title: "说明页面",
path: 'pages/demo/route-interceptor/index', path: "pages/demo/route-interceptor/index",
}, },
{ {
title: '单独登录页面', title: "单独登录页面",
path: 'pages/demo/route-interceptor/login-page?name=feige&age=30', path: "pages/demo/route-interceptor/login-page?name=feige&age=30",
}, },
{ {
title: '登录弹窗', title: "登录弹窗",
path: 'pages/demo/route-interceptor/login-model?name=feige&age=30', path: "pages/demo/route-interceptor/login-model?name=feige&age=30",
}, },
{ {
title: '静默登录', title: "静默登录",
path: 'pages/demo/route-interceptor/login-auto?name=feige&age=30', path: "pages/demo/route-interceptor/login-auto?name=feige&age=30",
}, },
] ];
const tabList = reactive([ const tabList = reactive([
{ {
id: 1, id: 1,
title: '基础功能', title: "基础功能",
list: baseDemos, list: baseDemos,
}, },
{ {
id: 2, id: 2,
title: '登录拦截', title: "登录拦截",
list: routeInterceptionList, list: routeInterceptionList,
}, },
{ {
id: 3, id: 3,
title: '页面功能', title: "页面功能",
list: pageDemos, list: pageDemos,
}, },
]) ]);
const currIdx = ref(0) const currIdx = ref(0);
const currContentList = computed(() => { const currContentList = computed(() => {
return tabList[currIdx.value].list return tabList[currIdx.value].list;
}) });
const goDetailPage = (path: string) => { const goDetailPage = (path: string) => {
const url = `/${path}` const url = `/${path}`;
uni.navigateTo({ uni.navigateTo({
url, url,
}) });
} };
</script> </script>
<style> <style>
......
...@@ -6,27 +6,34 @@ ...@@ -6,27 +6,34 @@
</route> </route>
<template> <template>
<view class="mt-4 h-10 text-center">动态时钟</view> <view class="mt-4 h-10 text-center">
<view class="clock-box"> 动态时钟
<view class="clock" :style="{ '--ds': ds, '--dm': dm, '--dh': dh }"> </view>
<view class="clock-pane"> <view class="clock-box">
<text class="clock-num" :style="{ '--i': n }" v-for="n in 12" :key="n">{{ n }}</text> <view class="clock" :style="{ '--ds': ds, '--dm': dm, '--dh': dh }">
</view> <view class="clock-pane">
<view class="clock-hour"></view> <text v-for="n in 12"
<view class="clock-min"></view> :key="n"
<view class="clock-sec"></view> class="clock-num"
:style="{ '--i': n }">
{{ n }}
</text>
</view>
<view class="clock-hour"></view>
<view class="clock-min"></view>
<view class="clock-sec"></view>
</view>
</view> </view>
</view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
const d = new Date() const d = new Date();
const h = d.getHours() const h = d.getHours();
const m = d.getMinutes() const m = d.getMinutes();
const s = d.getSeconds() const s = d.getSeconds();
const ds = ref(s) const ds = ref(s);
const dm = ref(m + s / 60) const dm = ref(m + s / 60);
const dh = ref(h + m / 60 + s / 3600) const dh = ref(h + m / 60 + s / 3600);
</script> </script>
<style lang="scss"> <style lang="scss">
...@@ -37,6 +44,8 @@ const dh = ref(h + m / 60 + s / 3600) ...@@ -37,6 +44,8 @@ const dh = ref(h + m / 60 + s / 3600)
} }
.clock { .clock {
--step: 60s;
position: relative; position: relative;
display: flex; display: flex;
align-items: center; align-items: center;
...@@ -46,7 +55,6 @@ const dh = ref(h + m / 60 + s / 3600) ...@@ -46,7 +55,6 @@ const dh = ref(h + m / 60 + s / 3600)
font-size: 24px; font-size: 24px;
border-radius: 20px; border-radius: 20px;
box-shadow: 2px 2px 20px #0000001a; box-shadow: 2px 2px 20px #0000001a;
--step: 60s;
} }
.clock::before { .clock::before {
......
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!