-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
166 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,8 @@ const options = ref([ | |
label: '关机' | ||
}, | ||
{ | ||
label: '重启' | ||
label: '重启', | ||
divided: true | ||
}, | ||
{ | ||
label: '网络设置', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,8 @@ export default { | |
label: '关机' | ||
}, | ||
{ | ||
label: '重启' | ||
label: '重启', | ||
divided: true | ||
}, | ||
{ | ||
label: '网络设置', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,37 @@ | ||
import MagicString from 'magic-string' | ||
import type { Plugin } from 'vite' | ||
|
||
function pascalCase(str: string) { | ||
const camelCaseStr = str.replace(/-(\w)/g, (_, c) => (c ? c.toUpperCase() : '')) | ||
return camelCaseStr.charAt(0).toUpperCase() + camelCaseStr.slice(1) | ||
import AutoVite from 'unplugin-vue-components/vite' | ||
import AutoWebpack from 'unplugin-vue-components/webpack' | ||
import AutoRollup from 'unplugin-vue-components/rollup' | ||
import AutoEsbuild from 'unplugin-vue-components/esbuild' | ||
import AutoRspack from 'unplugin-vue-components/rspack' | ||
|
||
const supportMap = { | ||
'vite': AutoVite, | ||
'webpack': AutoWebpack, | ||
'rollup': AutoRollup, | ||
'esbuild': AutoEsbuild, | ||
'rspack': AutoRspack | ||
} | ||
|
||
const resolveVue = (code: string, s: MagicString) => { | ||
const results: any = [] | ||
|
||
for (const match of code.matchAll(/_resolveComponent[0-9]*\("(.+?)"\)/g)) { | ||
const matchedName = match[1] | ||
if (match.index != null && matchedName && !matchedName.startsWith('_')) { | ||
const start = match.index | ||
const end = start + match[0].length | ||
results.push({ | ||
rawName: matchedName, | ||
replace: (resolved: string) => s.overwrite(start, end, resolved) | ||
}) | ||
export const TinyVueResolver = (componentName) => { | ||
if (componentName.startsWith('Tiny') && !componentName.startsWith('TinyIcon')) { | ||
return { | ||
name: componentName.slice(4), | ||
from: '@opentiny/vue' | ||
} | ||
} | ||
|
||
return results | ||
} | ||
|
||
const findComponent = (rawName: string, name: string, s: MagicString) => { | ||
if (!name.match(/^Tiny[a-zA-Z]/)) { | ||
return | ||
} | ||
s.prepend(`import ${name} from '@opentiny/vue-${rawName.slice(5)}';\n`) | ||
} | ||
|
||
const transformCode = (code) => { | ||
const s = new MagicString(code) | ||
const results = resolveVue(code, s) | ||
|
||
for (const { rawName, replace } of results) { | ||
const name = pascalCase(rawName) | ||
findComponent(rawName, name, s) | ||
replace(name) | ||
} | ||
|
||
const result = s.toString() | ||
return result | ||
} | ||
|
||
export default function vitePluginAutoImport(): Plugin { | ||
return { | ||
name: '@opentiny/auto-import', | ||
|
||
transform(code, id) { | ||
// 不处理node_modules内的依赖 | ||
if (/\.(?:vue)$/.test(id) && !/(node_modules)/.test(id)) { | ||
return { | ||
code: transformCode(code), | ||
map: null | ||
} | ||
} | ||
} | ||
} | ||
/** TinyVue 自动导入组件的插件,支持Vite,Webpack,Rollup 等常见的构建工具。 | ||
* 目前不支持Tiny Icon的自动导入 | ||
* @example | ||
* import autoImportPlugin from '@opentiny/unplugin-tiny-vue' | ||
* plugins: [autoImportPlugin('vite')] | ||
*/ | ||
export default (name) => { | ||
// 兼容webpack/vite的差异 | ||
const autoPlugin = supportMap[name].default || supportMap[name] | ||
|
||
return autoPlugin({ | ||
resolvers: [TinyVueResolver] | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,58 @@ | |
*/ | ||
import type { ITabsRenderlessParams, ITabsPane, ITabsCustomEvent, ITabsPaneVm } from '@/types' | ||
|
||
// 此处与aui区别开,将tabNav的方法抽离出来,从源头解决pane的排序问题 | ||
const getOrderedPanes = (parent, panes) => { | ||
const slotDefault = parent.$slots.default | ||
let orders | ||
|
||
if (typeof slotDefault === 'function') { | ||
orders = [] | ||
|
||
const tabVnodes = slotDefault() | ||
const handler = ({ type, componentOptions, props }) => { | ||
let componentName = type && type.componentName | ||
|
||
if (!componentName) componentName = componentOptions && componentOptions.Ctor.extendOptions.componentName | ||
|
||
if (componentName === 'TabItem') { | ||
const paneName = (props && props.name) || (componentOptions && componentOptions.propsData.name) | ||
|
||
orders.push(paneName) | ||
} | ||
} | ||
|
||
tabVnodes.forEach(({ type, componentOptions, props, children }) => { | ||
if ( | ||
type && | ||
(type.toString() === 'Symbol(Fragment)' || // [email protected]之前的开发模式 | ||
type.toString() === 'Symbol(v-fgt)' || // [email protected] 的变更 | ||
type.toString() === 'Symbol()') // 构建后 | ||
) { | ||
Array.isArray(children) && | ||
children.forEach(({ type, componentOptions, props }) => handler({ type, componentOptions, props })) | ||
} else { | ||
handler({ type, componentOptions, props }) | ||
} | ||
}) | ||
} | ||
|
||
// 此处不同步aui,vue3情况下插槽使用v-if生成的slotDefault有差异 | ||
if (orders.length > 0) { | ||
let tmpPanes = [] | ||
|
||
orders.forEach((paneName) => { | ||
let pane = panes.find((pane) => pane.name === paneName) | ||
|
||
if (pane) tmpPanes.push(pane) | ||
}) | ||
|
||
panes = tmpPanes | ||
} | ||
|
||
return panes | ||
} | ||
|
||
export const calcPaneInstances = | ||
({ | ||
constants, | ||
|
@@ -44,24 +96,7 @@ export const calcPaneInstances = | |
index > -1 ? (currentPanes[index] = vm) : currentPanes.push(vm) | ||
} | ||
}) | ||
|
||
const currentPaneStates = currentPanes.map((pane) => pane.state) | ||
const paneStates = state.panes.map((pane) => pane.state) | ||
|
||
let newPanes = [] as ITabsPaneVm[] | ||
for (let i = 0; i < paneStates.length; i++) { | ||
const paneState = paneStates[i] | ||
const index = currentPaneStates.indexOf(paneState) | ||
|
||
if (index > -1) { | ||
newPanes.push(state.panes[i]) | ||
currentPanes.splice(index, 1) | ||
|
||
currentPaneStates.splice(index, 1) | ||
} | ||
} | ||
|
||
newPanes = newPanes.concat(currentPanes) | ||
const newPanes = getOrderedPanes(parent, currentPanes) as ITabsPaneVm[] | ||
|
||
const panesChanged = !( | ||
newPanes.length === state.panes.length && | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,4 +101,4 @@ | |
] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.