mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-12-02 17:53:47 +08:00
fix(layout): use Naive UI for the placement selector
This commit is contained in:
parent
22dfe441e0
commit
33319de653
@ -2,7 +2,10 @@ import { generateLayoutSource, layoutWriteEndpoint } from '@/layout/designer'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
|
||||
vi.mock('@/hooks/template/useI18n', () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
useI18n: () => ({
|
||||
t: (key: string, params?: { row?: number }) =>
|
||||
typeof params?.row === 'number' ? `${key} ${params.row}` : key,
|
||||
}),
|
||||
}))
|
||||
vi.mock('@/layout/useLayout', () => ({
|
||||
useLayout: () => ({ layouts: { value: [{ id: 'side' }] } }),
|
||||
@ -14,7 +17,7 @@ async function mountDesigner(writer: boolean) {
|
||||
const { default: Designer } =
|
||||
await import('@/views/demo/layout-lab/LayoutDesigner')
|
||||
|
||||
return mount(Designer)
|
||||
return mount(Designer, { global: { stubs: { teleport: true } } })
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
@ -49,8 +52,17 @@ it('posts the edited visual design on the local development server and blocks du
|
||||
|
||||
return control
|
||||
}
|
||||
const selectRow = (value: string) =>
|
||||
wrapper.get('select[aria-label="position"]').setValue(value)
|
||||
const selectRow = async (label: string) => {
|
||||
const select = wrapper.getComponent({ name: 'Select' })
|
||||
|
||||
await select.get('.n-base-selection').trigger('click')
|
||||
const option = select
|
||||
.findAll('.n-base-select-option')
|
||||
.find((item) => item.text() === label)
|
||||
|
||||
expect.assert(option)
|
||||
await option.trigger('click')
|
||||
}
|
||||
|
||||
expect(wrapper.find('[data-tile]').exists()).toBe(false)
|
||||
expect(wrapper.find('.layout-designer__outlet').exists()).toBe(true)
|
||||
@ -63,8 +75,9 @@ it('posts the edited visual design on the local development server and blocks du
|
||||
.map((item) => item.text()),
|
||||
).toEqual(['tabs', 'actions'])
|
||||
await tile('actions').trigger('click')
|
||||
await selectRow('rows:0')
|
||||
await selectRow('topRow 1')
|
||||
await action('left').trigger('click')
|
||||
await selectRow('topRow 1')
|
||||
await action('rowDown').trigger('click')
|
||||
expect(
|
||||
wrapper
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import { useI18n } from '@/hooks/template/useI18n'
|
||||
import { layoutBlocks } from '@/layout/designer'
|
||||
import type { LayoutBlock, LayoutDesign } from '@/layout/designer'
|
||||
import { NButton } from 'naive-ui'
|
||||
import { NButton, NSelect } from 'naive-ui'
|
||||
import type { SelectGroupOption } from 'naive-ui'
|
||||
import type { PropType } from 'vue'
|
||||
import { useLayoutDraftPreview } from './useLayoutDraftPreview'
|
||||
|
||||
@ -44,6 +45,7 @@ export default defineComponent({
|
||||
const dropAfter = ref(false)
|
||||
const announcement = ref('')
|
||||
const editor = useTemplateRef<HTMLElement>('editor')
|
||||
const positionLabelId = useId()
|
||||
const rowsOf = (region: Region) => design[region] ?? []
|
||||
const positionOf = (brick: LayoutBlock) => {
|
||||
for (const region of regions) {
|
||||
@ -355,40 +357,49 @@ export default defineComponent({
|
||||
if (!pos) return
|
||||
|
||||
const rows = rowsOf(pos.region)
|
||||
const currentRow = `${pos.region}:${pos.row}`
|
||||
const options: SelectGroupOption[] = regions.map((region) => {
|
||||
const regionRows = rowsOf(region)
|
||||
|
||||
return {
|
||||
type: 'group',
|
||||
key: region,
|
||||
label: t(region === 'rows' ? 'aboveContent' : 'belowContent'),
|
||||
children: [
|
||||
...regionRows.map((_, index) => ({
|
||||
label: rowName(region, index),
|
||||
value: `${region}:${index}`,
|
||||
})),
|
||||
{
|
||||
label: t(region === 'rows' ? 'newTop' : 'newBottom'),
|
||||
value: `${region}:${regionRows.length}`,
|
||||
},
|
||||
],
|
||||
}
|
||||
})
|
||||
|
||||
return (
|
||||
<>
|
||||
<label>
|
||||
{t('position')}
|
||||
<select
|
||||
aria-label={t('position')}
|
||||
value={`${pos.region}:${pos.row}`}
|
||||
onChange={(event) => {
|
||||
const [region, index] = (
|
||||
event.currentTarget as HTMLSelectElement
|
||||
).value.split(':')
|
||||
<div
|
||||
class="layout-designer__placement"
|
||||
role="group"
|
||||
aria-labelledby={positionLabelId}
|
||||
>
|
||||
<span id={positionLabelId}>{t('position')}</span>
|
||||
<NSelect
|
||||
value={currentRow}
|
||||
options={options}
|
||||
virtualScroll={false}
|
||||
onUpdateValue={(value: string) => {
|
||||
if (value === currentRow) return
|
||||
|
||||
const [region, index] = value.split(':')
|
||||
|
||||
if (region === 'rows' || region === 'bottomRows')
|
||||
place(brick, region, Number(index))
|
||||
}}
|
||||
>
|
||||
{regions.map((region) => (
|
||||
<optgroup
|
||||
key={region}
|
||||
label={t(region === 'rows' ? 'aboveContent' : 'belowContent')}
|
||||
>
|
||||
{rowsOf(region).map((_, index) => (
|
||||
<option key={index} value={`${region}:${index}`}>
|
||||
{rowName(region, index)}
|
||||
</option>
|
||||
))}
|
||||
<option value={`${region}:${rowsOf(region).length}`}>
|
||||
{t(region === 'rows' ? 'newTop' : 'newBottom')}
|
||||
</option>
|
||||
</optgroup>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
/>
|
||||
</div>
|
||||
<div class="layout-designer__buttons">
|
||||
<NButton
|
||||
size="small"
|
||||
|
||||
@ -194,22 +194,11 @@
|
||||
margin-block-end: 12px;
|
||||
}
|
||||
&__fields label,
|
||||
&__inspector label {
|
||||
&__placement {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
color: var(--r-text-secondary);
|
||||
}
|
||||
&__inspector select {
|
||||
min-inline-size: 0;
|
||||
min-block-size: 36px;
|
||||
inline-size: 100%;
|
||||
padding-inline: 8px;
|
||||
border: 1px solid var(--r-control-border);
|
||||
border-radius: var(--r-control-radius);
|
||||
background: var(--r-surface);
|
||||
color: var(--r-text);
|
||||
font: inherit;
|
||||
}
|
||||
&__project {
|
||||
margin-block: 20px 12px;
|
||||
padding-block-start: 16px;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user