-
-
Notifications
You must be signed in to change notification settings - Fork 18
feat: add ui tmui3.2 #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add ui tmui3.2 #115
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" | ||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" /> | ||
<title></title> | ||
<!--preload-links--> | ||
<!--app-context--> | ||
</head> | ||
|
||
<body> | ||
<div id="app"><!--app-html--></div> | ||
<script type="module" src="/src/main.ts"></script> | ||
</body> | ||
|
||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default function getData({ oldData }) { | ||
const tmuiConfig = { | ||
id: 'tmuiConfig', | ||
types: ['tmui-uni/global.d.ts'], | ||
} | ||
return { | ||
...oldData, | ||
config: oldData.config.flatMap(config => | ||
config.id === 'baseConfig' ? [tmuiConfig, config] : config, | ||
), | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"dependencies": { | ||
"@vue/compiler-core": "^3.5.11", | ||
"echarts": "5.4.2", | ||
"pinia": "^2.0.33", | ||
"sass": "^1.77.5", | ||
"tmui-uni": "^3.2.7", | ||
"vue": "^3.5.16", | ||
"vue-docgen-api": "^4.79.2", | ||
"vue-i18n": "^11.1.5" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { | ||
uniPostcssPlugin, | ||
} = require('@dcloudio/uni-cli-shared') | ||
|
||
module.exports = { | ||
plugins: [ | ||
uniPostcssPlugin(), | ||
require('autoprefixer')(), | ||
], | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<script setup lang="ts"> | ||
import { onLaunch } from '@dcloudio/uni-app' | ||
|
||
onLaunch(() => {}) | ||
</script> | ||
|
||
<style> | ||
/* 图标必须 */ | ||
@import url(tmui-uni/css/remixicon.min.css); | ||
/* 自定预处理类,可选 */ | ||
@import url(tmui-uni/css/tmui.css); | ||
page { | ||
background: #f5f5f5; | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"prompt": "template" | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,29 @@ | ||||||||||||||
export default function getData({ oldData }) { | ||||||||||||||
if (!oldData.entries) { | ||||||||||||||
oldData.entries = [] | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
const hasPiniaImport = oldData.entries.some(entry => | ||||||||||||||
entry.importer && entry.importer.includes('pinia'), | ||||||||||||||
) | ||||||||||||||
Comment on lines
+6
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Apply optional chaining to improve code safety. The static analysis tool correctly identifies that optional chaining should be used here to prevent potential runtime errors if Apply this fix: - const hasPiniaImport = oldData.entries.some(entry =>
- entry.importer && entry.importer.includes('pinia'),
- )
+ const hasPiniaImport = oldData.entries.some(entry =>
+ entry.importer?.includes('pinia'),
+ ) 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome (1.9.4)[error] 7-7: Change to an optional chain. Unsafe fix: Change to an optional chain. (lint/complexity/useOptionalChain) 🤖 Prompt for AI Agents
|
||||||||||||||
|
||||||||||||||
const hasTmuiImport = oldData.entries.some(entry => | ||||||||||||||
entry.importer && (entry.importer.includes('tmui') || entry.importer.includes('tm-ui')), | ||||||||||||||
) | ||||||||||||||
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Apply optional chaining for consistency. For consistency with the fix above, apply optional chaining here as well. - const hasTmuiImport = oldData.entries.some(entry =>
- entry.importer && (entry.importer.includes('tmui') || entry.importer.includes('tm-ui')),
- )
+ const hasTmuiImport = oldData.entries.some(entry =>
+ entry.importer?.includes('tmui') || entry.importer?.includes('tm-ui'),
+ ) 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||
|
||||||||||||||
if (!hasPiniaImport) { | ||||||||||||||
oldData.entries.push({ | ||||||||||||||
importer: 'import * as Pinia from "pinia"', | ||||||||||||||
use: 'app.use(Pinia.createPinia())', | ||||||||||||||
}) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if (!hasTmuiImport) { | ||||||||||||||
oldData.entries.push({ | ||||||||||||||
importer: 'import tmUi from "tmui-uni"', | ||||||||||||||
use: 'app.use(tmUi)', | ||||||||||||||
}) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
return oldData | ||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script lang="ts" setup> | ||
</script> | ||
|
||
<template> | ||
<view> | ||
<tm-button :block="true"> | ||
嗨~TMUI | ||
</tm-button> | ||
</view> | ||
</template> | ||
|
||
<style> | ||
|
||
</style> |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,170 @@ | ||||||||||||||||||||||||||||||
export default function getData({ oldData }) { | ||||||||||||||||||||||||||||||
// 一次性检测所有包 | ||||||||||||||||||||||||||||||
const existing = new Set( | ||||||||||||||||||||||||||||||
oldData.plugins | ||||||||||||||||||||||||||||||
.filter(p => p.importer) | ||||||||||||||||||||||||||||||
.map(p => p.importer) | ||||||||||||||||||||||||||||||
.join(' ') | ||||||||||||||||||||||||||||||
.match(/@[\w-]+\/[\w-]+/g) || [], | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// 检查是否已存在 Components 插件 | ||||||||||||||||||||||||||||||
const hasComponentsPlugin = oldData.plugins.some(p => | ||||||||||||||||||||||||||||||
p.initializer?.includes('Components('), | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// TMUI resolver 函数 - 优化版本 | ||||||||||||||||||||||||||||||
const tmuiResolver = `(name) => { | ||||||||||||||||||||||||||||||
if (!name.startsWith('Tm')) return | ||||||||||||||||||||||||||||||
const comp = name.slice(2).replace(/([A-Z])/g, '-$1').toLowerCase().replace(/^-/, 'tm-') | ||||||||||||||||||||||||||||||
return { name, from: \`tmui-uni/components/\${comp}/\${comp}.vue\` } | ||||||||||||||||||||||||||||||
}` | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// 基础配置优化 | ||||||||||||||||||||||||||||||
const baseConfig = { | ||||||||||||||||||||||||||||||
...oldData, | ||||||||||||||||||||||||||||||
define: { | ||||||||||||||||||||||||||||||
__VUE_I18N_FULL_INSTALL__: true, | ||||||||||||||||||||||||||||||
__VUE_I18N_LEGACY_API__: true, | ||||||||||||||||||||||||||||||
__VUE_I18N_PROD_DEVTOOLS__: false, | ||||||||||||||||||||||||||||||
...oldData.define, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
build: { | ||||||||||||||||||||||||||||||
target: 'es6', | ||||||||||||||||||||||||||||||
cssCodeSplit: true, | ||||||||||||||||||||||||||||||
...oldData.build, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
css: { | ||||||||||||||||||||||||||||||
preprocessorOptions: { | ||||||||||||||||||||||||||||||
scss: { | ||||||||||||||||||||||||||||||
api: 'modern-compiler', | ||||||||||||||||||||||||||||||
silenceDeprecations: ['legacy-js-api'], | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
...oldData.css, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
server: { | ||||||||||||||||||||||||||||||
port: 1314, | ||||||||||||||||||||||||||||||
proxy: { | ||||||||||||||||||||||||||||||
'/pag': { | ||||||||||||||||||||||||||||||
target: 'https://cdn.tmui.design', | ||||||||||||||||||||||||||||||
changeOrigin: true, | ||||||||||||||||||||||||||||||
rewrite: path => path.replace(/^\/api/, '/api'), | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
Comment on lines
+48
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Review the proxy configuration for security. The proxy configuration redirects The rewrite rule on line 52 replaces - rewrite: path => path.replace(/^\/api/, '/api'),
+ rewrite: path => path.replace(/^\/pag/, ''), Or if no rewrite is needed: - rewrite: path => path.replace(/^\/api/, '/api'), 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||
...oldData.server, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// 创建插件工厂函数 | ||||||||||||||||||||||||||||||
const createPlugins = () => { | ||||||||||||||||||||||||||||||
const plugins = [] | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// Components 插件 | ||||||||||||||||||||||||||||||
if (!hasComponentsPlugin) { | ||||||||||||||||||||||||||||||
plugins.push({ | ||||||||||||||||||||||||||||||
id: 'tmuiComponents', | ||||||||||||||||||||||||||||||
...(!existing.has('@uni-helper/vite-plugin-uni-components') && { | ||||||||||||||||||||||||||||||
importer: `import Components from '@uni-helper/vite-plugin-uni-components'`, | ||||||||||||||||||||||||||||||
}), | ||||||||||||||||||||||||||||||
initializer: `Components({ | ||||||||||||||||||||||||||||||
dts: true, | ||||||||||||||||||||||||||||||
resolvers: [${tmuiResolver}], | ||||||||||||||||||||||||||||||
include: [/\\.vue$/, /\\.uvue$/] | ||||||||||||||||||||||||||||||
})`, | ||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// Vue JSX 插件 | ||||||||||||||||||||||||||||||
plugins.push({ | ||||||||||||||||||||||||||||||
id: 'vueJsx', | ||||||||||||||||||||||||||||||
...(!existing.has('@vitejs/plugin-vue-jsx') && { | ||||||||||||||||||||||||||||||
importer: 'import vueJsx from "@vitejs/plugin-vue-jsx"', | ||||||||||||||||||||||||||||||
}), | ||||||||||||||||||||||||||||||
initializer: 'vueJsx()', | ||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
return plugins | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// 合并现有 Components 插件配置 | ||||||||||||||||||||||||||||||
const mergeComponentsPlugin = (plugin) => { | ||||||||||||||||||||||||||||||
const hasTmuiResolver = plugin.initializer.includes('tmui-uni/components') | ||||||||||||||||||||||||||||||
if (hasTmuiResolver) | ||||||||||||||||||||||||||||||
return plugin | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// 解析现有配置 | ||||||||||||||||||||||||||||||
const configMatch = plugin.initializer.match(/Components\(\{([^}]+)\}\)/) | ||||||||||||||||||||||||||||||
if (!configMatch) | ||||||||||||||||||||||||||||||
return plugin | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const existingConfig = configMatch[1] | ||||||||||||||||||||||||||||||
const configItems = [] | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// 提取并规范化配置项 | ||||||||||||||||||||||||||||||
const extractConfig = (key, defaultValue) => { | ||||||||||||||||||||||||||||||
const match = existingConfig.match(new RegExp(`${key}:\\s*([^,\\n}]+)`)) | ||||||||||||||||||||||||||||||
return match ? `${key}: ${match[1].trim()}` : `${key}: ${defaultValue}` | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
configItems.push(extractConfig('dts', 'true')) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// 处理 resolvers | ||||||||||||||||||||||||||||||
const resolversMatch = existingConfig.match(/resolvers:\s*\[([^\]]*)\]/) | ||||||||||||||||||||||||||||||
if (resolversMatch) { | ||||||||||||||||||||||||||||||
const existingResolvers = resolversMatch[1].trim() | ||||||||||||||||||||||||||||||
const resolversList = existingResolvers | ||||||||||||||||||||||||||||||
? `${existingResolvers.split('\n').map(line => line.trim()).filter(Boolean).join(',\n ')},\n ${tmuiResolver}` | ||||||||||||||||||||||||||||||
: tmuiResolver | ||||||||||||||||||||||||||||||
configItems.push(`resolvers: [\n ${resolversList}\n ]`) | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
else { | ||||||||||||||||||||||||||||||
configItems.push(`resolvers: [${tmuiResolver}]`) | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// 处理 include | ||||||||||||||||||||||||||||||
const includeMatch = existingConfig.match(/include:\s*\[([^\]]*)\]/) | ||||||||||||||||||||||||||||||
configItems.push(includeMatch | ||||||||||||||||||||||||||||||
? `include: [${includeMatch[1]}]` | ||||||||||||||||||||||||||||||
: 'include: [/\\.vue$/, /\\.uvue$/]', | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||
...plugin, | ||||||||||||||||||||||||||||||
initializer: `Components({\n ${configItems.join(',\n ')}\n })`, | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// 插入插件到正确位置 | ||||||||||||||||||||||||||||||
const insertPlugins = (plugins, newPlugins) => { | ||||||||||||||||||||||||||||||
const autoImportIndex = plugins.findIndex(p => p.id === 'autoImport') | ||||||||||||||||||||||||||||||
const uniIndex = plugins.findIndex(p => p.id === 'uni') | ||||||||||||||||||||||||||||||
const insertIndex = autoImportIndex !== -1 ? autoImportIndex + 1 : uniIndex | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const result = [...plugins] | ||||||||||||||||||||||||||||||
result.splice(insertIndex, 0, ...newPlugins) | ||||||||||||||||||||||||||||||
return result | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// 主逻辑 | ||||||||||||||||||||||||||||||
if (hasComponentsPlugin) { | ||||||||||||||||||||||||||||||
const updatedPlugins = baseConfig.plugins.map(plugin => | ||||||||||||||||||||||||||||||
plugin.initializer?.includes('Components(') | ||||||||||||||||||||||||||||||
? mergeComponentsPlugin(plugin) | ||||||||||||||||||||||||||||||
: plugin, | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// 只添加 vueJsx 插件 | ||||||||||||||||||||||||||||||
const vueJsxPlugin = createPlugins().find(p => p.id === 'vueJsx') | ||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||
...baseConfig, | ||||||||||||||||||||||||||||||
plugins: vueJsxPlugin ? insertPlugins(updatedPlugins, [vueJsxPlugin]) : updatedPlugins, | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// 添加所有新插件 | ||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||
...baseConfig, | ||||||||||||||||||||||||||||||
plugins: insertPlugins(baseConfig.plugins, createPlugins()), | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Several runtime-only deps look like build-time/dev deps
@vue/compiler-core
,sass
andvue-docgen-api
inflate the production bundle when declared underdependencies
. Move them todevDependencies
unless they are required at runtime.This keeps end-user installs leaner.
📝 Committable suggestion
🤖 Prompt for AI Agents