-
-
本页演示项目中 @/iview 封装组件的常见用法,数据均为本地 Mock,无需后端接口。
+
+
IView 组件库使用文档
+
+ @/iview 是基于 Ant Design Vue 封装的业务组件库,提供配置驱动的表单、筛选、表格、详情与整页布局能力。
+ 本页包含说明文档与可交互示例,数据均为本地 Mock,无需后端接口。
+
+
+
+
+
+
+
+ {{ docOverview.structure }}
+
+
+
+
+
+ {{ docOverview.quickstart }}
+
+
+
+
+
+
-
-
-
提交校验
-
重置
-
- {{ formReadOnly ? "切换为编辑" : "切换为只读" }}
-
+
+
+
+
+
提交校验
+
重置
+
+ {{ formReadOnly ? "切换为编辑" : "切换为只读" }}
+
+
+
-
+
-
-
+
-
-
-
- {{ statusLabel(record.status) }}
+
+
+
+
+
+ {{ statusLabel(record.status) }}
+
-
-
+
+
+
-
-
{{ layoutPageExample }}
+
+
+
+
{{ layoutPageExample }}
+
+
+
+
+
+
+
+
+
+
IViewConfirm — 确认操作
+
+
+ 普通确认(PC 气泡 / 移动端 Modal)
+
+
+ 重要确认(需输入文字)
+
+
+
+
IViewDrawer — 抽屉
+
打开详情抽屉
+
+
消息提示 — messageTips
+
+
showSuccessTips
+
showErrorTips
+
+
-
+
{{ statusLabel(record.status) }}
@@ -131,9 +164,307 @@ import IViewTable from "@/iview/IViewTable.vue";
import IViewDescriptions from "@/iview/IViewDescriptions.vue";
import IViewConfirm from "@/iview/IViewConfirm.vue";
import IViewDrawer from "@/iview/IViewDrawer.vue";
+import DemoDoc from "./DemoDoc.vue";
import { showSuccessTips, showErrorTips } from "@/iview/utils/messageTips";
-const activeSection = ref("form");
+const activeSection = ref("overview");
+const overviewCollapse = ref(["arch", "components", "quickstart"]);
+
+// ── 文档内容 ──────────────────────────────────────────
+const docOverview = {
+ structure: `src/iview/
+├── IViewForm.vue # 配置驱动表单
+├── IViewFilter.vue # 筛选栏(基于 IViewForm inline 布局)
+├── IViewTable.vue # 表格(PC 表格 / 移动端卡片)
+├── IViewDescriptions.vue # 详情描述列表
+├── IViewConfirm.vue # 确认弹层
+├── IViewDrawer.vue # 响应式抽屉
+├── IViewTabs.vue # 标签页
+├── ILayoutPage.vue # 整页 CRUD 布局
+├── form/ # 各类型表单控件
+├── display/ # 展示类子组件
+├── utils/ # request、messageTips 等工具
+└── urlEmbed/ # iframe 嵌入页通信`,
+ quickstart: `// 1. 按需引入组件
+import IViewForm from "@/iview/IViewForm.vue";
+import { showSuccessTips, showErrorTips } from "@/iview/utils/messageTips";
+import { apiRequest } from "@/iview/utils/request";
+
+// 2. 配置驱动表单
+const formData = ref({});
+const formConfig = ref({
+ fields: [
+ { name: "username", label: "账号", type: "text", required: true },
+ { name: "status", label: "状态", type: "boolean", trueValue: 1, falseValue: 0 },
+ ],
+});
+
+// 3. 模板
+
+
+// 4. 提交
+await formRef.value.validate();
+await apiRequest("api.xxx.create", formData.value);
+showSuccessTips("保存成功");`,
+};
+
+const componentTableColumns = [
+ { title: "组件", dataIndex: "name", width: 180 },
+ { title: "用途", dataIndex: "desc" },
+ { title: "典型场景", dataIndex: "scene", ellipsis: true },
+];
+
+const componentTableData = [
+ { name: "IViewForm", desc: "配置驱动表单,支持 17+ 字段类型", scene: "新增/编辑、设置页" },
+ { name: "IViewFilter", desc: "列表筛选栏,支持高级筛选折叠", scene: "列表页顶部搜索" },
+ { name: "IViewTable", desc: "表格,PC 端可拖拽横向滚动,移动端卡片", scene: "数据列表展示" },
+ { name: "IViewDescriptions", desc: "详情描述列表", scene: "详情页、抽屉内容" },
+ { name: "IViewConfirm", desc: "确认操作(普通 / 重要)", scene: "删除、危险操作" },
+ { name: "IViewDrawer", desc: "响应式抽屉,自动适配侧边栏宽度", scene: "详情、表单弹层" },
+ { name: "IViewTabs", desc: "标签页,移动端 Strip 样式", scene: "模块切换、嵌套 Tab" },
+ { name: "ILayoutPage", desc: "整页 CRUD 布局引擎", scene: "标准增删改查页面" },
+ { name: "apiRequest", desc: "统一 API 请求(自动带 token)", scene: "所有后端接口调用" },
+ { name: "messageTips", desc: "成功/错误消息提示", scene: "操作反馈" },
+];
+
+const docForm = [
+ {
+ title: "Props",
+ content: `IViewForm
+ v-model / modelValue Object | String 表单数据(modelFormat='json' 时为 JSON 字符串)
+ config Object | String 表单配置 { fields, extrasFields, formatValue, unformatValue }
+ readOnly Boolean 全局只读
+ layout 'vertical' | 'horizontal' | 'inline'
+ labelCol / wrapperCol Object 标签布局(inline 时无效)
+ disableResponsive Boolean 禁用移动端强制 vertical 布局`,
+ },
+ {
+ title: "暴露方法(ref)",
+ content: `formRef.value.validate() // 校验全部可见字段,失败 throw
+formRef.value.validateField(field) // 校验单个字段
+formRef.value.resetFormData() // 重置为 defaultValue`,
+ },
+ {
+ title: "字段配置 fields[]",
+ content: `通用属性:
+ name 字段名(必填)
+ label 标签
+ type 字段类型(见下方类型表)
+ required 是否必填
+ defaultValue 默认值
+ placeholder 占位符
+ tips 输入提示
+ show 显示条件,支持函数或表达式字符串,如 "!!record.guid"
+ disabled 禁用,支持函数
+ onChanged 值变化回调
+
+字段类型:
+ title 分组标题(仅展示 label)
+ text 单行文本(minLength / maxlength / textLenMax)
+ textarea 多行文本(textRows / maxlength)
+ number 数字(min / max / numMin / numMax)
+ radio 单选(options: [{ value, label }])
+ checkbox 多选(options)
+ select 下拉(options,支持远程 optionsApi)
+ date 日期
+ datetime 日期时间
+ time 时间
+ boolean 开关(trueValue / falseValue)
+ image 图片上传
+ video 视频上传
+ file 文件上传
+ fileBase64 Base64 文件
+ imageBase64 Base64 图片
+ signatureImage 手写签名
+
+扩展:registerIViewFormFieldComponent(type, component) 注册自定义字段类型`,
+ },
+ {
+ title: "代码示例",
+ content: `
+
+const formConfig = ref({
+ extrasFields: ["guid"], // 额外保留但不渲染的字段
+ fields: [
+ { type: "title", label: "基础信息" },
+ { name: "name", label: "姓名", type: "text", required: true, maxlength: 20 },
+ { name: "city", label: "城市", type: "select", options: [
+ { value: "gz", label: "广州" },
+ ]},
+ { name: "enabled", label: "启用", type: "boolean", trueValue: 1, falseValue: 0 },
+ ],
+});`,
+ },
+];
+
+const docList = [
+ {
+ title: "IViewFilter Props",
+ content: `config Object 筛选项配置 { fields: [...] },字段同 IViewForm
+v-model Object 筛选参数
+searchButtonText String 搜索按钮文字,默认「搜索」
+resetButtonText String 重置按钮文字,默认「重置」
+
+字段 advanced: true → PC 端归入「高级选项」折叠区
+移动端首个筛选项始终可见,其余可收入「高级筛选」
+
+事件:@search @reset @init`,
+ },
+ {
+ title: "IViewTable Props",
+ content: `columns Array 列配置
+data-source Array 数据源
+row-key String 行唯一键
+loading Boolean 加载态
+pagination Object | false 分页配置,false 关闭分页
+show-filter Boolean 是否显示列显示设置
+
+列配置:
+ title / dataIndex 标题 / 字段名
+ width 列宽
+ bodySlot: true 使用 #bodyCell 插槽自定义渲染
+ fixed: 'right' 固定列
+ ellipsis 超长省略
+ customRender 函数 ({ record, column, mobile }) => HTML 字符串
+
+事件:@change(pagination, filters, sorter)
+
+特性:PC 端支持列宽拖拽、横向拖拽滚动条;移动端自动切换为卡片布局`,
+ },
+ {
+ title: "代码示例",
+ content: `
+
+
+
+
+ 编辑
+
+
+`,
+ },
+];
+
+const docDetail = [
+ {
+ title: "Props",
+ content: `record-data Object 详情数据对象
+columns-list Array 列配置(同表格列,支持 bodySlot / customRender / span)
+column-size Number 每行列数,默认 2
+hidden-label Boolean 是否隐藏标签,默认 true`,
+ },
+ {
+ title: "列配置扩展",
+ content: `span Number 占列数(如 span: 2 占满一行)
+bodySlot: true 使用 #bodyCell 插槽
+show Function | String 条件显示
+customRender Function ({ record, column, mobile }) => HTML
+
+
+
+ {{ record.status }}
+
+`,
+ },
+];
+
+const docCommon = [
+ {
+ title: "IViewConfirm",
+ content: `importance 'normal' | 'important'
+ normal PC 端 Popconfirm 气泡;移动端 Modal
+ important Modal + 需输入 entityName 文字才能确认
+
+title 确认标题
+entityName important 模式下需输入的确认文字
+@confirm 确认回调,可返回 Promise 自动 loading
+
+
+ 删除
+`,
+ },
+ {
+ title: "IViewDrawer",
+ content: `open / v-model:open 是否打开
+title 标题
+width 固定宽度(可选,默认自适应)
+flushContent 去掉内边距,适合 iframe 全屏
+@close 关闭回调
+
+
+
+`,
+ },
+ {
+ title: "IViewTabs",
+ content: `v-model:activeKey 当前 Tab key
+embedded 嵌入模式(去掉外层 padding)
+level 'primary' | 'secondary' 层级样式
+animated 是否开启动画
+
+
+ ...
+ ...
+`,
+ },
+ {
+ title: "messageTips / apiRequest",
+ content: `import { showSuccessTips, showErrorTips } from "@/iview/utils/messageTips";
+import { apiRequest } from "@/iview/utils/request";
+
+showSuccessTips("保存成功");
+showErrorTips(error); // 支持表单 errorFields 自动滚动定位
+
+const data = await apiRequest("api.system.admin.info.list", { page: 1 });
+// api 字符串对应后端接口标识,请求体自动附带 token`,
+ },
+];
+
+const docLayout = [
+ {
+ title: "config 结构",
+ content: `const config = ref({
+ listPages: [{ // 列表页(可多个 Tab)
+ title, name, api, rowKey, isDefault,
+ showFilter, pagination, columns, filters,
+ defaultParams,
+ }],
+ formPages: [{ // 表单页(抽屉内)
+ name, title,
+ submitApi, // 新增提交接口
+ recordApi, // 编辑时拉取详情(update 场景)
+ paramsKey: ["guid"], // 从 record 取参的字段
+ formConfig: { fields: [...] },
+ }],
+ detailPages: [{ // 详情页(抽屉内)
+ name, title, recordApi, paramsKey, columns,
+ }],
+ infoPages: [{ // 顶部信息区(可选)
+ name, recordApi, columns,
+ }],
+});`,
+ },
+ {
+ title: "暴露方法(pageRef)",
+ content: `pageRef.value.showFormPage('create') // 打开新增表单
+pageRef.value.showFormPage('update', record) // 打开编辑表单
+pageRef.value.showDetailPage('detail', record)// 打开详情
+pageRef.value.refreshList() // 刷新列表
+pageRef.value.refreshPage() // 刷新整页
+pageRef.value.closeFormPage() // 关闭表单抽屉
+pageRef.value.patchListRow(id, patch) // 局部更新列表行`,
+ },
+ {
+ title: "插槽",
+ content: `#listActions="{ type, refresh }" 列表操作区(标题、新增按钮等)
+#bodyCell="{ column, record, type, refresh }" 自定义列/详情渲染
+#listHeader / #listFooter 列表上下扩展区
+#infoHeader / #infoTab / #infoFooter 信息区扩展
+#expandedRowRender 表格行展开`,
+ },
+];
// ── 表单示例 ──────────────────────────────────────────
const formRef = ref(null);
@@ -384,50 +715,77 @@ const detailColumns = ref([
{ title: "备注", dataIndex: "remark", span: 2 },
]);
+// ── 通用组件示例 ──────────────────────────────────────
+const handleNormalConfirm = () => {
+ showSuccessTips("已确认操作");
+};
+
+const handleImportantConfirm = () => {
+ showSuccessTips("重要操作已确认");
+};
+
// ── ILayoutPage 配置示例 ──────────────────────────────
-const layoutPageExample = `const config = ref({
+const layoutPageExample = `
+
+
+ 添加
+
+
+
+ 编辑
+ handleDelete(record)">
+ 删除
+
+
+
+
+
+
+