Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b0a6118e0 | ||
|
|
09ad43007a | ||
|
|
e789f8a1f7 | ||
|
|
d906603ce3 | ||
|
|
c49663e16e | ||
|
|
c44f2a159e | ||
|
|
35abfd831c | ||
|
|
3b0887b126 | ||
|
|
bba08dadcc | ||
|
|
701ed957ef | ||
|
|
0b75f8c6f2 | ||
|
|
417318921c | ||
|
|
f7ef29a928 | ||
|
|
f7ee862e0f | ||
|
|
8ac1427015 | ||
|
|
ebe5937fb6 | ||
|
|
de18412010 | ||
|
|
2b33bca681 | ||
|
|
ac57de97cb | ||
|
|
0b8f873a4c |
@@ -7,8 +7,7 @@ Shrimp 框架前端 —— 一种**经典解决方案**(不是框架本身),消
|
|||||||
## 安装
|
## 安装
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 推荐 HTTP
|
npm i git+http://git.zeromvc.com/wc24/shrimp-admin.git#v0.3.0
|
||||||
npm i git+http://git.zeromvc.com/wc24/shrimp-admin.git#v0.1.0
|
|
||||||
```
|
```
|
||||||
|
|
||||||
shrimp-admin 是**源码 ship**(.ts + .vue 直接发),由消费侧 Vite 编译。
|
shrimp-admin 是**源码 ship**(.ts + .vue 直接发),由消费侧 Vite 编译。
|
||||||
@@ -20,6 +19,8 @@ shrimp-admin 是**源码 ship**(.ts + .vue 直接发),由消费侧 Vite 编译
|
|||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import { createShrimpAdmin, App } from 'shrimp-admin'
|
import { createShrimpAdmin, App } from 'shrimp-admin'
|
||||||
import 'shrimp-admin/style'
|
import 'shrimp-admin/style'
|
||||||
|
import zhCn from './locales/zh-cn.json'
|
||||||
|
import en from './locales/en.json'
|
||||||
|
|
||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
app.use(createShrimpAdmin({
|
app.use(createShrimpAdmin({
|
||||||
@@ -27,22 +28,111 @@ app.use(createShrimpAdmin({
|
|||||||
API_URL: '/admin-api',
|
API_URL: '/admin-api',
|
||||||
TIMEOUT: 10000,
|
TIMEOUT: 10000,
|
||||||
},
|
},
|
||||||
moduleSources: import.meta.glob('./module/**/*.vue'),
|
locales: { 'zh-cn': zhCn, en },
|
||||||
customFields: import.meta.glob('./module/fields/Field*.vue'),
|
sources: import.meta.glob('./shrimp/**/*.vue'),
|
||||||
}))
|
}))
|
||||||
app.mount('#app')
|
app.mount('#app')
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 唯一约定: `sources` 路径后缀覆盖
|
||||||
|
|
||||||
|
消费侧把所有要交给框架的 .vue 通过单个 `sources` 入口注入(`import.meta.glob` 必须由消费侧自己调用,vite 静态扫描相对调用文件)。框架按**文件路径后缀**匹配,同后缀消费侧优先,内置兜底。
|
||||||
|
|
||||||
|
```
|
||||||
|
项目/
|
||||||
|
└── src/shrimp/ 消费侧目录,可任意命名
|
||||||
|
├── components/
|
||||||
|
│ ├── login.vue 覆盖框架内置 login 页
|
||||||
|
│ ├── layout.vue 覆盖整体布局壳
|
||||||
|
│ └── fields/
|
||||||
|
│ └── FieldRelativeTime.vue 注册字段类型 relativeTime
|
||||||
|
└── module/
|
||||||
|
├── product.vue 业务模块,routed by moduleKey
|
||||||
|
└── user/
|
||||||
|
└── orders.vue 子模块,parent=user
|
||||||
|
```
|
||||||
|
|
||||||
|
### 覆盖颗粒度只在 3 个入口
|
||||||
|
|
||||||
|
框架内 .vue 之间的 peer 引用是**硬编码静态 import**,override 颗粒度就停在下面这 3 类入口,不会一路传递下去:
|
||||||
|
|
||||||
|
| 入口 | 后缀 | 说明 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| **router targets** | `components/login.vue`、`components/layout.vue`、`components/404.vue` | vue-router 三个根级路由组件 |
|
||||||
|
| **module routes** | `module/<key>.vue`、`module/<parent>/<sub>.vue` | 走 `registerRoute` 的业务模块/子模块 |
|
||||||
|
| **field registry** | `components/fields/Field<X>.vue` | 字段类型注册表(文件名首字母小写 = type 键) |
|
||||||
|
|
||||||
|
想换更细的部件(比如 layout 里的 topbar)就在消费侧的 `layout.vue` 自己组装 — 框架不再代理任何 peer 切换。
|
||||||
|
|
||||||
|
### 字段类型注册
|
||||||
|
|
||||||
|
`components/fields/Field<X>.vue` 自动注册类型 `<x>`(首字母小写):
|
||||||
|
|
||||||
|
| 文件 | type 注册键 |
|
||||||
|
| -------------------------- | ---------------- |
|
||||||
|
| `FieldString.vue` | `string` |
|
||||||
|
| `FieldRelativeTime.vue` | `relativeTime` |
|
||||||
|
| 你自己的 `FieldMyType.vue` | `myType` |
|
||||||
|
|
||||||
|
后端 moduleInfo 里 `field.type === 'myType'` 时就用你这个组件。内置类型: `string` / `boolean` / `date` / `json` / `number` / `password` / `relation` / `select` / `tab` / `textarea` / `relativeTime`。
|
||||||
|
|
||||||
|
### 业务模块
|
||||||
|
|
||||||
|
`module/<key>.vue` 命中 `moduleKey === '<key>'` 的路由,自动作为内容页。子表用嵌套目录(`module/<parent>/<sub>.vue`)。
|
||||||
|
|
||||||
|
### 例子: 覆盖 login 页
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<!-- src/shrimp/components/login.vue -->
|
||||||
|
<template>
|
||||||
|
<div class="custom-login">
|
||||||
|
<h2>{{ vueAdmin.adminConfig.title || 'Admin' }}</h2>
|
||||||
|
<el-form :model="form" :rules="rules" @keyup.enter="login">
|
||||||
|
<el-form-item prop="user">
|
||||||
|
<el-input v-model="form.user" :placeholder="$t('login.userPlaceholder')" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item prop="password">
|
||||||
|
<el-input v-model="form.password" :placeholder="$t('login.PWPlaceholder')" show-password />
|
||||||
|
</el-form-item>
|
||||||
|
<el-button type="primary" :loading="info.islogin" @click="login">
|
||||||
|
{{ $t('login.signIn') }}
|
||||||
|
</el-button>
|
||||||
|
</el-form>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { reactive, computed } from 'vue'
|
||||||
|
import { useI18n } from 'vue-i18n'
|
||||||
|
import { vueAdmin } from 'shrimp-admin'
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const info = reactive({ islogin: false })
|
||||||
|
const form = reactive({ user: '', password: '' })
|
||||||
|
const rules = computed(() => ({
|
||||||
|
user: [{ required: true, message: t('login.userError'), trigger: 'blur' }],
|
||||||
|
password: [{ required: true, message: t('login.PWError'), trigger: 'blur' }],
|
||||||
|
}))
|
||||||
|
|
||||||
|
function login() {
|
||||||
|
info.islogin = true
|
||||||
|
vueAdmin.fetchLogin({ username: form.user, password: form.password })
|
||||||
|
.then(async (data: any) => {
|
||||||
|
vueAdmin.token = data.token
|
||||||
|
await vueAdmin.loadUserInfo()
|
||||||
|
vueAdmin.router.push(vueAdmin.getFirstMenuPath())
|
||||||
|
})
|
||||||
|
.catch((e: any) => console.warn('[Login]', e.message))
|
||||||
|
.finally(() => { info.islogin = false })
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
只要文件落在 `src/shrimp/components/login.vue`,被 `sources` 的 glob 扫到,框架的 `/login` 路由就会用你这份替换内置版本。
|
||||||
|
|
||||||
## 消费的契约
|
## 消费的契约
|
||||||
|
|
||||||
参见 shrimp-server README `## 约定` 章节。本包消费以下条件契约:
|
参见 shrimp-server README `## 约定` 章节。本包消费以下条件契约:
|
||||||
|
|
||||||
- **ShrimpTable**: list 响应 `{list,total,page,pageSize,totalPages}` / 字段 type 枚举 / populate `${key}_label`
|
- **ShrimpTable**: list 响应 `{list,total,page,pageSize,totalPages}` / 字段 type 枚举 / populate `${key}_label`
|
||||||
- **ShrimpServer**: HTTP 路由 / JWT Bearer / IUserAccessor 返回的 powers
|
- **ShrimpServer**: HTTP 路由 / JWT Bearer / IUserAccessor 返回的 powers
|
||||||
- **默认 Field*.vue**: 字段 type 必须是内置枚举之一,或通过 `customFields` 注册
|
|
||||||
|
|
||||||
## 扩展点
|
|
||||||
|
|
||||||
- `customFields` — 业务字段组件(`Field<Name>.vue`)
|
|
||||||
- `moduleSources` — 业务模块组件(`module/<key>.vue` / `module/<parent>/<sub>.vue`)
|
|
||||||
- `vueAdmin.registerField(type, comp)` / `overrideField(moduleKey, fieldKey, comp)` — 运行时也可
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "shrimp-admin",
|
"name": "shrimp-admin",
|
||||||
"version": "0.2.2",
|
"version": "0.7.8",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Shrimp 框架前端 — 消费 ShrimpServer + ShrimpTable 契约的经典 Vue3 + Element Plus 实现",
|
"description": "Shrimp 框架前端 — 消费 ShrimpServer + ShrimpTable 契约的经典 Vue3 + Element Plus 实现",
|
||||||
"main": "src/index.ts",
|
"main": "src/index.ts",
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed } from "vue";
|
import { computed } from "vue";
|
||||||
import { vueAdmin } from "../VueAdmin";
|
import { vueAdmin } from "./VueAdmin";
|
||||||
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
||||||
import en from 'element-plus/es/locale/lang/en'
|
import en from 'element-plus/es/locale/lang/en'
|
||||||
|
|
||||||
@@ -20,5 +20,5 @@ const locale = computed(() => {
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@use "../style/style.scss";
|
@use "./style/style.scss";
|
||||||
</style>
|
</style>
|
||||||
+69
-60
@@ -10,7 +10,6 @@ import { createI18n, I18n } from 'vue-i18n'
|
|||||||
import { IShrimpResponse, ILabel } from './IShrimpType'
|
import { IShrimpResponse, ILabel } from './IShrimpType'
|
||||||
|
|
||||||
import { ShrimpClient, handleShrimpResponse, type IShrimpTipper, type IRouteInfo } from './ShrimpClient'
|
import { ShrimpClient, handleShrimpResponse, type IShrimpTipper, type IRouteInfo } from './ShrimpClient'
|
||||||
import FieldString from './components/fields/FieldString.vue'
|
|
||||||
|
|
||||||
// ============== 工具 ==============
|
// ============== 工具 ==============
|
||||||
|
|
||||||
@@ -39,50 +38,65 @@ export interface ShrimpAdminConfig {
|
|||||||
LS_ENCRYPTION_key?: string
|
LS_ENCRYPTION_key?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type VueLoader = () => Promise<any>
|
||||||
|
|
||||||
export interface ShrimpAdminOptions {
|
export interface ShrimpAdminOptions {
|
||||||
config: ShrimpAdminConfig
|
config: ShrimpAdminConfig
|
||||||
/** 业务模块组件:`import.meta.glob('./module/**\/*.vue')` 的结果 */
|
/**
|
||||||
moduleSources?: Record<string, () => Promise<{ default: Component } | Component>>
|
* 消费侧 .vue 源,推荐 `import.meta.glob('./shrimp/**\/*.vue')`。
|
||||||
/** 业务字段组件:`import.meta.glob('./module/fields/Field*.vue')`,文件名 FieldXxx → type='fieldXxx' */
|
* - `shrimp/components/<name>.vue` 同后缀覆盖框架内置(login/layout/topbar/ShrimpTable/...)
|
||||||
customFields?: Record<string, () => Promise<{ default: Component } | Component>>
|
* - `shrimp/components/fields/Field<X>.vue` 注册字段类型 `<x>`(首字母小写),同名覆盖内置
|
||||||
|
* - `shrimp/module/<key>.vue` 业务模块组件(routed by moduleKey)
|
||||||
|
*/
|
||||||
|
sources?: Record<string, VueLoader>
|
||||||
/** 语言资源,与框架自带的合并(消费侧同 key 覆盖框架默认) */
|
/** 语言资源,与框架自带的合并(消费侧同 key 覆盖框架默认) */
|
||||||
locales?: Record<string, any>
|
locales?: Record<string, any>
|
||||||
/** 语言列表,默认 [{ lang: 'zh-cn', name: '简体中文' }] */
|
/** 语言列表,默认 [{ lang: 'zh-cn', name: '简体中文' }] */
|
||||||
langList?: { lang: string; name: string }[]
|
langList?: { lang: string; name: string }[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============== 源注册表 ==============
|
||||||
|
//
|
||||||
|
// 框架在 3 个入口点用消费侧 sources 覆盖内置(按路径后缀同后缀覆盖):
|
||||||
|
// 1. router: components/{layout,login,404}.vue
|
||||||
|
// 2. registerRoute: module/<key>.vue 等业务模块
|
||||||
|
// 3. fieldRegistry: components/fields/Field<X>.vue (按文件名导出的字段类型)
|
||||||
|
// 框架内 .vue 之间的 peer 引用是硬编码静态 import,override 颗粒度就停在上面这些"入口"。
|
||||||
|
|
||||||
|
const internalSources = import.meta.glob<Component>('./{components,module}/**/*.vue')
|
||||||
|
const externalSources: Record<string, VueLoader> = {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路径后缀匹配解析: 消费侧优先,内置兜底。
|
||||||
|
* suffix 形如 `components/login.vue` / `module/user.vue` / `module/user/operationLog.vue`。
|
||||||
|
*/
|
||||||
|
export function resolveVue(suffix: string): VueLoader {
|
||||||
|
const tail = '/' + suffix
|
||||||
|
for (const key in externalSources) {
|
||||||
|
if (key.endsWith(tail)) return externalSources[key]
|
||||||
|
}
|
||||||
|
for (const key in internalSources) {
|
||||||
|
if (key.endsWith(tail)) return internalSources[key] as any
|
||||||
|
}
|
||||||
|
throw new Error(`[shrimp-admin] resolveVue: ${suffix} not found in sources`)
|
||||||
|
}
|
||||||
|
|
||||||
// ============== 字段组件注册表 ==============
|
// ============== 字段组件注册表 ==============
|
||||||
|
//
|
||||||
|
// 约定:`components/fields/Field<X>.vue` → 字段类型 `<x>`(首字母小写)。
|
||||||
|
// 后端 moduleInfo 的 field.type 命中这里的 key 就用对应组件,否则回退到 string。
|
||||||
|
|
||||||
const fieldRegistry = new Map<string, Component>()
|
const fieldRegistry = new Map<string, Component>()
|
||||||
const fieldOverrides = new Map<string, string>()
|
|
||||||
|
|
||||||
fieldRegistry.set('string', FieldString)
|
function deriveFieldType(path: string): string | null {
|
||||||
fieldRegistry.set('boolean', defineAsyncComponent(() => import('./components/fields/FieldBoolean.vue')))
|
const m = path.match(/\/components\/fields\/Field([A-Z][A-Za-z0-9]*)\.vue$/)
|
||||||
fieldRegistry.set('date', defineAsyncComponent(() => import('./components/fields/FieldDate.vue')))
|
if (!m) return null
|
||||||
fieldRegistry.set('number', defineAsyncComponent(() => import('./components/fields/FieldNumber.vue')))
|
return m[1][0].toLowerCase() + m[1].slice(1)
|
||||||
fieldRegistry.set('password', defineAsyncComponent(() => import('./components/fields/FieldPassword.vue')))
|
|
||||||
fieldRegistry.set('relation', defineAsyncComponent(() => import('./components/fields/FieldRelation.vue')))
|
|
||||||
fieldRegistry.set('select', defineAsyncComponent(() => import('./components/fields/FieldSelect.vue')))
|
|
||||||
fieldRegistry.set('textarea', defineAsyncComponent(() => import('./components/fields/FieldTextarea.vue')))
|
|
||||||
fieldRegistry.set('json', defineAsyncComponent(() => import('./components/fields/FieldJson.vue')))
|
|
||||||
fieldRegistry.set('tab', defineAsyncComponent(() => import('./components/fields/FieldTab.vue')))
|
|
||||||
|
|
||||||
// 框架自带模块组件 — vite glob 相对本文件解析,扫到的是 shrimp-admin 内部的 module/
|
|
||||||
const internalModules = import.meta.glob<Component>('./module/**/*.vue')
|
|
||||||
|
|
||||||
// 业务模块由消费侧通过 createShrimpAdmin({ moduleSources }) 注册
|
|
||||||
const externalModules: Record<string, () => Promise<any>> = {}
|
|
||||||
|
|
||||||
function resolveModuleComponent(componentPath: string): (() => Promise<any>) | null {
|
|
||||||
const suffix = `/module/${componentPath}.vue`
|
|
||||||
// 业务优先(允许覆盖同名内置)
|
|
||||||
for (const key in externalModules) {
|
|
||||||
if (key.endsWith(suffix)) return externalModules[key]
|
|
||||||
}
|
}
|
||||||
for (const key in internalModules) {
|
|
||||||
if (key.endsWith(suffix)) return internalModules[key] as any
|
for (const path in internalSources) {
|
||||||
}
|
const type = deriveFieldType(path)
|
||||||
return null
|
if (type) fieldRegistry.set(type, defineAsyncComponent(internalSources[path] as any))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============== LocalData ==============
|
// ============== LocalData ==============
|
||||||
@@ -109,21 +123,17 @@ export class VueAdmin extends ShrimpClient {
|
|||||||
userName = ''
|
userName = ''
|
||||||
config: ShrimpAdminConfig
|
config: ShrimpAdminConfig
|
||||||
langList: { lang: string; name: string }[]
|
langList: { lang: string; name: string }[]
|
||||||
|
/** 已注册成功的模块路由(moduleKey → IRouteInfo),供 relation 跳转/单项查看解析路由 */
|
||||||
|
moduleRoutes = new Map<string, IRouteInfo>()
|
||||||
|
|
||||||
registerField(type: string, comp: Component) { fieldRegistry.set(type, comp) }
|
getFieldComponent(_moduleKey: string, type: string, _fieldKey?: string): Component {
|
||||||
|
return fieldRegistry.get(type) || fieldRegistry.get('string')!
|
||||||
overrideField(moduleKey: string, fieldKey: string, comp: Component) {
|
|
||||||
const registryKey = `__override_${moduleKey}_${fieldKey}`
|
|
||||||
fieldRegistry.set(registryKey, comp)
|
|
||||||
fieldOverrides.set(`${moduleKey}.${fieldKey}`, registryKey)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getFieldComponent(moduleKey: string, type: string, fieldKey?: string): Component {
|
/** 目标模块能否作为「单项查看」跳转目标:已按权限注册路由 且 非子模块。返回其路由信息或 undefined(不可跳) */
|
||||||
if (fieldKey) {
|
routeForModule(moduleKey: string): IRouteInfo | undefined {
|
||||||
const override = fieldOverrides.get(`${moduleKey}.${fieldKey}`)
|
if (this.moduleInfo.find(m => m.moduleKey === moduleKey)?.parent) return undefined
|
||||||
if (override && fieldRegistry.has(override)) return fieldRegistry.get(override)!
|
return this.moduleRoutes.get(moduleKey)
|
||||||
}
|
|
||||||
return fieldRegistry.get(type) || FieldString
|
|
||||||
}
|
}
|
||||||
|
|
||||||
state = reactive({ isMobile: false })
|
state = reactive({ isMobile: false })
|
||||||
@@ -161,15 +171,11 @@ export class VueAdmin extends ShrimpClient {
|
|||||||
this.config = opts.config
|
this.config = opts.config
|
||||||
this.langList = opts.langList || [{ lang: 'zh-cn', name: '简体中文' }]
|
this.langList = opts.langList || [{ lang: 'zh-cn', name: '简体中文' }]
|
||||||
|
|
||||||
// 业务模块/字段注册
|
if (opts.sources) {
|
||||||
if (opts.moduleSources) Object.assign(externalModules, opts.moduleSources)
|
Object.assign(externalSources, opts.sources)
|
||||||
if (opts.customFields) {
|
for (const path in opts.sources) {
|
||||||
for (const path in opts.customFields) {
|
const type = deriveFieldType(path)
|
||||||
const match = path.match(/\/Field(.+)\.vue$/)
|
if (type) fieldRegistry.set(type, defineAsyncComponent(opts.sources[path] as any))
|
||||||
if (match) {
|
|
||||||
const name = 'field' + match[1]
|
|
||||||
fieldRegistry.set(name, defineAsyncComponent(opts.customFields[path] as any))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,8 +250,10 @@ export class VueAdmin extends ShrimpClient {
|
|||||||
|
|
||||||
registerRoute(info: IRouteInfo) {
|
registerRoute(info: IRouteInfo) {
|
||||||
const componentPath = info.componentPath || info.moduleKey
|
const componentPath = info.componentPath || info.moduleKey
|
||||||
const importer = resolveModuleComponent(componentPath)
|
let importer: VueLoader
|
||||||
if (!importer) {
|
try {
|
||||||
|
importer = resolveVue(`module/${componentPath}.vue`)
|
||||||
|
} catch {
|
||||||
console.warn(`[shrimp-admin] module component not found: module/${componentPath}.vue`)
|
console.warn(`[shrimp-admin] module component not found: module/${componentPath}.vue`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -256,6 +264,7 @@ export class VueAdmin extends ShrimpClient {
|
|||||||
props: { moduleKey: info.moduleKey, events: info.events },
|
props: { moduleKey: info.moduleKey, events: info.events },
|
||||||
meta: { title: info.label }
|
meta: { title: info.label }
|
||||||
})
|
})
|
||||||
|
this.moduleRoutes.set(info.moduleKey, info)
|
||||||
}
|
}
|
||||||
|
|
||||||
initRouter() {
|
initRouter() {
|
||||||
@@ -265,17 +274,17 @@ export class VueAdmin extends ShrimpClient {
|
|||||||
{
|
{
|
||||||
name: "layout",
|
name: "layout",
|
||||||
path: "/",
|
path: "/",
|
||||||
component: () => import('./views/layout.vue'),
|
component: resolveVue('components/layout.vue'),
|
||||||
children: []
|
children: []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/login",
|
path: "/login",
|
||||||
component: () => import('./views/login.vue'),
|
component: resolveVue('components/login.vue'),
|
||||||
meta: { title: "t:login.signIn" }
|
meta: { title: { t: 'login.signIn' } }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/:pathMatch(.*)",
|
path: "/:pathMatch(.*)",
|
||||||
component: () => import('./views/404.vue'),
|
component: resolveVue('components/404.vue'),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
@@ -343,7 +352,7 @@ export class VueAdmin extends ShrimpClient {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
ElMessage.error(this.t('t:base.netError'))
|
ElMessage.error(this.t({ t: 'base.netError' }))
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ function buildRules(field: IFieldConfig): FormItemRule[] {
|
|||||||
if (field.required) {
|
if (field.required) {
|
||||||
rules.push({
|
rules.push({
|
||||||
required: true,
|
required: true,
|
||||||
message: vueAdmin.t('shrimp.fieldRequired'),
|
message: vueAdmin.t({ t: 'shrimp.fieldRequired', params: { field: field.label } }),
|
||||||
trigger: 'change',
|
trigger: 'change',
|
||||||
...(field.type === 'string' || field.type === 'textarea' || field.type === 'password' ? { trigger: 'blur' } : {}),
|
...(field.type === 'string' || field.type === 'textarea' || field.type === 'password' ? { trigger: 'blur' } : {}),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -4,11 +4,18 @@
|
|||||||
<el-form :model="localFilterData">
|
<el-form :model="localFilterData">
|
||||||
<template v-for="field in filterableFields" :key="field.key">
|
<template v-for="field in filterableFields" :key="field.key">
|
||||||
<el-form-item :label="vueAdmin.t(field.label)">
|
<el-form-item :label="vueAdmin.t(field.label)">
|
||||||
|
<div class="filter-field-row">
|
||||||
|
<div class="filter-field-control">
|
||||||
<slot :name="`filter-${field.key}`" :field="field" :data="localFilterData">
|
<slot :name="`filter-${field.key}`" :field="field" :data="localFilterData">
|
||||||
<component :is="vueAdmin.getFieldComponent(moduleKey, field.type, field.key)" :field="field"
|
<component :is="vueAdmin.getFieldComponent(moduleKey, field.type, field.key)"
|
||||||
:model-value="localFilterData[field.key]"
|
:field="field" :model-value="localFilterData[field.key]"
|
||||||
@update:model-value="onFieldChange(field.key, $event)" mode="filter" />
|
@update:model-value="onFieldChange(field.key, $event)" mode="filter" />
|
||||||
</slot>
|
</slot>
|
||||||
|
</div>
|
||||||
|
<!-- 单独清空该字段:仅在有值时出现,点了只删这一个 key -->
|
||||||
|
<el-button v-if="hasValue(field.key)" link :icon="CircleClose" class="filter-clear"
|
||||||
|
@click="clearField(field.key)" />
|
||||||
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</template>
|
</template>
|
||||||
</el-form>
|
</el-form>
|
||||||
@@ -21,6 +28,7 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref, watch } from 'vue'
|
import { ref, watch } from 'vue'
|
||||||
|
import { CircleClose } from '@element-plus/icons-vue'
|
||||||
import { IFieldConfig } from '../IShrimpType'
|
import { IFieldConfig } from '../IShrimpType'
|
||||||
import { vueAdmin } from '../VueAdmin'
|
import { vueAdmin } from '../VueAdmin'
|
||||||
|
|
||||||
@@ -68,6 +76,21 @@ function onFieldChange(key: string, value: any) {
|
|||||||
localFilterData.value = { ...localFilterData.value, [key]: value }
|
localFilterData.value = { ...localFilterData.value, [key]: value }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 该字段当前是否有筛选值(决定单独清空按钮是否出现);范围 {gte,lte}/数组按内容判空
|
||||||
|
function hasValue(key: string): boolean {
|
||||||
|
const v = localFilterData.value[key]
|
||||||
|
if (v == null || v === '') return false
|
||||||
|
if (Array.isArray(v)) return v.length > 0
|
||||||
|
if (typeof v === 'object') return Object.keys(v).length > 0
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 单独清空某个字段:只摘掉这一个 key,其余筛选条件不动
|
||||||
|
function clearField(key: string) {
|
||||||
|
const { [key]: _, ...rest } = localFilterData.value
|
||||||
|
localFilterData.value = rest
|
||||||
|
}
|
||||||
|
|
||||||
function handleReset() {
|
function handleReset() {
|
||||||
closedByReset.value = true
|
closedByReset.value = true
|
||||||
localFilterData.value = {}
|
localFilterData.value = {}
|
||||||
@@ -101,4 +124,23 @@ function handleConfirm() {
|
|||||||
.shrimp-drawer .el-drawer__body .el-form-item {
|
.shrimp-drawer .el-drawer__body .el-form-item {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.filter-field-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-field-control {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-clear {
|
||||||
|
flex: none;
|
||||||
|
padding: 0;
|
||||||
|
font-size: 16px;
|
||||||
|
color: var(--el-text-color-secondary);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
<slot :name="`column-${field.key}`" :row="row" :field="field">
|
<slot :name="`column-${field.key}`" :row="row" :field="field">
|
||||||
<component :is="vueAdmin.getFieldComponent(moduleKey, field.type, field.key)" :field="field"
|
<component :is="vueAdmin.getFieldComponent(moduleKey, field.type, field.key)" :field="field"
|
||||||
:model-value="row[field.key]" mode="display"
|
:model-value="row[field.key]" mode="display"
|
||||||
v-bind="field.type === 'relation' || field.type === 'textarea' ? { displayLabel: row[field.key + '_label'] } : {}" />
|
v-bind="field.type === 'textarea' ? { displayLabel: row[field.key + '_label'] } : {}" />
|
||||||
</slot>
|
</slot>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
@@ -78,7 +78,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref, computed, useSlots, onMounted, type Component } from 'vue'
|
import { ref, computed, useSlots, onMounted, provide, type Component } from 'vue'
|
||||||
import { ITableCrudProto, IFieldConfig, IModuleInfo, IPageQuery } from '../IShrimpType'
|
import { ITableCrudProto, IFieldConfig, IModuleInfo, IPageQuery } from '../IShrimpType'
|
||||||
import { vueAdmin } from '../VueAdmin'
|
import { vueAdmin } from '../VueAdmin'
|
||||||
import { Plus, Delete as DeleteIcon, Download, Upload, Edit, VideoPlay, VideoPause, Operation } from '@element-plus/icons-vue'
|
import { Plus, Delete as DeleteIcon, Download, Upload, Edit, VideoPlay, VideoPause, Operation } from '@element-plus/icons-vue'
|
||||||
@@ -132,8 +132,18 @@ const {
|
|||||||
|
|
||||||
const searchVisible = ref(false)
|
const searchVisible = ref(false)
|
||||||
|
|
||||||
|
// relation 跳转用 ?filter={_id} 锁定单条;_id 是隐形 pin(不在筛选抽屉里),
|
||||||
|
// 用户一旦搜索/改筛选就清掉它,避免被看不见的 _id 一直 AND 着导致结果莫名为空
|
||||||
|
function stripJumpPin() {
|
||||||
|
if ('_id' in filterData.value) {
|
||||||
|
const { _id, ...rest } = filterData.value
|
||||||
|
filterData.value = rest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function onSearch() {
|
function onSearch() {
|
||||||
searchKeyword.value = keyword.value
|
searchKeyword.value = keyword.value
|
||||||
|
stripJumpPin()
|
||||||
currentPage.value = 1
|
currentPage.value = 1
|
||||||
refresh()
|
refresh()
|
||||||
}
|
}
|
||||||
@@ -151,7 +161,8 @@ const hasFilter = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
async function handleFilterConfirm(newFilterData: Record<string, any>) {
|
async function handleFilterConfirm(newFilterData: Record<string, any>) {
|
||||||
filterData.value = newFilterData
|
const { _id, ...rest } = newFilterData // 确认筛选 → 丢弃跳转 pin
|
||||||
|
filterData.value = rest
|
||||||
currentPage.value = 1
|
currentPage.value = 1
|
||||||
await refresh()
|
await refresh()
|
||||||
}
|
}
|
||||||
@@ -201,9 +212,24 @@ const formFields = computed(() => {
|
|||||||
return list.filter(f => f.editable !== 'readonly')
|
return list.filter(f => f.editable !== 'readonly')
|
||||||
})
|
})
|
||||||
const searchableFields = computed(() => fields.value.filter(f => f.searchable))
|
const searchableFields = computed(() => fields.value.filter(f => f.searchable))
|
||||||
|
// 递归收集 filterable 字段(含 object/tab 嵌套叶子),生成 key=点路径的"合成字段"。
|
||||||
|
// 这样筛选抽屉/buildFilter/URL 同步全按 field.key 走即可——key 就是 condition.level 这种路径。
|
||||||
|
function collectFilterablePaths(list: IFieldConfig[], base: string[], out: any[]) {
|
||||||
|
for (const f of list) {
|
||||||
|
const path = [...base, f.key]
|
||||||
|
if (f.filterable) out.push({ ...f, key: path.join('.') })
|
||||||
|
if (f.type === 'tab' && Array.isArray((f as any).tabs)) {
|
||||||
|
for (const t of (f as any).tabs) collectFilterablePaths(t.fields, path, out)
|
||||||
|
} else if (f.type === 'object' && Array.isArray((f as any).fields)) {
|
||||||
|
collectFilterablePaths((f as any).fields, path, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
const filterableFields = computed(() => {
|
const filterableFields = computed(() => {
|
||||||
const lockedKeys = new Set(Object.keys(props.baseFilter || {}))
|
const lockedKeys = new Set(Object.keys(props.baseFilter || {}))
|
||||||
return fields.value.filter(f => f.filterable && !lockedKeys.has(f.key))
|
const out: any[] = []
|
||||||
|
collectFilterablePaths(fields.value, [], out)
|
||||||
|
return out.filter(f => !lockedKeys.has(f.key))
|
||||||
})
|
})
|
||||||
|
|
||||||
const formSlotNames = computed(() => Object.keys(slots).filter(name => name.startsWith('form-')))
|
const formSlotNames = computed(() => Object.keys(slots).filter(name => name.startsWith('form-')))
|
||||||
@@ -214,6 +240,9 @@ const filterSlotNames = computed(() => Object.keys(slots).filter(name => name.st
|
|||||||
const data = ref<any[]>([])
|
const data = ref<any[]>([])
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const total = ref(0)
|
const total = ref(0)
|
||||||
|
// relation 显示名字典 { moduleKey: { id: 名 } },由 list 响应带回,provide 给表格里的字段组件查名
|
||||||
|
const refs = ref<Record<string, Record<string, any>>>({})
|
||||||
|
provide('shrimpRefs', refs)
|
||||||
|
|
||||||
// ---- 对话框状态 ----
|
// ---- 对话框状态 ----
|
||||||
|
|
||||||
@@ -293,8 +322,10 @@ async function handleAdd() {
|
|||||||
formData.value[field.key] = false
|
formData.value[field.key] = false
|
||||||
} else if (field.type === 'number') {
|
} else if (field.type === 'number') {
|
||||||
formData.value[field.key] = 0
|
formData.value[field.key] = 0
|
||||||
} else if (field.multiple) {
|
} else if (field.type === 'array' || field.multiple) {
|
||||||
formData.value[field.key] = []
|
formData.value[field.key] = []
|
||||||
|
} else if (field.type === 'object') {
|
||||||
|
formData.value[field.key] = {}
|
||||||
} else {
|
} else {
|
||||||
formData.value[field.key] = ''
|
formData.value[field.key] = ''
|
||||||
}
|
}
|
||||||
@@ -320,8 +351,10 @@ async function handleSave() {
|
|||||||
formFields.value.forEach(field => {
|
formFields.value.forEach(field => {
|
||||||
if (field.editable === 'readonly') return
|
if (field.editable === 'readonly') return
|
||||||
if (field.editable === 'addOnly') return
|
if (field.editable === 'addOnly') return
|
||||||
const newValue = formData.value[field.key]
|
// 清空字段值为 undefined 时,JSON.stringify 会丢键 → 后端收不到、看似"提交无效"。
|
||||||
const oldValue = originalData.value[field.key]
|
// 归一成 null:既保证清空能提交(后端置空),又让"两边都空"不误判为有改动。
|
||||||
|
const newValue = formData.value[field.key] ?? null
|
||||||
|
const oldValue = originalData.value[field.key] ?? null
|
||||||
if (newValue === oldValue) return
|
if (newValue === oldValue) return
|
||||||
submitData[field.key] = newValue
|
submitData[field.key] = newValue
|
||||||
})
|
})
|
||||||
@@ -426,7 +459,16 @@ async function handleExport() {
|
|||||||
}
|
}
|
||||||
if (ownerId.value) query.ownerId = ownerId.value
|
if (ownerId.value) query.ownerId = ownerId.value
|
||||||
const list = await api.export(query)
|
const list = await api.export(query)
|
||||||
const ws = XLSX.utils.json_to_sheet(list)
|
// 后端只发原始对象;xlsx 单元格放不下对象/数组(会变 [object Object]),这里通用地 JSON 序列化
|
||||||
|
// (覆盖 tab 等结构化字段)。import 时这些字符串由后端各类型 reqFilter 还原。
|
||||||
|
const rows = list.map((row: Record<string, any>) => {
|
||||||
|
const out: Record<string, any> = {}
|
||||||
|
for (const [k, v] of Object.entries(row)) {
|
||||||
|
out[k] = (v !== null && typeof v === 'object') ? JSON.stringify(v) : v
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
})
|
||||||
|
const ws = XLSX.utils.json_to_sheet(rows)
|
||||||
const wb = XLSX.utils.book_new()
|
const wb = XLSX.utils.book_new()
|
||||||
XLSX.utils.book_append_sheet(wb, ws, props.moduleKey)
|
XLSX.utils.book_append_sheet(wb, ws, props.moduleKey)
|
||||||
XLSX.writeFile(wb, `${props.moduleKey}_export_${Date.now()}.xlsx`)
|
XLSX.writeFile(wb, `${props.moduleKey}_export_${Date.now()}.xlsx`)
|
||||||
@@ -501,6 +543,7 @@ async function refresh(query?: Record<string, any>) {
|
|||||||
Object.assign(pageQuery, query)
|
Object.assign(pageQuery, query)
|
||||||
const res = await api.list(pageQuery)
|
const res = await api.list(pageQuery)
|
||||||
data.value = res.list || []
|
data.value = res.list || []
|
||||||
|
refs.value = res.refs || {}
|
||||||
total.value = res.total
|
total.value = res.total
|
||||||
currentPage.value = res.page
|
currentPage.value = res.page
|
||||||
currentPageSize.value = res.pageSize
|
currentPageSize.value = res.pageSize
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
<template>
|
||||||
|
<!-- 显示:逐元素递归渲染 item 的 display 组件 -->
|
||||||
|
<template v-if="mode === 'display'">
|
||||||
|
<span v-if="!items.length">-</span>
|
||||||
|
<span v-else class="arr-display">
|
||||||
|
<span v-for="(el, i) in items" :key="i" class="arr-chip">
|
||||||
|
<component :is="vueAdmin.getFieldComponent(moduleKey, field.item.type, '')"
|
||||||
|
:field="field.item" :model-value="el" mode="display" />
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<!-- 编辑:每项一行(标题 + item 编辑组件 + 删除),底部添加。第一版从简:无排序拖拽 -->
|
||||||
|
<div v-else class="field-array">
|
||||||
|
<div v-for="(el, i) in items" :key="i" class="arr-row">
|
||||||
|
<div class="arr-head">
|
||||||
|
<span class="arr-idx">{{ itemTitle }} #{{ i + 1 }}</span>
|
||||||
|
<el-button type="danger" text size="small" @click="removeAt(i)">删除</el-button>
|
||||||
|
</div>
|
||||||
|
<component :is="vueAdmin.getFieldComponent(moduleKey, field.item.type, '')"
|
||||||
|
:field="field.item" :model-value="el"
|
||||||
|
@update:model-value="setAt(i, $event)" mode="edit" :disabled="disabled" />
|
||||||
|
</div>
|
||||||
|
<el-button type="primary" text @click="addOne" :disabled="disabled">+ 添加{{ itemTitle }}</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { computed, inject } from 'vue'
|
||||||
|
import { vueAdmin } from '../../VueAdmin'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
field: any
|
||||||
|
modelValue: any
|
||||||
|
mode: 'display' | 'edit' | 'filter'
|
||||||
|
disabled?: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{ 'update:modelValue': [value: any] }>()
|
||||||
|
|
||||||
|
const moduleKey = inject('shrimpModuleKey', '')
|
||||||
|
|
||||||
|
const items = computed<any[]>(() => Array.isArray(props.modelValue) ? props.modelValue : [])
|
||||||
|
const itemTitle = computed(() => vueAdmin.t(props.field.item?.label) || '项')
|
||||||
|
|
||||||
|
function setAt(i: number, value: any) {
|
||||||
|
const arr = items.value.slice()
|
||||||
|
arr[i] = value
|
||||||
|
emit('update:modelValue', arr)
|
||||||
|
}
|
||||||
|
function removeAt(i: number) {
|
||||||
|
const arr = items.value.slice()
|
||||||
|
arr.splice(i, 1)
|
||||||
|
emit('update:modelValue', arr)
|
||||||
|
}
|
||||||
|
function addOne() {
|
||||||
|
emit('update:modelValue', [...items.value, defaultOf(props.field.item)])
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 按 item schema 递归生成一个默认元素 */
|
||||||
|
function defaultOf(schema: any): any {
|
||||||
|
if (!schema) return null
|
||||||
|
if (schema.defaultValue !== undefined) return schema.defaultValue
|
||||||
|
if (schema.type === 'object') {
|
||||||
|
const obj: any = {}
|
||||||
|
for (const f of schema.fields || []) obj[f.key] = defaultOf(f)
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
if (schema.type === 'array') return []
|
||||||
|
if (schema.type === 'number') return 0
|
||||||
|
if (schema.type === 'boolean') return false
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.arr-display {
|
||||||
|
display: inline-flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-array {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arr-row {
|
||||||
|
padding: 8px 10px;
|
||||||
|
border: 1px solid var(--el-border-color-lighter);
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arr-head {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arr-idx {
|
||||||
|
color: var(--el-text-color-secondary);
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
/>
|
/>
|
||||||
<el-date-picker v-else :model-value="modelValue" @update:model-value="$emit('update:modelValue', $event)" :disabled="disabled"
|
<el-date-picker v-else :model-value="modelValue" @update:model-value="$emit('update:modelValue', $event)" :disabled="disabled"
|
||||||
type="datetime" style="width: 100%" />
|
type="datetime" :clearable="!field.required" style="width: 100%" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
<template>
|
|
||||||
<template v-if="mode === 'display'">
|
|
||||||
<el-tooltip v-if="modelValue != null" :content="displayValue" placement="top">
|
|
||||||
<span class="json-display">{{ displayValue }}</span>
|
|
||||||
</el-tooltip>
|
|
||||||
<span v-else>-</span>
|
|
||||||
</template>
|
|
||||||
<el-input
|
|
||||||
v-else
|
|
||||||
:model-value="modelValue"
|
|
||||||
@update:model-value="$emit('update:modelValue', $event)"
|
|
||||||
type="textarea"
|
|
||||||
:rows="4"
|
|
||||||
:disabled="disabled"
|
|
||||||
placeholder="请输入 JSON"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import { computed } from 'vue'
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
field: any
|
|
||||||
modelValue: any
|
|
||||||
mode: 'display' | 'edit' | 'filter'
|
|
||||||
disabled?: boolean
|
|
||||||
}>()
|
|
||||||
|
|
||||||
defineEmits<{
|
|
||||||
'update:modelValue': [value: any]
|
|
||||||
}>()
|
|
||||||
|
|
||||||
const displayValue = computed(() => {
|
|
||||||
if (props.modelValue == null) return ''
|
|
||||||
if (typeof props.modelValue === 'string') return props.modelValue
|
|
||||||
return JSON.stringify(props.modelValue, null, 2)
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.json-display {
|
|
||||||
display: inline-block;
|
|
||||||
max-width: 200px;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
<template>
|
||||||
|
<!-- 显示:递归渲染各子字段的 display 组件(relation 子查 refs) -->
|
||||||
|
<template v-if="mode === 'display'">
|
||||||
|
<span v-if="!modelValue || typeof modelValue !== 'object'">-</span>
|
||||||
|
<span v-else class="obj-display">
|
||||||
|
<span v-for="f in field.fields || []" :key="f.key" class="obj-child">
|
||||||
|
<span class="obj-label">{{ vueAdmin.t(f.label) }}:</span>
|
||||||
|
<component :is="vueAdmin.getFieldComponent(moduleKey, f.type, f.key)"
|
||||||
|
:field="f" :model-value="(modelValue || {})[f.key]" mode="display" />
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<!-- 编辑:每个子字段一行,递归渲染 edit 组件 -->
|
||||||
|
<div v-else class="field-object">
|
||||||
|
<el-form-item v-for="f in field.fields || []" :key="f.key" :label="vueAdmin.t(f.label)" :required="f.required">
|
||||||
|
<component :is="vueAdmin.getFieldComponent(moduleKey, f.type, f.key)"
|
||||||
|
:field="f" :model-value="(modelValue || {})[f.key]"
|
||||||
|
@update:model-value="onChild(f.key, $event)" mode="edit" :disabled="disabled" />
|
||||||
|
</el-form-item>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { inject } from 'vue'
|
||||||
|
import { vueAdmin } from '../../VueAdmin'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
field: any
|
||||||
|
modelValue: any
|
||||||
|
mode: 'display' | 'edit' | 'filter'
|
||||||
|
disabled?: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{ 'update:modelValue': [value: any] }>()
|
||||||
|
|
||||||
|
const moduleKey = inject('shrimpModuleKey', '')
|
||||||
|
|
||||||
|
function onChild(key: string, value: any) {
|
||||||
|
emit('update:modelValue', { ...(props.modelValue || {}), [key]: value })
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.obj-display {
|
||||||
|
display: inline-flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.obj-child {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.obj-label {
|
||||||
|
color: var(--el-text-color-secondary);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-object {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
padding-left: 12px;
|
||||||
|
border-left: 2px solid var(--el-border-color-lighter);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,7 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<template v-if="mode === 'display'">
|
<template v-if="mode === 'display'">
|
||||||
<template v-if="field.multiple && Array.isArray(displayLabel)">{{ displayLabel.filter(Boolean).join(', ') || '-' }}</template>
|
<template v-if="field.multiple">
|
||||||
<template v-else>{{ displayLabel || modelValue || '-' }}</template>
|
<span v-if="!displayItems.length">-</span>
|
||||||
|
<template v-for="(it, i) in displayItems" :key="i"><a v-if="jumpable" class="rel-link" @click.stop="goto(it.id)">{{ it.name }}</a><span v-else>{{ it.name }}</span><span v-if="i < displayItems.length - 1">、</span></template>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<a v-if="jumpable && modelValue != null" class="rel-link" @click.stop="goto(modelValue)">{{ displayName }}</a>
|
||||||
|
<span v-else>{{ displayName || '-' }}</span>
|
||||||
|
</template>
|
||||||
</template>
|
</template>
|
||||||
<el-select
|
<el-select
|
||||||
v-else-if="mode === 'filter'"
|
v-else-if="mode === 'filter'"
|
||||||
@@ -12,13 +18,13 @@
|
|||||||
>
|
>
|
||||||
<el-option v-for="opt in options" :key="opt.value" :label="opt.label" :value="opt.value" />
|
<el-option v-for="opt in options" :key="opt.value" :label="opt.label" :value="opt.value" />
|
||||||
</el-select>
|
</el-select>
|
||||||
<el-select v-else :model-value="stringValue" @update:model-value="$emit('update:modelValue', $event)" :disabled="disabled" :multiple="field.multiple" filterable remote :remote-method="onSearch" :loading="loading" style="width: 100%">
|
<el-select v-else :model-value="stringValue" @update:model-value="onEdit" :disabled="disabled" :multiple="field.multiple" :clearable="!field.required" filterable remote :remote-method="onSearch" :loading="loading" style="width: 100%">
|
||||||
<el-option v-for="opt in options" :key="opt.value" :label="opt.label" :value="opt.value" />
|
<el-option v-for="opt in options" :key="opt.value" :label="opt.label" :value="opt.value" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref, onMounted, computed } from 'vue'
|
import { ref, inject, onMounted, computed, type Ref } from 'vue'
|
||||||
import { vueAdmin } from '../../VueAdmin'
|
import { vueAdmin } from '../../VueAdmin'
|
||||||
import { ITableCrudProto } from '../../IShrimpType'
|
import { ITableCrudProto } from '../../IShrimpType'
|
||||||
|
|
||||||
@@ -27,16 +33,45 @@ const props = defineProps<{
|
|||||||
modelValue: any
|
modelValue: any
|
||||||
mode: 'display' | 'edit' | 'filter'
|
mode: 'display' | 'edit' | 'filter'
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
displayLabel?: string | string[]
|
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
defineEmits<{
|
const emit = defineEmits<{
|
||||||
'update:modelValue': [value: any]
|
'update:modelValue': [value: any]
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
// 编辑态清空:el-select 单选清空发 '' 或 undefined,relation 是 ObjectId、且 undefined 会被
|
||||||
|
// JSON.stringify 丢键 → 都归一成 null(取消关联)。多选清空是 [],原样。
|
||||||
|
function onEdit(v: any) {
|
||||||
|
emit('update:modelValue', v === '' || v == null ? (props.field.multiple ? [] : null) : v)
|
||||||
|
}
|
||||||
|
|
||||||
const options = ref<{ label: string; value: string }[]>([])
|
const options = ref<{ label: string; value: string }[]>([])
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
|
// 显示用:从 ShrimpTable provide 的 refs 字典按 id 查名(替代旧的 _label)
|
||||||
|
const refs = inject<Ref<Record<string, Record<string, any>>>>('shrimpRefs', ref<Record<string, Record<string, any>>>({}))
|
||||||
|
const dict = computed(() => refs.value?.[props.field.relation?.moduleKey] ?? {})
|
||||||
|
const displayName = computed(() => {
|
||||||
|
const id = props.modelValue
|
||||||
|
if (id == null) return ''
|
||||||
|
return dict.value[String(id)] ?? String(id)
|
||||||
|
})
|
||||||
|
const displayItems = computed(() =>
|
||||||
|
(Array.isArray(props.modelValue) ? props.modelValue : [])
|
||||||
|
.filter((id: any) => id != null)
|
||||||
|
.map((id: any) => ({ id, name: dict.value[String(id)] ?? String(id) }))
|
||||||
|
)
|
||||||
|
|
||||||
|
// 单项查看跳转:目标模块可达(已注册路由)且非子模块时,名字可点 → 跳目标模块并过滤到该 _id(单行)
|
||||||
|
const jumpable = computed(() =>
|
||||||
|
props.mode === 'display' && !!props.field.relation && !!vueAdmin.routeForModule(props.field.relation.moduleKey)
|
||||||
|
)
|
||||||
|
function goto(id: any) {
|
||||||
|
const r = props.field.relation && vueAdmin.routeForModule(props.field.relation.moduleKey)
|
||||||
|
if (!r || id == null) return
|
||||||
|
vueAdmin.router.push({ name: r.name, query: { filter: JSON.stringify({ _id: String(id) }) } })
|
||||||
|
}
|
||||||
|
|
||||||
/** 统一转为字符串值,解决 ObjectId 与 el-select 的匹配问题 */
|
/** 统一转为字符串值,解决 ObjectId 与 el-select 的匹配问题 */
|
||||||
const stringValue = computed(() => {
|
const stringValue = computed(() => {
|
||||||
// filter 模式强制 multiple,始终返回数组
|
// filter 模式强制 multiple,始终返回数组
|
||||||
@@ -92,3 +127,13 @@ onMounted(async () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.rel-link {
|
||||||
|
color: var(--el-color-primary);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.rel-link:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { vueAdmin } from '../VueAdmin'
|
import { vueAdmin } from '../../VueAdmin'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
@update:model-value="$emit('update:modelValue', $event)"
|
@update:model-value="$emit('update:modelValue', $event)"
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
:multiple="field.multiple"
|
:multiple="field.multiple"
|
||||||
|
:clearable="!field.required"
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
>
|
>
|
||||||
<el-option v-for="opt in resolvedOptions" :key="opt.value" :label="vueAdmin.t(opt.label)" :value="opt.value" />
|
<el-option v-for="opt in resolvedOptions" :key="opt.value" :label="vueAdmin.t(opt.label)" :value="opt.value" />
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
</el-tag>
|
</el-tag>
|
||||||
<el-input v-model="inputValue" @keyup.enter="addTag" @blur="addTag" :placeholder="$t('base.pressEnter')" />
|
<el-input v-model="inputValue" @keyup.enter="addTag" @blur="addTag" :placeholder="$t('base.pressEnter')" />
|
||||||
</div>
|
</div>
|
||||||
<el-input v-else :model-value="modelValue" @update:model-value="$emit('update:modelValue', $event)" :disabled="disabled" clearable />
|
<el-input v-else :model-value="modelValue" @update:model-value="$emit('update:modelValue', $event)" :disabled="disabled" :clearable="!field.required" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
|||||||
@@ -1,13 +1,21 @@
|
|||||||
<template>
|
<template>
|
||||||
<template v-if="mode === 'display'">
|
<template v-if="mode === 'display'">
|
||||||
<span v-if="!modelValue || typeof modelValue !== 'object'">-</span>
|
<!-- 显示=前端递归渲染:分支标签 + 选中分支子字段。没选 type(清空) → 显示 - -->
|
||||||
<el-tooltip v-else :content="JSON.stringify(modelValue, null, 2)" placement="top">
|
<span v-if="!modelValue || typeof modelValue !== 'object' || modelValue.type == null">-</span>
|
||||||
<span class="tab-display">{{ displayText }}</span>
|
<span v-else class="tab-display">
|
||||||
</el-tooltip>
|
<span class="tab-branch">{{ branchLabel }}</span>
|
||||||
|
<span v-for="childField in selectedTab?.fields || []" :key="childField.key" class="tab-child">
|
||||||
|
<span class="tab-child-label">{{ vueAdmin.t(childField.label) }}:</span>
|
||||||
|
<component :is="vueAdmin.getFieldComponent(moduleKey, childField.type, childField.key)"
|
||||||
|
:field="childField" :model-value="(modelValue || {})[childField.key]" mode="display" />
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
</template>
|
</template>
|
||||||
<div v-else class="field-tab">
|
<div v-else class="field-tab">
|
||||||
<el-form-item :label="vueAdmin.t(field.label) + ' - 类型'" :required="field.required">
|
<el-form-item :label="vueAdmin.t(field.label) + ' - 类型'" :required="field.required">
|
||||||
<el-select :model-value="innerValue.type" @update:model-value="onTypeChange" :disabled="disabled">
|
<!-- 非必填可清空 → 清空后 type=null、整个 tab 置空、下面分支消失 -->
|
||||||
|
<el-select :model-value="modelValue?.type ?? undefined" @update:model-value="onTypeChange"
|
||||||
|
:clearable="!field.required" :disabled="disabled">
|
||||||
<el-option v-for="tab in field.tabs" :key="tab.key" :label="vueAdmin.t(tab.label)" :value="tab.key" />
|
<el-option v-for="tab in field.tabs" :key="tab.key" :label="vueAdmin.t(tab.label)" :value="tab.key" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@@ -16,7 +24,7 @@
|
|||||||
<el-form-item :label="vueAdmin.t(childField.label)" :required="childField.required">
|
<el-form-item :label="vueAdmin.t(childField.label)" :required="childField.required">
|
||||||
<component :is="vueAdmin.getFieldComponent(moduleKey, childField.type, childField.key)"
|
<component :is="vueAdmin.getFieldComponent(moduleKey, childField.type, childField.key)"
|
||||||
:field="childField"
|
:field="childField"
|
||||||
:model-value="innerValue[childField.key]"
|
:model-value="(modelValue || {})[childField.key]"
|
||||||
@update:model-value="onChildChange(childField.key, $event)"
|
@update:model-value="onChildChange(childField.key, $event)"
|
||||||
mode="edit"
|
mode="edit"
|
||||||
:disabled="disabled" />
|
:disabled="disabled" />
|
||||||
@@ -27,7 +35,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, inject, onMounted } from 'vue'
|
import { computed, inject } from 'vue'
|
||||||
import { vueAdmin } from '../../VueAdmin'
|
import { vueAdmin } from '../../VueAdmin'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
@@ -43,39 +51,18 @@ const emit = defineEmits<{
|
|||||||
|
|
||||||
const moduleKey = inject('shrimpModuleKey', '')
|
const moduleKey = inject('shrimpModuleKey', '')
|
||||||
|
|
||||||
const displayText = computed(() => {
|
const selectedTab = computed(() =>
|
||||||
if (!props.modelValue || typeof props.modelValue !== 'object') return '-'
|
props.field.tabs?.find((t: any) => t.key === props.modelValue?.type)
|
||||||
const type = props.modelValue.type
|
)
|
||||||
const tab = props.field.tabs?.find((t: any) => t.key === type)
|
|
||||||
return tab ? vueAdmin.t(tab.label) : String(type)
|
|
||||||
})
|
|
||||||
|
|
||||||
const selectedTab = computed(() => {
|
const branchLabel = computed(() => selectedTab.value ? vueAdmin.t(selectedTab.value.label) : '')
|
||||||
const type = props.modelValue?.type
|
|
||||||
return props.field.tabs?.find((t: any) => t.key === type)
|
|
||||||
})
|
|
||||||
|
|
||||||
const innerValue = computed(() => {
|
|
||||||
const val = props.modelValue
|
|
||||||
if (val != null && typeof val === 'object' && Object.keys(val).length > 0) {
|
|
||||||
return val
|
|
||||||
}
|
|
||||||
return initValue()
|
|
||||||
})
|
|
||||||
|
|
||||||
function initValue() {
|
|
||||||
const firstTab = props.field.tabs?.[0]
|
|
||||||
if (!firstTab) return {}
|
|
||||||
const obj: any = { type: firstTab.key }
|
|
||||||
firstTab.fields?.forEach((f: any) => {
|
|
||||||
if (f.defaultValue !== undefined) {
|
|
||||||
obj[f.key] = typeof f.defaultValue === 'function' ? f.defaultValue() : f.defaultValue
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return obj
|
|
||||||
}
|
|
||||||
|
|
||||||
function onTypeChange(type: any) {
|
function onTypeChange(type: any) {
|
||||||
|
// 清空(非必填) → 整个 tab 置空:type=null、空状态、分支消失
|
||||||
|
if (type == null || type === '') {
|
||||||
|
emit('update:modelValue', null)
|
||||||
|
return
|
||||||
|
}
|
||||||
const tab = props.field.tabs?.find((t: any) => t.key === type)
|
const tab = props.field.tabs?.find((t: any) => t.key === type)
|
||||||
const obj: any = { type }
|
const obj: any = { type }
|
||||||
tab?.fields?.forEach((f: any) => {
|
tab?.fields?.forEach((f: any) => {
|
||||||
@@ -87,24 +74,32 @@ function onTypeChange(type: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onChildChange(key: string, value: any) {
|
function onChildChange(key: string, value: any) {
|
||||||
emit('update:modelValue', { ...innerValue.value, [key]: value })
|
emit('update:modelValue', { ...(props.modelValue || {}), [key]: value })
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
const val = props.modelValue
|
|
||||||
if (val == null || val === '' || (typeof val === 'object' && Object.keys(val).length === 0)) {
|
|
||||||
emit('update:modelValue', initValue())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.tab-display {
|
.tab-display {
|
||||||
display: inline-block;
|
display: inline-flex;
|
||||||
max-width: 200px;
|
flex-wrap: wrap;
|
||||||
overflow: hidden;
|
align-items: center;
|
||||||
text-overflow: ellipsis;
|
gap: 4px 10px;
|
||||||
white-space: nowrap;
|
}
|
||||||
|
|
||||||
|
.tab-branch {
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--el-color-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-child {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-child-label {
|
||||||
|
color: var(--el-text-color-secondary);
|
||||||
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.field-tab {
|
.field-tab {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
:model-value="modelValue"
|
:model-value="modelValue"
|
||||||
@update:model-value="$emit('update:modelValue', $event)"
|
@update:model-value="$emit('update:modelValue', $event)"
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
clearable
|
:clearable="!field.required"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
<div v-if="!vueAdmin.state.isMobile && nextMenu.length > 0" class="aminui-side">
|
<div v-if="!vueAdmin.state.isMobile && nextMenu.length > 0" class="aminui-side">
|
||||||
<div class="adminui-side-scroll">
|
<div class="adminui-side-scroll">
|
||||||
<el-scrollbar>
|
<el-scrollbar>
|
||||||
<el-menu :default-active="$route.fullPath" router>
|
<el-menu :default-active="$route.path" router>
|
||||||
<navMenu :navMenus="nextMenu"></navMenu>
|
<navMenu :navMenus="nextMenu"></navMenu>
|
||||||
</el-menu>
|
</el-menu>
|
||||||
</el-scrollbar>
|
</el-scrollbar>
|
||||||
@@ -43,13 +43,13 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import SideM from "./sideM.vue";
|
|
||||||
import { ref, watch } from "vue";
|
import { ref, watch } from "vue";
|
||||||
|
import { vueAdmin } from "../VueAdmin";
|
||||||
|
import { type IMenuItem } from "../IShrimpType";
|
||||||
|
import SideM from "./sideM.vue";
|
||||||
import navMenu from "./navMenu.vue";
|
import navMenu from "./navMenu.vue";
|
||||||
import Topbar from "./topbar.vue";
|
import Topbar from "./topbar.vue";
|
||||||
import Userbar from "./userbar.vue";
|
import Userbar from "./userbar.vue";
|
||||||
import { vueAdmin } from "../VueAdmin";
|
|
||||||
import { type IMenuItem } from "../IShrimpType";
|
|
||||||
import Logo from "./logo.vue";
|
import Logo from "./logo.vue";
|
||||||
|
|
||||||
// 初始化选中菜单
|
// 初始化选中菜单
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
import { vueAdmin } from "../VueAdmin";
|
import { vueAdmin } from "../VueAdmin";
|
||||||
import { reactive, computed, onMounted } from "vue";
|
import { reactive, computed, onMounted } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import LangSwitch from "../components/LangSwitch.vue";
|
import LangSwitch from "./ShrimpLangSwitch.vue";
|
||||||
|
|
||||||
vueAdmin.token = null;
|
vueAdmin.token = null;
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
<el-main>
|
<el-main>
|
||||||
<el-scrollbar>
|
<el-scrollbar>
|
||||||
<el-menu
|
<el-menu
|
||||||
:default-active="$route.fullPath"
|
:default-active="$route.path"
|
||||||
@select="select"
|
@select="select"
|
||||||
router
|
router
|
||||||
background-color="#212d3d"
|
background-color="#212d3d"
|
||||||
@@ -33,10 +33,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import navMenu from "./navMenu.vue";
|
|
||||||
import Logo from "./logo.vue";
|
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { vueAdmin } from '../VueAdmin';
|
import { vueAdmin } from '../VueAdmin';
|
||||||
|
import navMenu from "./navMenu.vue";
|
||||||
|
import Logo from "./logo.vue";
|
||||||
|
|
||||||
let nav = ref(false);
|
let nav = ref(false);
|
||||||
function showMobileNav() { nav.value = true; }
|
function showMobileNav() { nav.value = true; }
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { vueAdmin } from "../VueAdmin";
|
import { vueAdmin } from "../VueAdmin";
|
||||||
import LangSwitch from "../components/LangSwitch.vue";
|
import LangSwitch from "./ShrimpLangSwitch.vue";
|
||||||
|
|
||||||
function screen() {
|
function screen() {
|
||||||
vueAdmin.fullscreen();
|
vueAdmin.fullscreen();
|
||||||
+6
-4
@@ -47,6 +47,7 @@ export {
|
|||||||
VueAdmin,
|
VueAdmin,
|
||||||
vueAdmin,
|
vueAdmin,
|
||||||
createShrimpAdmin,
|
createShrimpAdmin,
|
||||||
|
resolveVue,
|
||||||
type ShrimpAdminOptions,
|
type ShrimpAdminOptions,
|
||||||
type ShrimpAdminConfig,
|
type ShrimpAdminConfig,
|
||||||
} from './VueAdmin'
|
} from './VueAdmin'
|
||||||
@@ -58,14 +59,15 @@ export {
|
|||||||
type IRouteInfo,
|
type IRouteInfo,
|
||||||
} from './ShrimpClient'
|
} from './ShrimpClient'
|
||||||
|
|
||||||
// 框架组件 — 业务页面想直接复用就 import 这些
|
// 框架组件 — 业务页面想直接复用就 import 这些。
|
||||||
|
// 这些是「静态」导出,拿到的就是框架内置版本,不受消费侧 sources 影响。
|
||||||
export { default as ShrimpTable } from './components/ShrimpTable.vue'
|
export { default as ShrimpTable } from './components/ShrimpTable.vue'
|
||||||
export { default as ShrimpEditDrawer } from './components/ShrimpEditDrawer.vue'
|
export { default as ShrimpEditDrawer } from './components/ShrimpEditDrawer.vue'
|
||||||
export { default as ShrimpFilterDrawer } from './components/ShrimpFilterDrawer.vue'
|
export { default as ShrimpFilterDrawer } from './components/ShrimpFilterDrawer.vue'
|
||||||
export { default as ShrimpFilterTrigger } from './components/ShrimpFilterTrigger.vue'
|
export { default as ShrimpFilterTrigger } from './components/ShrimpFilterTrigger.vue'
|
||||||
export { default as ShrimpSearchInput } from './components/ShrimpSearchInput.vue'
|
export { default as ShrimpSearchInput } from './components/ShrimpSearchInput.vue'
|
||||||
export { default as PowerTree } from './components/PowerTree.vue'
|
export { default as ShrimpPowerTree } from './components/ShrimpPowerTree.vue'
|
||||||
export { default as LangSwitch } from './components/LangSwitch.vue'
|
export { default as ShrimpLangSwitch } from './components/ShrimpLangSwitch.vue'
|
||||||
|
|
||||||
// 应用入口视图(消费侧 createApp 用)
|
// 应用入口视图(消费侧 createApp 用)
|
||||||
export { default as App } from './views/App.vue'
|
export { default as App } from './App.vue'
|
||||||
|
|||||||
+19
-3
@@ -28,7 +28,7 @@
|
|||||||
<el-input v-model="formData.description" type="textarea" :rows="3" />
|
<el-input v-model="formData.description" type="textarea" :rows="3" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('role.powers')">
|
<el-form-item :label="$t('role.powers')">
|
||||||
<PowerTree :modelValue="formData.powers || []" :allPowers="allPowers" :menuTree="vueAdmin.menuTree"
|
<ShrimpPowerTree :modelValue="formData.powers || []" :allPowers="allPowers" :menuTree="vueAdmin.menuTree"
|
||||||
@update:modelValue="val => formData.powers = val" />
|
@update:modelValue="val => formData.powers = val" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
@@ -50,10 +50,11 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted } from 'vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
|
import { useRoute } from 'vue-router'
|
||||||
import { vueAdmin } from '../VueAdmin'
|
import { vueAdmin } from '../VueAdmin'
|
||||||
import { IRole, IRoleProto, WithId, ILabel } from '../IShrimpType'
|
import { IRole, IRoleProto, WithId, ILabel } from '../IShrimpType'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import PowerTree from '../components/PowerTree.vue'
|
import ShrimpPowerTree from '../components/ShrimpPowerTree.vue'
|
||||||
|
|
||||||
interface IPowerItem {
|
interface IPowerItem {
|
||||||
key: string
|
key: string
|
||||||
@@ -61,12 +62,24 @@ interface IPowerItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
const route = useRoute()
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
moduleKey: string
|
moduleKey: string
|
||||||
events?: string[]
|
events?: string[]
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
// relation 跳转落到 role 页时带 ?filter={"_id":...}。role 是自定义 master-detail 页(非 ShrimpTable、
|
||||||
|
// 不做服务端过滤),全量加载后按这个 _id 在列表里选中那条;解析不出就走默认(选第一个)。
|
||||||
|
function jumpTargetId(): string {
|
||||||
|
try {
|
||||||
|
const f = route.query.filter ? JSON.parse(String(route.query.filter)) : null
|
||||||
|
return f && typeof f === 'object' ? String(f._id || '') : ''
|
||||||
|
} catch {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const roleApi = vueAdmin.getModule<IRoleProto>('role')
|
const roleApi = vueAdmin.getModule<IRoleProto>('role')
|
||||||
|
|
||||||
const roleList = ref<WithId<IRole>[]>([])
|
const roleList = ref<WithId<IRole>[]>([])
|
||||||
@@ -138,7 +151,10 @@ async function handleDelete() {
|
|||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
allPowers.value = await roleApi.allPower()
|
allPowers.value = await roleApi.allPower()
|
||||||
await loadRoles()
|
await loadRoles()
|
||||||
if (roleList.value.length > 0) {
|
const jumpId = jumpTargetId()
|
||||||
|
if (jumpId && roleList.value.some(r => r._id === jumpId)) {
|
||||||
|
onSelect(jumpId)
|
||||||
|
} else if (roleList.value.length > 0) {
|
||||||
onSelect(roleList.value[0]._id)
|
onSelect(roleList.value[0]._id)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
+6
-5
@@ -1,13 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<ShrimpTable moduleKey="user" />
|
<ShrimpTable moduleKey="user">
|
||||||
|
<template #column-updatedAt="{ row }">
|
||||||
|
<FieldRelativeTime :model-value="row.updatedAt" mode="display" :field="{}" />
|
||||||
|
</template>
|
||||||
|
</ShrimpTable>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import ShrimpTable from '../components/ShrimpTable.vue'
|
import ShrimpTable from '../components/ShrimpTable.vue'
|
||||||
import { vueAdmin } from '../VueAdmin'
|
import FieldRelativeTime from '../components/fields/FieldRelativeTime.vue'
|
||||||
import FieldRelativeTime from './FieldRelativeTime.vue'
|
|
||||||
|
|
||||||
vueAdmin.overrideField('user', 'updatedAt', FieldRelativeTime)
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -14,8 +14,8 @@
|
|||||||
import { ref, computed, onMounted, watch } from 'vue'
|
import { ref, computed, onMounted, watch } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import ShrimpTable from '../../components/ShrimpTable.vue'
|
|
||||||
import { vueAdmin } from '../../VueAdmin'
|
import { vueAdmin } from '../../VueAdmin'
|
||||||
|
import ShrimpTable from '../../components/ShrimpTable.vue'
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|||||||
Reference in New Issue
Block a user