提交 3e340c50 作者: 方治民

feat: 依赖升级、增加全局 Message 工具注入、移除 fui 相关的无用代码文件和配置

上级 7a5248f4
...@@ -18,7 +18,7 @@ export function configAutoImportPlugin(): Plugin { ...@@ -18,7 +18,7 @@ export function configAutoImportPlugin(): Plugin {
'@/config/app': ['$app'], '@/config/app': ['$app'],
'@/api/services': ['defs'], '@/api/services': ['defs'],
'@/api/services/mods': ['API'], '@/api/services/mods': ['API'],
'@/commom/message': ['Message'], '@/common/message': ['Message'],
}, },
], ],
}) })
......
...@@ -63,25 +63,25 @@ ...@@ -63,25 +63,25 @@
} }
}, },
"dependencies": { "dependencies": {
"@dcloudio/uni-app": "^3.0.0-alpha-3050420220804003", "@dcloudio/uni-app": "^3.0.0-alpha-3050420220804007",
"@dcloudio/uni-app-plus": "^3.0.0-alpha-3050420220804003", "@dcloudio/uni-app-plus": "^3.0.0-alpha-3050420220804007",
"@dcloudio/uni-components": "^3.0.0-alpha-3050420220804003", "@dcloudio/uni-components": "^3.0.0-alpha-3050420220804007",
"@dcloudio/uni-h5": "^3.0.0-alpha-3050420220804003", "@dcloudio/uni-h5": "^3.0.0-alpha-3050420220804007",
"@dcloudio/uni-mp-alipay": "^3.0.0-alpha-3050420220804003", "@dcloudio/uni-mp-alipay": "^3.0.0-alpha-3050420220804007",
"@dcloudio/uni-mp-baidu": "^3.0.0-alpha-3050420220804003", "@dcloudio/uni-mp-baidu": "^3.0.0-alpha-3050420220804007",
"@dcloudio/uni-mp-kuaishou": "^3.0.0-alpha-3050420220804003", "@dcloudio/uni-mp-kuaishou": "^3.0.0-alpha-3050420220804007",
"@dcloudio/uni-mp-lark": "^3.0.0-alpha-3050420220804003", "@dcloudio/uni-mp-lark": "^3.0.0-alpha-3050420220804007",
"@dcloudio/uni-mp-qq": "^3.0.0-alpha-3050420220804003", "@dcloudio/uni-mp-qq": "^3.0.0-alpha-3050420220804007",
"@dcloudio/uni-mp-toutiao": "^3.0.0-alpha-3050420220804003", "@dcloudio/uni-mp-toutiao": "^3.0.0-alpha-3050420220804007",
"@dcloudio/uni-mp-weixin": "^3.0.0-alpha-3050420220804003", "@dcloudio/uni-mp-weixin": "^3.0.0-alpha-3050420220804007",
"@dcloudio/uni-quickapp-webview": "^3.0.0-alpha-3050420220804003", "@dcloudio/uni-quickapp-webview": "^3.0.0-alpha-3050420220804007",
"@vue/runtime-core": "^3.2.37", "@vue/runtime-core": "^3.2.37",
"@vueuse/core": "^8.9.4", "@vueuse/core": "^8.9.4",
"axios": "^0.26.1", "axios": "^0.26.1",
"dayjs": "^1.11.4", "dayjs": "^1.11.5",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"mockjs": "^1.1.0", "mockjs": "^1.1.0",
"pinia": "^2.0.17", "pinia": "^2.0.19",
"qs": "~6.9.7", "qs": "~6.9.7",
"vue": "^3.2.37", "vue": "^3.2.37",
"vue-i18n": "^9.2.2", "vue-i18n": "^9.2.2",
...@@ -91,21 +91,21 @@ ...@@ -91,21 +91,21 @@
"@commitlint/cli": "^17.0.3", "@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^16.2.4", "@commitlint/config-conventional": "^16.2.4",
"@dcloudio/types": "^3.0.13", "@dcloudio/types": "^3.0.13",
"@dcloudio/uni-automator": "^3.0.0-alpha-3050420220804003", "@dcloudio/uni-automator": "^3.0.0-alpha-3050420220804007",
"@dcloudio/uni-cli-shared": "^3.0.0-alpha-3050420220804003", "@dcloudio/uni-cli-shared": "^3.0.0-alpha-3050420220804007",
"@dcloudio/uni-helper-json": "^1.0.13", "@dcloudio/uni-helper-json": "^1.0.13",
"@dcloudio/vite-plugin-uni": "^3.0.0-alpha-3050420220804003", "@dcloudio/vite-plugin-uni": "^3.0.0-alpha-3050420220804007",
"@types/lodash-es": "^4.17.6", "@types/lodash-es": "^4.17.6",
"@types/mockjs": "^1.0.6", "@types/mockjs": "^1.0.6",
"@types/prettier": "^2.7.0", "@types/prettier": "^2.7.0",
"@types/qs": "^6.9.7", "@types/qs": "^6.9.7",
"@typescript-eslint/eslint-plugin": "^5.33.0", "@typescript-eslint/eslint-plugin": "^5.33.1",
"@typescript-eslint/parser": "^5.33.0", "@typescript-eslint/parser": "^5.33.1",
"commitizen": "^4.2.5", "commitizen": "^4.2.5",
"conventional-changelog-cli": "^2.2.2", "conventional-changelog-cli": "^2.2.2",
"cz-conventional-changelog": "^3.3.0", "cz-conventional-changelog": "^3.3.0",
"dotenv": "^16.0.1", "dotenv": "^16.0.1",
"eslint": "^8.21.0", "eslint": "^8.22.0",
"eslint-config-prettier": "^8.5.0", "eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1", "eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-vue": "^9.3.0", "eslint-plugin-vue": "^9.3.0",
...@@ -121,7 +121,7 @@ ...@@ -121,7 +121,7 @@
"prettier": "^2.7.1", "prettier": "^2.7.1",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"sort-package-json": "^1.57.0", "sort-package-json": "^1.57.0",
"stylelint": "^14.9.1", "stylelint": "^14.10.0",
"stylelint-config-html": "^1.1.0", "stylelint-config-html": "^1.1.0",
"stylelint-config-prettier": "^9.0.3", "stylelint-config-prettier": "^9.0.3",
"stylelint-config-recommended": "^8.0.0", "stylelint-config-recommended": "^8.0.0",
...@@ -130,8 +130,8 @@ ...@@ -130,8 +130,8 @@
"stylus": "^0.56.0", "stylus": "^0.56.0",
"terser": "^5.14.2", "terser": "^5.14.2",
"typescript": "^4.7.4", "typescript": "^4.7.4",
"unplugin-auto-import": "^0.7.2", "unplugin-auto-import": "^0.11.2",
"vite": "^3.0.4", "vite": "^3.0.8",
"vue-eslint-parser": "^9.0.3" "vue-eslint-parser": "^9.0.3"
}, },
"engines": { "engines": {
......
<script setup lang="ts"> <script setup lang="ts">
import { Message } from '@/common/message'
onLaunch(() => { onLaunch(() => {
console.log('App Launch') console.log('App Launch')
}) })
......
// 本文件由FirstUI授权予长沙壹润信息科技发展有限公司(手机号: 156 16 26 019 5,身份证尾号:503 75T)专用,请尊重知识产权,勿私下传播,违者追究法律责任。
const fui = {
toast: function (text: string) {
if (text) {
// #ifndef APP-PLUS
uni.showToast({
title: text,
icon: 'none',
duration: 2000,
})
// #endif
// #ifdef APP-PLUS
plus.nativeUI.toast(text, {
duration: 'short',
})
// #endif
}
},
modal: function (
title: string,
content: string,
callback: Function,
showCancel: boolean,
confirmColor: string,
confirmText: string,
) {
uni.showModal({
title: title,
content: content,
showCancel: showCancel || false,
// #ifndef MP-TOUTIAO
cancelColor: '#7F7F7F',
confirmColor: confirmColor || '#465CFF',
// #endif
confirmText: confirmText || '确定',
success(res) {
if (res.confirm) {
callback && callback(true)
} else {
callback && callback(false)
}
},
fail(err) {
console.log(err)
},
})
},
href(url: string, isMain: boolean) {
if (isMain) {
uni.switchTab({
url: url,
})
} else {
uni.navigateTo({
url: url,
})
}
},
jsonp: function (url: string, callback: Function, callbackname: string) {
// #ifdef H5
window[callbackname] = callback
const script = document.createElement('script')
script.src = url
script.type = 'text/javascript'
document.head.appendChild(script)
document.head.removeChild(script)
// #endif
},
resUrl: function () {
return 'https://res.firstui.cn/static/images'
},
}
export default fui
// 本文件由FirstUI授权予长沙壹润信息科技发展有限公司(手机号: 15 6 1 62 60 19 5,身份证尾号: 50 37 5T)专用,请尊重知识产权,勿私下传播,违者追究法律责任。
import http from '@/components/firstui/fui-request'
//初始化请求配置项
http.create({
host: 'https://ffa.firstui.cn',
header: {
// 'content-type': 'application/x-www-form-urlencoded'
},
})
//请求拦截
http.interceptors.request.use((config) => {
//请求之前可在请求头中加入token等信息
const token = uni.getStorageSync('firstui_token') || 'testToken'
if (config.header) {
config.header['token'] = token
} else {
config.header = {
token: token,
}
}
return config
})
//响应拦截
http.interceptors.response.use((response) => {
//TODO
return response
})
export default http
...@@ -3,21 +3,75 @@ export const Message = { ...@@ -3,21 +3,75 @@ export const Message = {
* 消息轻提示 * 消息轻提示
* @param text 消息内容 * @param text 消息内容
*/ */
toast: function (text: string) { toast: (text: string, duration?: 'short' | 'long'): void => {
if (text) { if (text) {
// #ifndef APP-PLUS // #ifndef APP-PLUS
uni.showToast({ uni.showToast({
title: text, title: text,
icon: 'none', icon: 'none',
duration: 2000, duration: duration === 'short' ? 2000 : 3500,
}) })
// #endif // #endif
// #ifdef APP-PLUS // #ifdef APP-PLUS
plus.nativeUI.toast(text, { plus.nativeUI.toast(text, {
duration: 'short', duration: duration || 'short',
}) })
// #endif // #endif
} }
}, },
/**
* 消息弹窗提示
* @param message 消息内容
* @param title 标题
* @returns Promise<void>
*/
alert: (message: string, title = '提示', confirmText = '确定'): Promise<void> => {
return new Promise((resolve, reject) => {
// #ifndef APP-PLUS
uni.showModal({
title: title,
content: message,
showCancel: false,
confirmText: confirmText,
success: () => resolve(),
fail: (err) => reject(err),
})
// #endif
// #ifdef APP-PLUS
plus.nativeUI.alert(message, resolve, title, confirmText)
// #endif
})
},
/**
* 消息确认提示
* @param title 标题
* @param message 提示内容
* @param confirmText 确认按钮文字
* @param showCancel 是否显示取消按钮
* @returns Promise<boolean> 是否点击了确认按钮
*/
confirm: (message: string, title = '提示', confirmText = '确定', showCancel = true): Promise<boolean> => {
return new Promise((resolve, reject) => {
// #ifndef APP-PLUS
uni.showModal({
title: title,
content: message,
showCancel: showCancel,
confirmText: confirmText,
success: (res) => resolve(res.confirm),
fail: (err) => reject(err),
})
// #endif
// #ifdef APP-PLUS
plus.nativeUI.confirm(message, ({ index }) => resolve(index === 0), {
title,
buttons: ['确认', '取消'],
verticalAlign: 'center',
})
// #endif
})
},
} }
...@@ -13,16 +13,12 @@ export const $app = config ...@@ -13,16 +13,12 @@ export const $app = config
export function setupAppConfig(app: App<Element>) { export function setupAppConfig(app: App<Element>) {
// 打印 App 信息 // 打印 App 信息
// #ifdef H5 // #ifdef H5
const block = Array(50).fill('=').join('') console.log(
const infos: string[] = [] `%c APP %c ${config.name} %c V${config.version} `,
infos.push(block) 'padding: 2px 1px; border-radius: 3px; color: #fff; background: #fa593b; font-weight: bold; margin-right: 5px;',
infos.push(`[App] name: ${config.name}`) 'padding: 2px 1px; border-radius: 3px 0 0 3px; color: #fff; background: #606060; font-weight: bold;',
infos.push(`[App] version: ${config.version}`) 'padding: 2px 1px; border-radius: 0 3px 3px 0; color: #fff; background: #42c02e; font-weight: bold;',
infos.push(`[App] description: ${config.description}`) )
infos.push(`[App] author: ${config.author.name} ${config.author.url}`)
infos.push(`[App] lastBuildTime: ${config.lastBuildTime}`)
infos.push(block)
console.log('%c' + infos.join('\n'), 'color: violet;')
// #endif // #endif
app.config.globalProperties.$app = $app app.config.globalProperties.$app = $app
......
...@@ -6,7 +6,6 @@ import { setupAppConfig } from '/@/config/app' ...@@ -6,7 +6,6 @@ import { setupAppConfig } from '/@/config/app'
import { setupStore } from '/@/store' import { setupStore } from '/@/store'
import { setupI18n } from '/@/locales' import { setupI18n } from '/@/locales'
import fui from './common/fui-app'
import fuiConfig from './components/firstui/fui-config' import fuiConfig from './components/firstui/fui-config'
export function createApp() { export function createApp() {
...@@ -24,7 +23,6 @@ export function createApp() { ...@@ -24,7 +23,6 @@ export function createApp() {
//全局组件配置 //全局组件配置
// @ts-ignore // @ts-ignore
uni.$fui = fuiConfig uni.$fui = fuiConfig
app.config.globalProperties.fui = fui
return { return {
app, app,
......
<script setup lang="ts"> <script setup lang="ts">
import { Message } from '@/common/message'
import dayjs from 'dayjs' import dayjs from 'dayjs'
const year = ref(dayjs().year()) const year = ref(dayjs().year())
const title = ref('Hello World') const title = ref('Hello World')
// TODO: 测试接口 onMounted(() => {
API.example.hello.request().then((body) => { // test API
title.value = body API.example.hello.request().then((body) => {
title.value = body
Message.toast(body) console.log(body, $app.name, $app.version)
console.log(body) Message.toast(body)
})
}) })
const change = () => { const surprise = () => {
// #ifdef APP-PLUS
const orientation = plus.navigator.getOrientation() const orientation = plus.navigator.getOrientation()
Message.toast('Orientation: ' + orientation)
if (orientation === 0) { if (orientation === 0) {
plus.screen.lockOrientation('landscape-primary') plus.screen.lockOrientation('landscape-primary')
} else if (orientation === 90) { } else if (orientation === 90) {
plus.screen.lockOrientation('portrait-primary') plus.screen.lockOrientation('portrait-primary')
} }
Message.toast('🥳 surprise~')
// #endif
// #ifndef APP-PLUS
Message.toast(`使用 APP 运行点击有惊喜~ ╰(*°▽°*)╯`)
// #endif
} }
</script> </script>
<template> <template>
<view class="content"> <view class="content">
<fui-avatar src="/static/logo.png" radius="14" @click="change" /> <fui-avatar src="/static/logo.png" radius="14" @click="surprise" />
<view class="info"> <view class="info">
<text class="title">{{ title }}</text> <text class="title">{{ title }}</text>
<text class="title">{{ $t('app.hello') }}</text> <text class="title">{{ $t('app.hello') }}</text>
......
// Generated by 'unplugin-auto-import' // Generated by 'unplugin-auto-import'
// We suggest you to commit this file into source control export {}
declare global { declare global {
const $app: typeof import('@/config/app')['$app'] const $app: typeof import('@/config/app')['$app']
const API: typeof import('@/api/services/mods')['API'] const API: typeof import('@/api/services/mods')['API']
const EffectScope: typeof import('vue')['EffectScope']
const Message: typeof import('@/common/message')['Message']
const computed: typeof import('vue')['computed'] const computed: typeof import('vue')['computed']
const createApp: typeof import('vue')['createApp'] const createApp: typeof import('vue')['createApp']
const customRef: typeof import('vue')['customRef'] const customRef: typeof import('vue')['customRef']
...@@ -10,15 +12,15 @@ declare global { ...@@ -10,15 +12,15 @@ declare global {
const defineComponent: typeof import('vue')['defineComponent'] const defineComponent: typeof import('vue')['defineComponent']
const defs: typeof import('@/api/services')['defs'] const defs: typeof import('@/api/services')['defs']
const effectScope: typeof import('vue')['effectScope'] const effectScope: typeof import('vue')['effectScope']
const EffectScope: typeof import('vue')['EffectScope']
const getCurrentInstance: typeof import('vue')['getCurrentInstance'] const getCurrentInstance: typeof import('vue')['getCurrentInstance']
const getCurrentScope: typeof import('vue')['getCurrentScope'] const getCurrentScope: typeof import('vue')['getCurrentScope']
const h: typeof import('vue')['h'] const h: typeof import('vue')['h']
const inject: typeof import('vue')['inject'] const inject: typeof import('vue')['inject']
const isProxy: typeof import('vue')['isProxy']
const isReactive: typeof import('vue')['isReactive']
const isReadonly: typeof import('vue')['isReadonly'] const isReadonly: typeof import('vue')['isReadonly']
const isRef: typeof import('vue')['isRef'] const isRef: typeof import('vue')['isRef']
const markRaw: typeof import('vue')['markRaw'] const markRaw: typeof import('vue')['markRaw']
const Message: typeof import('@/commom/message')['Message']
const nextTick: typeof import('vue')['nextTick'] const nextTick: typeof import('vue')['nextTick']
const onActivated: typeof import('vue')['onActivated'] const onActivated: typeof import('vue')['onActivated']
const onAddToFavorites: typeof import('@dcloudio/uni-app')['onAddToFavorites'] const onAddToFavorites: typeof import('@dcloudio/uni-app')['onAddToFavorites']
...@@ -77,5 +79,6 @@ declare global { ...@@ -77,5 +79,6 @@ declare global {
const useSlots: typeof import('vue')['useSlots'] const useSlots: typeof import('vue')['useSlots']
const watch: typeof import('vue')['watch'] const watch: typeof import('vue')['watch']
const watchEffect: typeof import('vue')['watchEffect'] const watchEffect: typeof import('vue')['watchEffect']
const watchPostEffect: typeof import('vue')['watchPostEffect']
const watchSyncEffect: typeof import('vue')['watchSyncEffect']
} }
export {}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论