From dfa9fdbec269576d60f9c9d340ac164f37cda392 Mon Sep 17 00:00:00 2001
From: XiaoDaiGua-Ray <51957438+XiaoDaiGua-Ray@users.noreply.github.com>
Date: Wed, 4 Nov 2026 10:29:51 +0800
Subject: [PATCH] feat(demos): add working examples with visible results
---
__test__/components/iframe-loading.spec.ts | 18 +
public/examples/embed.html | 24 ++
public/examples/qr-background.gif | Bin 0 -> 2652 bytes
public/examples/request.json | 8 +
src/api/demo/test.ts | 43 +--
src/components/RFlow/src/Flow.tsx | 41 +--
src/components/RIframe/src/Iframe.tsx | 8 +-
.../components/useContextmenuCoordinate.ts | 12 +
src/locales/lang/en-US/demoDetails.json | 219 ++++++++++++
src/locales/lang/en-US/showcase.json | 40 ++-
src/locales/lang/zh-CN/demoDetails.json | 219 ++++++++++++
src/locales/lang/zh-CN/showcase.json | 40 ++-
src/views/demo/axios/index.scss | 3 -
src/views/demo/axios/index.tsx | 285 ++++++++--------
src/views/demo/barcode-demo.tsx | 230 ++++++-------
src/views/demo/cache-demo/index.tsx | 178 +++++-----
.../demo/components/CacheRouteExample.tsx | 58 ++++
src/views/demo/components/DemoResult.tsx | 18 +
src/views/demo/components/index.scss | 140 ++++++++
src/views/demo/context-menu/index.tsx | 110 +++---
src/views/demo/directive/index.tsx | 312 +++++++++---------
src/views/demo/draggable-card.tsx | 155 +++++----
src/views/demo/echart/index.scss | 2 +-
src/views/demo/echart/index.tsx | 197 ++++++-----
src/views/demo/flow-demo.tsx | 161 ++++-----
src/views/demo/form/index.tsx | 303 +++++++++--------
src/views/demo/iframe/index.tsx | 76 +++--
src/views/demo/modal-demo/index.tsx | 192 +++++------
.../demo/multi/views/multi-menu-one/index.tsx | 21 +-
.../views/sub-menu-other/index.tsx | 21 +-
.../views/multi-menu-two-one/index.tsx | 25 +-
src/views/demo/precision/index.tsx | 232 ++++++-------
src/views/demo/qrcode/index.tsx | 193 ++++++-----
.../demo/rely/views/rely-about/index.scss | 26 +-
.../demo/rely/views/rely-about/index.tsx | 216 +++++-------
src/views/demo/router-demo/people.ts | 8 +
.../router-demo/router-demo-detail/index.tsx | 89 +++--
.../router-demo/router-demo-home/index.tsx | 36 +-
src/views/demo/scroll-reveal/index.scss | 32 +-
src/views/demo/scroll-reveal/index.tsx | 27 +-
40 files changed, 2425 insertions(+), 1593 deletions(-)
create mode 100644 __test__/components/iframe-loading.spec.ts
create mode 100644 public/examples/embed.html
create mode 100644 public/examples/qr-background.gif
create mode 100644 public/examples/request.json
create mode 100644 src/locales/lang/en-US/demoDetails.json
create mode 100644 src/locales/lang/zh-CN/demoDetails.json
delete mode 100644 src/views/demo/axios/index.scss
create mode 100644 src/views/demo/components/CacheRouteExample.tsx
create mode 100644 src/views/demo/components/DemoResult.tsx
create mode 100644 src/views/demo/router-demo/people.ts
diff --git a/__test__/components/iframe-loading.spec.ts b/__test__/components/iframe-loading.spec.ts
new file mode 100644
index 00000000..149b0802
--- /dev/null
+++ b/__test__/components/iframe-loading.spec.ts
@@ -0,0 +1,18 @@
+import { RIframe } from '@/components/RIframe'
+import { mount } from '@vue/test-utils'
+
+describe('RIframe loading strategy', () => {
+ it.each([
+ [true, 'lazy'],
+ [false, 'eager'],
+ ['eager', 'eager'],
+ ] as const)('sets loading=%s to %s', (lazy, expected) => {
+ const wrapper = mount(RIframe, { props: { lazy, src: '/embed.html' } })
+
+ try {
+ expect(wrapper.get('iframe').attributes('loading')).toBe(expected)
+ } finally {
+ wrapper.unmount()
+ }
+ })
+})
diff --git a/public/examples/embed.html b/public/examples/embed.html
new file mode 100644
index 00000000..a46628cd
--- /dev/null
+++ b/public/examples/embed.html
@@ -0,0 +1,24 @@
+
+
+
+
+
Ray Template embed
+
+
+
+ Ray Template
+
+
diff --git a/public/examples/qr-background.gif b/public/examples/qr-background.gif
new file mode 100644
index 0000000000000000000000000000000000000000..0b1f062c8571eb1cec2e3fb455000c8d9c2ad6a0
GIT binary patch
literal 2652
zcmZ?wbhEHblwgox_|5>L~%oSd9oTwL7T+&nxy
zyu7@8e0==;`~m_3f`WoVLPEmA!XhFfqN1W=Vq)Ur;t~=Pl9G~AQc}{=(lRnKva+&r
za&q$W@(KzHii(O#N=nMg$|@=KYmvnwpwgT3XuL+B!Nqy1Kf0dV2c$
z`UVCDhK7blMn=ZQ#wI2vrlzK5W@hH*<`xzfmX?-QR#w*5);2aawzjr*c6Rpm_6`mX
zj*gB_PEO9w&Mq!4uCA_bZf@@G?j9ZO-;?s%`Gi0t*xzX
zZEfxC?HwH*ot>RsU0vPX-90@$y}iACeSQ7?{Szikm^g9bq)C$|Po6ww%9N>7r%szT
zZTj@-GiJ<~IdkT$S+i!(o;_#IoVj!7&YL%H{`~n17A#n}aN(jwixw|lykyCerAwDC
zTefWZ^5rX5tXR2n<*HSyR6b6BzI}L4N=^jk
zR*q1Hi+`m(HY{)~;Sg3bIk92Ep>|$ryAX+q50A8n^2dqHnE1f0PxgN;k7a?1=VZme
zvXGe*Q(dPECVJiR2vRva*}TwiO=fZW**Ti}pICMUz3^XbCCbJ!n$t$BJsMVfM~@vp
ze(Ln8v**uTynO!J&5O70UAh0{+T)iup1r;K^5d=7pKrhYb_bNrfO!l{Hp5cS!7D%9
z*$kN3Al2UEFJE7L`}Fq5yHCGfeIc&S`}XGrM+n1zP8p34a}GAMb83ZjYDeA(ZAb
T%UYW))ndzI|JmluObpfl=0*dm
literal 0
HcmV?d00001
diff --git a/public/examples/request.json b/public/examples/request.json
new file mode 100644
index 00000000..f8458dea
--- /dev/null
+++ b/public/examples/request.json
@@ -0,0 +1,8 @@
+{
+ "ticket": { "id": "RAY-024", "title": "Review the workspace", "status": "ready" },
+ "cities": {
+ "Hangzhou": { "temperature": 19, "humidity": 66 },
+ "Shanghai": { "temperature": 17, "humidity": 73 },
+ "Chengdu": { "temperature": 21, "humidity": 58 }
+ }
+}
diff --git a/src/api/demo/test.ts b/src/api/demo/test.ts
index 281c905e..c839ab8a 100644
--- a/src/api/demo/test.ts
+++ b/src/api/demo/test.ts
@@ -1,37 +1,20 @@
import { request } from '@/axios'
-import type { BasicResponse } from '@/types'
-interface AxiosTestResponse extends GlobalRecordable {
- data: GlobalRecordable[]
- city?: string
+interface RequestFixture {
+ ticket: { id: string; title: string; status: string }
+ cities: Record
}
-interface JSONPlaceholder {
- completed: boolean
- id: number
- title: string
- userId: number
-}
+export const requestFixtureUrl = `${import.meta.env.BASE_URL}examples/request.json`
-/**
- *
- * @param city 天气查询接口所需的城市名称
- *
- * @description
- * 按城市名称请求演示天气接口。
- *
- * @returns 演示接口的响应 Promise
- */
-export const getWeather = (city: string) => {
- return request({
- url: `https://www.tianqiapi.com/api?version=v9&appid=23035354&appsecret=8YvlPNrz&city=${city}`,
- method: 'get',
- })
-}
+export const getRequestFixture = () =>
+ request({ url: requestFixtureUrl, method: 'get' })
-export const getTypicCode = () => {
- return request({
- url: 'https://jsonplaceholder.typicode.com/todos/1',
- method: 'get',
- })
+export const getWeather = async (city: string) => {
+ const { cities } = await getRequestFixture()
+ const weather = cities[city]
+
+ if (!weather) throw new Error('Missing sample city.')
+
+ return { city, ...weather }
}
diff --git a/src/components/RFlow/src/Flow.tsx b/src/components/RFlow/src/Flow.tsx
index 591fa515..f322ff51 100644
--- a/src/components/RFlow/src/Flow.tsx
+++ b/src/components/RFlow/src/Flow.tsx
@@ -4,7 +4,6 @@ import { call, completeSize } from '@/utils'
import LogicFlow from '@logicflow/core'
import { omit } from 'lodash-es'
import { useTemplateRef } from 'vue'
-import type { WatchStopHandle } from 'vue'
import props from './props'
import type { FlowGraphData, G } from './types'
@@ -35,16 +34,11 @@ export default defineComponent({
edgeTextEdit: false,
textEdit: false,
}
- // watchData 回调
- let watchDataStop: WatchStopHandle
// 默认流程图数据
const defaultGraphData = {
nodes: [],
edges: [],
}
- const cacheProps = {
- readonly: props.readonly,
- }
// 注册流程图插件
const registerExtension = () => {
@@ -73,6 +67,7 @@ export default defineComponent({
// 单独处理 isSilentMode 配置项
Object.assign(readonlyOptions, ops, {
isSilentMode: bool,
+ adjustNodePosition: !bool,
})
logicFlowInstRef.value.updateEditConfig(readonlyOptions)
}
@@ -107,31 +102,17 @@ export default defineComponent({
updateFlowConfig(readonly)
}
- watchEffect(() => {
- if (props.watchData) {
- watchDataStop = watch(
- () => props.data,
- (ndata) => {
- if (logicFlowInstRef.value) {
- ndata && logicFlowInstRef.value.renderRawData(ndata as G)
- } else {
- setupFlowRender(ndata)
- }
- },
- )
- } else {
- watchDataStop?.()
- }
-
- if (props.readonly !== cacheProps.readonly) {
- updateFlowConfig(props.readonly)
-
- cacheProps.readonly = props.readonly
- }
- })
+ watch(
+ () => props.data,
+ (data) => {
+ if (props.watchData && data)
+ logicFlowInstRef.value?.renderRawData(data as G)
+ },
+ )
+ watch(() => props.readonly, updateFlowConfig)
onMounted(() => {
- setupFlowRender()
+ setupFlowRender(props.data)
const { onRegister } = props
@@ -140,6 +121,8 @@ export default defineComponent({
}
})
+ onBeforeUnmount(() => logicFlowInstRef.value?.destroy())
+
return {
flowDomRef,
cssVars,
diff --git a/src/components/RIframe/src/Iframe.tsx b/src/components/RIframe/src/Iframe.tsx
index ab629845..f810f8e8 100644
--- a/src/components/RIframe/src/Iframe.tsx
+++ b/src/components/RIframe/src/Iframe.tsx
@@ -68,7 +68,13 @@ export default defineComponent({
allow={this.allow}
name={this.name}
title={this.title}
- loading={typeof this.lazy === 'boolean' ? 'lazy' : this.lazy}
+ loading={
+ this.lazy === true
+ ? 'lazy'
+ : this.lazy === false
+ ? 'eager'
+ : this.lazy
+ }
/>
),
}}
diff --git a/src/hooks/components/useContextmenuCoordinate.ts b/src/hooks/components/useContextmenuCoordinate.ts
index abd7cd77..7a2dd557 100644
--- a/src/hooks/components/useContextmenuCoordinate.ts
+++ b/src/hooks/components/useContextmenuCoordinate.ts
@@ -5,12 +5,15 @@ import type {
MaybeElement,
MaybeElementRef,
OnClickOutsideHandler,
+ OnClickOutsideOptions,
} from '@vueuse/core'
import type { MaybeRefOrGetter } from 'vue'
export interface UseContextmenuCoordinateOptions {
/** 关闭菜单后执行的外部点击回调。 */
clickOutside?: OnClickOutsideHandler
+ /** 菜单挂载在目标之外时,可将弹层加入外部点击的忽略范围。 */
+ ignore?: OnClickOutsideOptions['ignore']
}
/**
@@ -92,6 +95,15 @@ export const useContextmenuCoordinate = (
if (typeof current === 'object') current.clickOutside?.(event)
},
+ {
+ ignore: () => {
+ const current = toValue(options)
+
+ return typeof current === 'object'
+ ? (toValue(current.ignore) ?? [])
+ : []
+ },
+ },
)
const cleanupContextmenu = useEventListener(
diff --git a/src/locales/lang/en-US/demoDetails.json b/src/locales/lang/en-US/demoDetails.json
new file mode 100644
index 00000000..515beda7
--- /dev/null
+++ b/src/locales/lang/en-US/demoDetails.json
@@ -0,0 +1,219 @@
+{
+ "result": "Result",
+ "empty": "No data",
+ "loading": "Loading",
+ "precision": {
+ "title": "Decimal precision",
+ "intro": "Edit the operands and inspect results at eight decimal places.",
+ "add": "Addition",
+ "subtract": "Subtraction",
+ "multiply": "Multiplication",
+ "divide": "Division",
+ "invalid": "Enter valid decimal numbers.",
+ "zero": "Divisors must be nonzero.",
+ "allocation": "Equal allocation",
+ "amount": "Amount",
+ "parts": "Number of shares"
+ },
+ "cache": {
+ "title": "Storage lab",
+ "intro": "Compare reading and writing the same key in two storage scopes.",
+ "write": "Write",
+ "read": "Read",
+ "remove": "Remove",
+ "scope": "Storage scope",
+ "key": "Key",
+ "value": "Value",
+ "missing": "No value for this key"
+ },
+ "form": {
+ "title": "Form validation",
+ "intro": "Submit the profile to see the submitted data beside the form.",
+ "profile": "Profile",
+ "name": "Name",
+ "age": "Age",
+ "date": "Date of birth",
+ "gender": "Gender",
+ "female": "Female",
+ "male": "Male",
+ "notes": "Notes",
+ "submit": "Submit profile",
+ "validateName": "Check name only",
+ "clear": "Clear validation",
+ "reset": "Reset",
+ "payload": "Submission",
+ "waiting": "Waiting for submission",
+ "submitted": "Submitted",
+ "invalid": "Check the highlighted fields",
+ "nameValid": "Name is valid",
+ "nameRequired": "Enter a name",
+ "ageRequired": "Enter an age between 0 and 120",
+ "dateRequired": "Choose a date of birth",
+ "genderRequired": "Choose a gender",
+ "sample": "Fill sample"
+ },
+ "request": {
+ "title": "Request lab",
+ "intro": "Inspect a manual response and compare request counts while typing in the throttle and debounce examples.",
+ "fixture": "Local sample data",
+ "fetch": "Fetch ticket",
+ "city": "Query by city",
+ "selectCity": "Choose a sample city",
+ "waiting": "Waiting for a request",
+ "failed": "Request failed. Try again.",
+ "throttle": "Throttle · 1 second",
+ "debounce": "Debounce · 1 second",
+ "sent": "{count} requests sent",
+ "input": "Type a few characters",
+ "last": "Latest response"
+ },
+ "iframe": {
+ "title": "Embedded content",
+ "intro": "Compare two loading strategies using the same local page.",
+ "eager": "Eager loading",
+ "lazy": "Lazy loading",
+ "loaded": "Loaded",
+ "pending": "Pending",
+ "mount": "Mount lazy example"
+ },
+ "modal": {
+ "title": "Dialogs",
+ "intro": "Open the presets to try dragging, fullscreen and a custom width.",
+ "card": "Card",
+ "dialog": "Dialog",
+ "fullscreen": "Fullscreen",
+ "record": "Sample ticket",
+ "open": {
+ "card": "Open card",
+ "dialog": "Open dialog",
+ "fullscreen": "Open fullscreen"
+ },
+ "width": "Card width",
+ "applyWidth": "Open at this width",
+ "createCard": "Create card programmatically",
+ "createDialog": "Create dialog programmatically",
+ "last": "Last closed"
+ },
+ "qr": {
+ "title": "QR code",
+ "intro": "Edit the content and style to regenerate the QR code.",
+ "controls": "Generation settings",
+ "content": "QR content",
+ "brand": "Center logo",
+ "status": "Display state",
+ "ready": "Ready",
+ "loading": "Loading",
+ "error": "Expired",
+ "download": "Download QR code",
+ "preview": "Scan preview",
+ "expired": "QR code expired",
+ "reload": "Reactivate",
+ "failed": "Could not generate the QR code",
+ "noText": "Enter text to generate a code",
+ "animated": "Animated background"
+ },
+ "barcode": {
+ "title": "Barcode",
+ "intro": "Switch encoding formats and edit the sample to see the live preview.",
+ "controls": "Encoding settings",
+ "format": "Format",
+ "content": "Barcode content",
+ "color": "Custom color",
+ "responsive": "Responsive width",
+ "preview": "Barcode preview",
+ "invalid": "This value does not match the selected format."
+ },
+ "flow": {
+ "title": "Flow diagram",
+ "intro": "Drag a node and inspect the graph, or switch to read-only mode.",
+ "review": "Review",
+ "done": "Done",
+ "canvas": "Workflow canvas",
+ "readonly": "Read-only",
+ "editable": "Editable",
+ "fit": "Fit view",
+ "reset": "Reset canvas",
+ "inspect": "Inspect graph",
+ "graph": "Current graph"
+ },
+ "drag": {
+ "title": "Draggable card",
+ "intro": "Open a card at a chosen position and compare the two drag boundaries.",
+ "stage": "Drag playground",
+ "position": "Initial position",
+ "enable": "Drag enabled",
+ "locked": "Drag locked",
+ "bounded": "Bounded card",
+ "body": "Page-wide card",
+ "bounds": "Container boundary"
+ },
+ "context": {
+ "title": "Context menu",
+ "intro": "Right-click the workspace or open the menu with the button.",
+ "target": "Ticket actions",
+ "open": "Open actions",
+ "last": "Last action",
+ "review": "Mark for review",
+ "archive": "Archive",
+ "restore": "Restore"
+ },
+ "nested": {
+ "draft": "Draft",
+ "note": "Temporary note",
+ "route": "Current route"
+ },
+ "detail": {
+ "name": "Name",
+ "address": "Address",
+ "phone": "Phone",
+ "action": "Actions",
+ "open": "Open details",
+ "back": "Back to people",
+ "missing": "Select a record from the list.",
+ "params": "Route parameters"
+ },
+ "directive": {
+ "ripple": "Click ripple",
+ "ripplePointer": "Ripple from pointer",
+ "rippleCenter": "Ripple from center",
+ "ellipsis": "Text truncation",
+ "single": "Single line",
+ "multi": "Multiple lines",
+ "copy1": "Copy text",
+ "copy2": "Copy custom content",
+ "copy": "Copy",
+ "throttle": "Throttle · 3 seconds",
+ "debounce": "Debounce · 3 seconds",
+ "calls": "Actual calls",
+ "run": "Trigger",
+ "disabled": "Disable interaction",
+ "nativeForm": "Native form",
+ "text": "Text selection",
+ "naive": "Naive UI controls",
+ "formInput": "Example input",
+ "submit": "Submit"
+ },
+ "chart": {
+ "sales": "Weekly sales trend",
+ "mount": "Render chart",
+ "dispose": "Dispose chart",
+ "update": "Refresh data",
+ "stopLoading": "Hide loading",
+ "showLoading": "Show loading",
+ "fixedTheme": "Fixed theme",
+ "pattern": "Show decals",
+ "hidePattern": "Hide decals",
+ "series": "Data state",
+ "revision": "Data revision {value}",
+ "unmounted": "Chart disposed"
+ },
+ "about": {
+ "title": "About Ray Template",
+ "intro": "Inspect the pinned dependency versions from the project manifest.",
+ "group": "Dependency group",
+ "runtime": "Runtime",
+ "development": "Development",
+ "search": "Search package names",
+ "noMatch": "No matching packages"
+ }
+}
diff --git a/src/locales/lang/en-US/showcase.json b/src/locales/lang/en-US/showcase.json
index fbdd4148..35226ba6 100644
--- a/src/locales/lang/en-US/showcase.json
+++ b/src/locales/lang/en-US/showcase.json
@@ -15,5 +15,43 @@
"layoutEyebrow": "WORKSPACE / LAYOUT",
"iconsEyebrow": "ASSETS / ICONS",
"livePreferences": "Live preview · Saved automatically",
- "layoutControls": "Layout & display"
+ "layoutControls": "Layout & display",
+ "detailTitle": "Person details",
+ "multiOneTitle": "First-level menu example",
+ "multiOtherTitle": "Sibling menu example",
+ "multiNestedTitle": "Deep menu example",
+ "axiosDescription": "Compare manual requests, throttling and debouncing, and inspect each response.",
+ "precisionDescription": "Edit the numeric tags to explore decimal arithmetic and allocation. Examples use eight decimal places.",
+ "barcodeDescription": "Compare sizing, colors and encoding formats. Edit the text to see the barcode update.",
+ "qrcodeDescription": "Compare basic QR codes, loading states and reactive content.",
+ "formDescription": "Fill in the sample form to try field validation, reset and submission.",
+ "modalDescription": "Try draggable, full-screen, custom-width and programmatic dialogs.",
+ "directiveDescription": "Try truncation, copying, ripples, disabling and event rate limiting in one place.",
+ "contextDescription": "Right-click the area below to explore menu positioning and available actions.",
+ "iframeDescription": "Compare lazy and eager iframes to see when external content loads.",
+ "cacheDescription": "Enter a key and value to compare session and local storage.",
+ "flowDescription": "Drag nodes to rearrange the graph and switch to read-only mode to compare behavior.",
+ "dragDescription": "Open a floating card to compare starting positions and drag boundaries.",
+ "chartDescription": "Explore chart themes, loading states and custom rendering.",
+ "detailDescription": "This view adds a breadcrumb to the existing tab. Use navigation above to return to the list.",
+ "aboutDescription": "See the project version, maintenance links and dependencies.",
+ "multiOneDescription": "Switch between nested routes to observe view caching and form state.",
+ "multiOtherDescription": "Open sibling views in the sidebar to inspect their breadcrumb hierarchy.",
+ "multiNestedDescription": "Inspect navigation and view caching for a deeply nested route.",
+ "iframeTitle": "Embedded content",
+ "segmentTitle": "Segment",
+ "segmentDescription": "Switch widths and sizes to see the capsule move across segments with icons, hints and disabled options.",
+ "segmentOverview": "Overview",
+ "segmentReports": "Detailed reports",
+ "segmentPopover": "A contextual hint for this segment.",
+ "segmentDisabled": "Unavailable",
+ "segmentPlayground": "Playground",
+ "segmentWidth": "Width",
+ "segmentSize": "Size",
+ "segmentSelected": "Selected · {value}",
+ "segmentUncontrolled": "Default selection",
+ "segmentCustom": "Custom tab",
+ "segmentCustomLabel": "02 / Custom",
+ "scrollDescription": "Scroll to see cards fade and slide into view.",
+ "scrollCard": "Scroll example {index}"
}
diff --git a/src/locales/lang/zh-CN/demoDetails.json b/src/locales/lang/zh-CN/demoDetails.json
new file mode 100644
index 00000000..a65c3c3e
--- /dev/null
+++ b/src/locales/lang/zh-CN/demoDetails.json
@@ -0,0 +1,219 @@
+{
+ "result": "结果",
+ "empty": "暂无数据",
+ "loading": "加载中",
+ "precision": {
+ "title": "数字精度",
+ "intro": "编辑操作数,对照八位小数的计算结果。",
+ "add": "加法",
+ "subtract": "减法",
+ "multiply": "乘法",
+ "divide": "除法",
+ "invalid": "请输入有效小数。",
+ "zero": "除数不能为 0。",
+ "allocation": "等额分配",
+ "amount": "金额",
+ "parts": "份数"
+ },
+ "cache": {
+ "title": "缓存实验室",
+ "intro": "对同一个键读写并比较两种存储范围。",
+ "write": "写入",
+ "read": "读取",
+ "remove": "删除",
+ "scope": "存储范围",
+ "key": "键名",
+ "value": "值",
+ "missing": "这个键还没有值"
+ },
+ "form": {
+ "title": "表单校验",
+ "intro": "填写档案后提交,右侧会显示实际提交的数据。",
+ "profile": "档案",
+ "name": "姓名",
+ "age": "年龄",
+ "date": "出生日期",
+ "gender": "性别",
+ "female": "女",
+ "male": "男",
+ "notes": "备注",
+ "submit": "提交档案",
+ "validateName": "仅校验姓名",
+ "clear": "清除校验",
+ "reset": "重置",
+ "payload": "提交数据",
+ "waiting": "等待提交",
+ "submitted": "提交成功",
+ "invalid": "请检查标记的字段",
+ "nameValid": "姓名校验通过",
+ "nameRequired": "请输入姓名",
+ "ageRequired": "请输入 0 至 120 岁的年龄",
+ "dateRequired": "请选择出生日期",
+ "genderRequired": "请选择性别",
+ "sample": "填入样例"
+ },
+ "request": {
+ "title": "请求实验室",
+ "intro": "查看手动请求的返回值,连续输入对比节流和防抖的实际发送次数。",
+ "fixture": "本地演示数据",
+ "fetch": "获取工单",
+ "city": "按城市查询",
+ "selectCity": "选择示例城市",
+ "waiting": "等待请求",
+ "failed": "请求失败,可重试",
+ "throttle": "节流 · 1 秒",
+ "debounce": "防抖 · 1 秒",
+ "sent": "已发送 {count} 次",
+ "input": "连续输入",
+ "last": "最近响应"
+ },
+ "iframe": {
+ "title": "嵌入内容",
+ "intro": "用同一个本地页面观察两种加载策略。",
+ "eager": "立即加载",
+ "lazy": "延迟加载",
+ "loaded": "已加载",
+ "pending": "等待加载",
+ "mount": "挂载延迟加载示例"
+ },
+ "modal": {
+ "title": "模态框",
+ "intro": "打开不同预设,试试拖拽、全屏和指定宽度。",
+ "card": "卡片",
+ "dialog": "对话框",
+ "fullscreen": "全屏",
+ "record": "示例工单",
+ "open": {
+ "card": "打开卡片",
+ "dialog": "打开对话框",
+ "fullscreen": "进入全屏"
+ },
+ "width": "卡片宽度",
+ "applyWidth": "按指定宽度打开",
+ "createCard": "命令式创建卡片",
+ "createDialog": "命令式创建对话框",
+ "last": "最近关闭"
+ },
+ "qr": {
+ "title": "二维码",
+ "intro": "输入内容并切换二维码样式,预览会随输入更新。",
+ "controls": "生成设置",
+ "content": "二维码内容",
+ "brand": "居中头像",
+ "status": "显示状态",
+ "ready": "正常",
+ "loading": "加载中",
+ "error": "已过期",
+ "download": "下载二维码",
+ "preview": "扫码预览",
+ "expired": "二维码已过期",
+ "reload": "重新启用",
+ "failed": "二维码生成失败",
+ "noText": "输入内容后生成",
+ "animated": "动态背景"
+ },
+ "barcode": {
+ "title": "条形码",
+ "intro": "切换编码格式并修改样例值,查看即时预览。",
+ "controls": "编码设置",
+ "format": "编码格式",
+ "content": "条码内容",
+ "color": "自定义颜色",
+ "responsive": "响应式宽度",
+ "preview": "条码预览",
+ "invalid": "内容不符合当前编码格式。"
+ },
+ "flow": {
+ "title": "流程图",
+ "intro": "拖动节点后读取画布数据,或切换只读模式。",
+ "review": "审核",
+ "done": "完成",
+ "canvas": "流程画布",
+ "readonly": "只读",
+ "editable": "可编辑",
+ "fit": "适应画布",
+ "reset": "重置画布",
+ "inspect": "读取图数据",
+ "graph": "当前图数据"
+ },
+ "drag": {
+ "title": "拖拽卡片",
+ "intro": "从指定位置打开卡片,比较容器内拖拽和页面范围拖拽。",
+ "stage": "拖拽试验台",
+ "position": "初始位置",
+ "enable": "允许拖拽",
+ "locked": "拖拽已锁定",
+ "bounded": "容器内卡片",
+ "body": "页面范围卡片",
+ "bounds": "容器拖拽边界"
+ },
+ "context": {
+ "title": "右键菜单",
+ "intro": "右击工作区打开菜单,也可用按钮选择操作。",
+ "target": "工单操作区",
+ "open": "打开操作菜单",
+ "last": "最近选择",
+ "review": "标记待审核",
+ "archive": "归档",
+ "restore": "恢复"
+ },
+ "nested": {
+ "draft": "草稿",
+ "note": "临时备注",
+ "route": "当前路由"
+ },
+ "detail": {
+ "name": "姓名",
+ "address": "地址",
+ "phone": "电话",
+ "action": "操作",
+ "open": "查看详情",
+ "back": "返回人员列表",
+ "missing": "请从列表选择一条记录。",
+ "params": "路由参数"
+ },
+ "directive": {
+ "ripple": "点击涟漪",
+ "ripplePointer": "从点击位置扩散",
+ "rippleCenter": "从中心扩散",
+ "ellipsis": "文本省略",
+ "single": "单行",
+ "multi": "多行",
+ "copy1": "复制文本",
+ "copy2": "复制自定义内容",
+ "copy": "复制",
+ "throttle": "节流 · 3 秒",
+ "debounce": "防抖 · 3 秒",
+ "calls": "实际执行次数",
+ "run": "触发",
+ "disabled": "禁用交互",
+ "nativeForm": "原生表单",
+ "text": "文本选择",
+ "naive": "Naive UI 控件",
+ "formInput": "示例输入框",
+ "submit": "提交"
+ },
+ "chart": {
+ "sales": "每周销售趋势",
+ "mount": "渲染图表",
+ "dispose": "卸载图表",
+ "update": "更新数据",
+ "stopLoading": "关闭加载",
+ "showLoading": "显示加载",
+ "fixedTheme": "固定主题示例",
+ "pattern": "显示贴花",
+ "hidePattern": "隐藏贴花",
+ "series": "数据状态",
+ "revision": "数据版本 {value}",
+ "unmounted": "已卸载"
+ },
+ "about": {
+ "title": "关于 Ray Template",
+ "intro": "从项目清单查看实际锁定的依赖版本。",
+ "group": "依赖分组",
+ "runtime": "生产依赖",
+ "development": "开发依赖",
+ "search": "搜索依赖名称",
+ "noMatch": "没有匹配的依赖"
+ }
+}
diff --git a/src/locales/lang/zh-CN/showcase.json b/src/locales/lang/zh-CN/showcase.json
index 67e04164..f684dfef 100644
--- a/src/locales/lang/zh-CN/showcase.json
+++ b/src/locales/lang/zh-CN/showcase.json
@@ -15,5 +15,43 @@
"layoutEyebrow": "WORKSPACE / LAYOUT",
"iconsEyebrow": "ASSETS / ICONS",
"livePreferences": "即时预览 · 自动保存",
- "layoutControls": "布局与显示"
+ "layoutControls": "布局与显示",
+ "detailTitle": "人员详情",
+ "multiOneTitle": "一级菜单示例",
+ "multiOtherTitle": "同级菜单示例",
+ "multiNestedTitle": "深层菜单示例",
+ "axiosDescription": "切换请求方式,对比手动执行、节流和防抖,并查看每次请求的结果。",
+ "precisionDescription": "用可编辑的数值标签验证小数运算和均分。示例默认保留八位小数。",
+ "barcodeDescription": "对比响应式、配色和编码格式,输入内容即可查看条形码的变化。",
+ "qrcodeDescription": "对比基础码、状态码和响应式内容,验证二维码从生成到更新的过程。",
+ "formDescription": "填写示例表单,试用字段验证、重置和提交。",
+ "modalDescription": "体验可拖拽、全屏、手动宽度和命令式打开的模态框。",
+ "directiveDescription": "在同一处体验文本省略、复制、涟漪、禁用和事件频率控制。",
+ "contextDescription": "在下方区域右键单击,检查菜单定位和可用操作。",
+ "iframeDescription": "对照延迟加载和立即加载的 iframe,观察外部内容的加载时机。",
+ "cacheDescription": "输入键和值,对比会话与本地缓存的读写。",
+ "flowDescription": "拖动节点调整布局,切换只读模式查看交互行为。",
+ "dragDescription": "在工作区中打开浮动卡片,比较不同初始位置与拖拽范围。",
+ "chartDescription": "对比基础图表、主题切换、加载状态和自定义渲染。",
+ "detailDescription": "这个页面在原标签页中追加面包屑,可使用上方导航回到列表。",
+ "aboutDescription": "了解项目版本、维护入口及使用的依赖。",
+ "multiOneDescription": "在多级菜单之间切换,观察页面缓存与表单状态。",
+ "multiOtherDescription": "通过侧栏进入同组页面,检查多级菜单与面包屑的对应关系。",
+ "multiNestedDescription": "查看深层路由对应的导航路径和页面缓存。",
+ "iframeTitle": "嵌入内容",
+ "segmentTitle": "分段器",
+ "segmentDescription": "切换宽度和尺寸,在带图标、提示和禁用项的分段器中观察选中滑块。",
+ "segmentOverview": "概览",
+ "segmentReports": "详细分析",
+ "segmentPopover": "提示信息跟随该选项。",
+ "segmentDisabled": "不可用",
+ "segmentPlayground": "交互试验台",
+ "segmentWidth": "宽度",
+ "segmentSize": "尺寸",
+ "segmentSelected": "当前选中 · {value}",
+ "segmentUncontrolled": "默认选中项",
+ "segmentCustom": "自定义标签",
+ "segmentCustomLabel": "02 / 自定义",
+ "scrollDescription": "向下滚动,观察卡片进入视口时的淡入和位移。",
+ "scrollCard": "滚动样例 {index}"
}
diff --git a/src/views/demo/axios/index.scss b/src/views/demo/axios/index.scss
deleted file mode 100644
index 5cac4b4e..00000000
--- a/src/views/demo/axios/index.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-.axios-header__btn {
- height: 64px;
-}
diff --git a/src/views/demo/axios/index.tsx b/src/views/demo/axios/index.tsx
index def4323a..4257d0d2 100644
--- a/src/views/demo/axios/index.tsx
+++ b/src/views/demo/axios/index.tsx
@@ -1,165 +1,146 @@
-import './index.scss'
-import { getTypicCode, getWeather } from '@/api/demo/test'
+import {
+ getRequestFixture,
+ getWeather,
+ requestFixtureUrl,
+} from '@/api/demo/test'
import { useHookPlusRequest, useRequest } from '@/axios'
-import { NButton, NCard, NFlex, NInput, NLayout } from 'naive-ui'
+import { useI18n } from '@/hooks'
+import { NButton, NCard, NFormItem, NInput, NSelect, NTag } from 'naive-ui'
+import DemoPage from '../components/DemoPage'
+import DemoResult from '../components/DemoResult'
-const Axios = defineComponent({
+export default defineComponent({
name: 'RAxios',
setup() {
- const state = reactive({
- weatherData: [],
- inputCityValue: null,
- throttleDemoInputValue: null,
- debounceDemoInputValue: null,
- weatherDemoInputValue: null,
- })
-
- const {
- data: throttleDemoValue,
- loading: throttleDemoLoading,
- run: throttleDemoRun,
- } = useHookPlusRequest(getTypicCode, {
- throttleWait: 1000,
- manual: true,
- })
- const {
- data: debounceDemoValue,
- loading: debounceDemoLoading,
- run: debounceDemoRun,
- } = useHookPlusRequest(getTypicCode, {
- debounceWait: 1000,
- manual: true,
- })
- const {
- data: weatherDemoValue,
- loading: weatherDemoLoading,
- run: weatherDemoRun,
- } = useHookPlusRequest(getWeather, {
- throttleWait: 1000,
- manual: true,
- })
- const {
- data: demoData,
- loading: demoLoading,
- run: demoRun,
- } = useRequest<{
- title: string
- }>(
- {
- url: 'https://jsonplaceholder.typicode.com/todos/1',
- method: 'get',
- cancelConfig: {
- cancel: true,
- },
- },
- {
- manual: true,
- onError: () => {
- window.$message.error('接口出现异常')
- },
- },
+ const { t } = useI18n('demoDetails')
+ const manual = useRequest>>(
+ { url: requestFixtureUrl, method: 'get', cancelConfig: { cancel: true } },
+ { manual: true },
)
+ const city = ref(null)
+ const weather = useHookPlusRequest(getWeather, { manual: true })
+ const cities = ['Hangzhou', 'Shanghai', 'Chengdu'].map((value) => ({
+ value,
+ label: value,
+ }))
+ const rateDemos = (['throttle', 'debounce'] as const).map((kind) => {
+ const input = ref('')
+ const sent = ref(0)
+ const inputId = useId()
+ const query = useHookPlusRequest(
+ async (value: string) => {
+ sent.value += 1
+ const { ticket } = await getRequestFixture()
- return {
- ...toRefs(state),
- throttleDemoValue,
- throttleDemoLoading,
- throttleDemoRun,
- debounceDemoValue,
- debounceDemoLoading,
- debounceDemoRun,
- weatherDemoValue,
- weatherDemoLoading,
- weatherDemoRun,
- demoData,
- demoLoading,
- demoRun,
- }
- },
- render() {
- return (
-
-
- 请求
-
- useRequest
- 支持配置化请求数据
- useHookPlusRequest
-
- 支持包裹一个拥有 promise 状态的异步函数,可以用来包裹一个 axios
- 请求返回值方法
-
+ return { value, ticket: ticket.id }
+ },
+ {
+ manual: true,
+ ...(kind === 'throttle'
+ ? { throttleWait: 1000 }
+ : { debounceWait: 1000 }),
+ },
+ )
+
+ return { kind, input, sent, inputId, query }
+ })
+
+ return () => (
+
+
+
+
+
manual.run()}>
+ {t('request.fetch')}
+
+
+ {manual.loading.value ? (
+ t('loading')
+ ) : manual.error.value ? (
+ t('request.failed')
+ ) : manual.data.value ? (
+ {JSON.stringify(manual.data.value.ticket, null, 2)}
+ ) : (
+ t('request.waiting')
+ )}
+
+
-
使用 useRequest 获取
-
-
- 1.基于 axios 封装,能够自动取消连续请求,避免重复渲染造成问题
-
-
- 2.打开控制台 => 网络 => 使用低速3g网络 =>
- 查看控制台被取消的请求
-
- 3.详情请查看文档
-
-
-
- 获取数据
-
- 结果:
- {this.demoLoading ? '获取中...' : this.demoData?.title}
-
-
-
-
使用 useHookPlusRequest 获取
-
-
- {
- this.throttleDemoRun()
+
+
+ {
+ city.value = value
+ weather.run(value)
}}
/>
- 不论触发多少次,一秒钟之内仅会触发一次
-
- 当前状态:
- {this.throttleDemoLoading ? '获取中...' : '获取成功!!!'}
-
-
+
+ {weather.loading.value
+ ? t('loading')
+ : weather.error.value
+ ? t('request.failed')
+ : weather.data.value
+ ? `${weather.data.value.temperature} °C · ${weather.data.value.humidity}% RH`
+ : t('request.waiting')}
+
+
-
-
- {
- this.debounceDemoRun()
- }}
- />
- 一秒后才会执行,如果中途重新请求,则会重新计时
-
- 当前状态:
- {this.debounceDemoLoading ? '获取中...' : '获取成功!!!'}
-
-
-
-
-
- {
- this.weatherDemoRun(val)
- }}
- />
- 该示例演示了如何根据动态值获取数据
-
- 当前状态:
- {this.weatherDemoLoading ? '获取中...' : '获取成功!!!'}
-
-
-
-
-
+ {rateDemos.map(({ kind, input, sent, inputId, query }) => (
+
+ {{
+ 'header-extra': () => (
+
+ {t('request.sent', { count: sent.value })}
+
+ ),
+ default: () => (
+
+
+ {
+ input.value = value
+
+ if (value.trim()) query.run(value)
+ else query.cancel()
+ }}
+ />
+
+
+ {query.loading.value ? (
+ t('loading')
+ ) : query.error.value ? (
+ t('request.failed')
+ ) : query.data.value ? (
+
+ {query.data.value.value} · {query.data.value.ticket}
+
+ ) : (
+ t('request.waiting')
+ )}
+
+
+ ),
+ }}
+
+ ))}
+
+
)
},
})
-
-export default Axios
diff --git a/src/views/demo/barcode-demo.tsx b/src/views/demo/barcode-demo.tsx
index 9251d997..225e11c7 100644
--- a/src/views/demo/barcode-demo.tsx
+++ b/src/views/demo/barcode-demo.tsx
@@ -1,133 +1,121 @@
import { RBarcode } from '@/components'
-import {
- NAlert,
- NCard,
- NFlex,
- NGrid,
- NGridItem,
- NInput,
- NSwitch,
-} from 'naive-ui'
+import { useI18n } from '@/hooks'
+import { NCard, NFlex, NFormItem, NInput, NSelect, NSwitch } from 'naive-ui'
+import DemoPage from './components/DemoPage'
+import DemoResult from './components/DemoResult'
+
+const samples = {
+ CODE128: 'RAY-024',
+ pharmacode: '1234',
+ codabar: 'A1234B',
+} as const
+const formats = Object.keys(samples).map((value) => ({ value, label: value }))
export default defineComponent({
name: 'BarcodeDemo',
setup() {
- const baseOptions = {
- width: 4,
- }
+ const { t } = useI18n('demoDetails')
+ const format = ref('CODE128')
+ const text = ref(samples.CODE128)
const loading = ref(false)
- const text = ref('RayTemplate')
+ const colored = ref(false)
+ const responsive = ref(false)
+ const failed = ref(false)
+ const id = useId()
- return {
- baseOptions,
- loading,
- text,
- }
- },
- render() {
- const { baseOptions } = this
-
- return (
-
-
-
- 点击查看详细配置项:
-
- js-barcode options
-
- 。
+ return () => (
+
+
+
+
+
+ {
+ format.value = value
+ text.value = samples[value]
+ failed.value = false
+ }}
+ />
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+ {text.value.trim() && (
+ {
+ failed.value = false
+ }}
+ onError={() => {
+ failed.value = true
+ }}
+ />
+ )}
+
+
+ {failed.value ? (
+ t('barcode.invalid')
+ ) : text.value.trim() ? (
+ {text.value}
+ ) : (
+ t('empty')
+ )}
+
+
-
-
-
-
-
-
-
-
-
-
- 该模式下,条形码只能渲染有效数值,否则将会渲染失败。可以查看官网说明:
-
- pharmacode
-
- 。
-
-
-
-
-
-
-
-
-
- 该模式下,需要注意 text 中的特殊字符,可以查看官网说明:
-
- codabar
-
- 。
-
-
-
-
-
-
-
-
-
- {{
- checked: () => 'loading...',
- unchecked: () => 'success!',
- }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
)
},
})
diff --git a/src/views/demo/cache-demo/index.tsx b/src/views/demo/cache-demo/index.tsx
index 16c296d0..279bd76a 100644
--- a/src/views/demo/cache-demo/index.tsx
+++ b/src/views/demo/cache-demo/index.tsx
@@ -1,101 +1,117 @@
+import { useI18n } from '@/hooks'
import { getStorage, hasStorage, removeStorage, setStorage } from '@/utils'
import {
NButton,
NCard,
NFlex,
+ NFormItem,
NInput,
- NInputGroup,
- NInputGroupLabel,
+ NRadioButton,
+ NRadioGroup,
} from 'naive-ui'
+import DemoPage from '../components/DemoPage'
+import DemoResult from '../components/DemoResult'
export default defineComponent({
name: 'CacheDemo',
setup() {
- const nameValue = ref('Ray')
- const currentPrefix = ref('ray:')
+ const { t } = useI18n('demoDetails')
+ const value = ref('Ray')
+ const scope = ref<'sessionStorage' | 'localStorage'>('sessionStorage')
+ const suffix = ref('name')
+ const selectedKey = computed(() => `ray:showcase:${suffix.value.trim()}`)
+ const current = ref(null)
+ const operation = ref('cache.read')
+ const keyId = useId()
+ const valueId = useId()
- return {
- nameValue,
- currentPrefix,
+ const read = () => {
+ current.value = hasStorage(selectedKey.value, scope.value)
+ ? getStorage(selectedKey.value, scope.value)
+ : null
}
- },
- render() {
- return (
-
- {{
- default: () => (
-
- 点击 setStorage 按钮,设置缓存示例
-
- 设置缓存内容
+
+ watch([selectedKey, scope], read, { immediate: true })
+
+ return () => (
+
+
+
+
+
+
+ sessionStorage
+
+ localStorage
+
+
-
-
- 设置前缀
+
+
-
-
- ),
- action: () => (
-
- {
- setStorage('name', this.nameValue, 'sessionStorage', {
- prefix: true,
- prefixKey: this.currentPrefix,
- })
-
- window.$message.success('设置成功')
- }}
- >
- setStorage
-
- {
- const name = getStorage('name', 'sessionStorage', {
- prefix: true,
- prefixKey: this.currentPrefix,
- })
-
- window.$message.success(`获取到的姓名为:${name}`)
- }}
- >
- getStorage
-
- {
- removeStorage('name', 'sessionStorage', {
- prefix: true,
- prefixKey: this.currentPrefix,
- })
-
- window.$message.success('删除成功')
- }}
- >
- removeStorage
-
- {
- const cacheKey = hasStorage('name', 'sessionStorage', {
- prefix: true,
- prefixKey: this.currentPrefix,
- })
-
- window.$message.success(`是否存在:${cacheKey}`)
- }}
- >
- hasStorage
-
-
- ),
- }}
-
+
+
+ {
+ setStorage(selectedKey.value, value.value, scope.value)
+ operation.value = 'cache.write'
+ read()
+ }}
+ >
+ {t('cache.write')}
+
+ {
+ operation.value = 'cache.read'
+ read()
+ }}
+ >
+ {t('cache.read')}
+
+ {
+ removeStorage(selectedKey.value, scope.value)
+ operation.value = 'cache.remove'
+ read()
+ }}
+ >
+ {t('cache.remove')}
+
+
+
+
+
+
+ {selectedKey.value}
+
+ {current.value === null
+ ? t('cache.missing')
+ : JSON.stringify(current.value)}
+
+
+
+
+
)
},
})
diff --git a/src/views/demo/components/CacheRouteExample.tsx b/src/views/demo/components/CacheRouteExample.tsx
new file mode 100644
index 00000000..8bf8bddc
--- /dev/null
+++ b/src/views/demo/components/CacheRouteExample.tsx
@@ -0,0 +1,58 @@
+import { useI18n } from '@/hooks'
+import { NButton, NCard, NFormItem, NInput, NTag } from 'naive-ui'
+import DemoPage from './DemoPage'
+import DemoResult from './DemoResult'
+
+export default defineComponent({
+ name: 'CacheRouteExample',
+ props: {
+ title: { type: String, required: true },
+ description: { type: String, required: true },
+ },
+ setup(props) {
+ const { t } = useI18n('demoDetails')
+ const route = useRoute()
+ const note = ref('')
+ const id = useId()
+
+ return () => (
+
+
+
+
+
+
+
+ {
+ note.value = ''
+ }}
+ >
+ {t('form.reset')}
+
+
+
+
+
+ {route.path}
+
+ KeepAlive
+
+
+ {note.value || t('empty')}
+
+
+
+
+
+ )
+ },
+})
diff --git a/src/views/demo/components/DemoResult.tsx b/src/views/demo/components/DemoResult.tsx
new file mode 100644
index 00000000..3efe6ba5
--- /dev/null
+++ b/src/views/demo/components/DemoResult.tsx
@@ -0,0 +1,18 @@
+export default defineComponent({
+ name: 'DemoResult',
+ props: {
+ label: { type: String, required: true },
+ error: Boolean,
+ },
+ setup(props, { slots }) {
+ return () => (
+
+
{props.label}
+
{slots.default?.()}
+
+ )
+ },
+})
diff --git a/src/views/demo/components/index.scss b/src/views/demo/components/index.scss
index bf44cdb9..f47501c2 100644
--- a/src/views/demo/components/index.scss
+++ b/src/views/demo/components/index.scss
@@ -80,3 +80,143 @@
grid-template-columns: minmax(300px, 0.9fr) minmax(0, 1.1fr);
}
}
+
+.r-demo-grid {
+ display: grid;
+ grid-template-columns: minmax(0, 1fr);
+ align-items: stretch;
+ gap: 20px;
+
+ > * {
+ min-inline-size: 0;
+ }
+
+ &__wide {
+ grid-column: 1 / -1;
+ }
+}
+
+@container (min-width: 760px) {
+ .r-demo-grid {
+ grid-template-columns: repeat(2, minmax(0, 1fr));
+ }
+}
+
+.r-demo-stage {
+ display: grid;
+ min-block-size: 220px;
+ place-items: center;
+ padding: 20px;
+ border: 1px dashed var(--r-control-border);
+ border-radius: var(--r-radius);
+ background-color: var(--r-surface-muted);
+ background-image: radial-gradient(
+ var(--r-control-border) 0.6px,
+ transparent 0.6px
+ );
+ background-size: 16px 16px;
+ color: var(--r-text);
+ text-align: center;
+
+ &--drag {
+ min-block-size: 380px;
+ margin-block-end: 20px;
+ }
+}
+
+.r-demo-card-stack {
+ display: grid;
+ gap: 16px;
+ min-width: 0;
+}
+
+.r-demo-artifact {
+ display: grid;
+ place-items: center;
+ min-width: 0;
+ min-height: 150px;
+ padding: 12px;
+ border: 1px solid var(--r-line);
+ border-radius: 10px;
+ background: #fff;
+ color: #182436;
+ overflow: auto;
+
+ > * {
+ max-inline-size: 100%;
+ }
+}
+
+.r-demo-result {
+ min-width: 0;
+ display: grid;
+ gap: 6px;
+ padding: 12px 14px;
+ border: 1px solid var(--r-line);
+ border-radius: 8px;
+ background: var(--r-surface-muted);
+ color: var(--r-text);
+
+ &--error {
+ border-inline-start: 3px solid #d05055;
+ }
+
+ &__label {
+ color: var(--r-text-secondary);
+ font-size: 12px;
+ font-weight: 600;
+ }
+
+ &__value {
+ overflow-wrap: anywhere;
+ font-variant-numeric: tabular-nums;
+
+ pre {
+ margin: 0;
+ white-space: pre-wrap;
+ font-family: var(--r-font-mono);
+ }
+ }
+}
+
+.r-demo-modal-sketch {
+ min-height: 112px;
+ display: grid;
+ place-items: center;
+ border-radius: 8px;
+ background: var(--r-canvas);
+
+ span {
+ inline-size: 60%;
+ block-size: 68px;
+ border: 1px solid var(--r-control-border);
+ border-block-start: 10px solid var(--r-theme-primary-color);
+ border-radius: 5px;
+ background: var(--r-surface);
+ }
+
+ &--dialog span {
+ inline-size: 40%;
+ block-size: 50px;
+ }
+
+ &--fullscreen span {
+ inline-size: calc(100% - 16px);
+ block-size: 96px;
+ }
+}
+
+.r-demo-artifact--barcode {
+ grid-template-columns: minmax(0, 1fr);
+
+ svg {
+ max-inline-size: 100%;
+ }
+}
+
+.r-demo-flow-canvas {
+ min-width: 0;
+ overflow: hidden;
+ border: 1px solid var(--r-line);
+ border-radius: 8px;
+}
diff --git a/src/views/demo/context-menu/index.tsx b/src/views/demo/context-menu/index.tsx
index d78f5702..e9fca4c4 100644
--- a/src/views/demo/context-menu/index.tsx
+++ b/src/views/demo/context-menu/index.tsx
@@ -1,81 +1,59 @@
-import { useContextmenuCoordinate } from '@/hooks'
-import { NCard, NDropdown, NFlex } from 'naive-ui'
+import { useContextmenuCoordinate, useI18n } from '@/hooks'
+import { NButton, NCard, NDropdown } from 'naive-ui'
+import DemoPage from '../components/DemoPage'
+import DemoResult from '../components/DemoResult'
+
+const actions = ['review', 'archive', 'restore'] as const
export default defineComponent({
name: 'ContextMenuDemo',
setup() {
- const demoOneRef = ref()
- const demoOneShow = ref(false)
- const options = ref([
- {
- label: '杰·盖茨比',
- key: 'jay gatsby',
- },
- {
- label: '黛西·布坎南',
- key: 'daisy buchanan',
- },
- {
- type: 'divider',
- key: 'd1',
- },
- {
- label: '尼克·卡拉威',
- key: 'nick caraway',
- },
- ])
-
- const { x, y, show, updateShow } = useContextmenuCoordinate(demoOneRef)
-
- const clickOutside = (e: MouseEvent) => {
- e.preventDefault()
-
+ const { t } = useI18n('demoDetails')
+ const stage = useTemplateRef('stage')
+ const { x, y, show, updateShow } = useContextmenuCoordinate(stage, {
+ ignore: ['.r-demo-context-popup'],
+ })
+ const selected = ref()
+ const options = computed(() =>
+ actions.map((key) => ({ key, label: t(`context.${key}`) })),
+ )
+ const select = (key: string) => {
+ selected.value = key
updateShow(false)
}
- return {
- demoOneRef,
- demoOneShow,
- x,
- y,
- show,
- options,
- clickOutside,
- updateShow,
- }
- },
- render() {
- const { x, y, show } = this
- const { clickOutside, updateShow } = this
-
- return (
-
-
-
- 默认点击元素外部会关闭菜单。
-
- 右击
+ return () => (
+
+
+
+
+
+ {t('context.target')}
+
+ {t('context.open')}
+
+
-
+
+ {selected.value ? t(`context.${selected.value}`) : t('empty')}
+
+
{
- window.$message.info(`选中了 ${option.label}`)
-
- updateShow(false)
- }}
- onClickoutside={clickOutside.bind(this)}
+ menuProps={() => ({ class: 'r-demo-context-popup' })}
+ onSelect={select}
+ onClickoutside={() => updateShow(false)}
/>
-
+
)
},
})
diff --git a/src/views/demo/directive/index.tsx b/src/views/demo/directive/index.tsx
index 7df25d24..b6936b5f 100644
--- a/src/views/demo/directive/index.tsx
+++ b/src/views/demo/directive/index.tsx
@@ -10,8 +10,9 @@ import {
NInputGroup,
NInputNumber,
NSwitch,
- NTag,
} from 'naive-ui'
+import DemoPage from '../components/DemoPage'
+import DemoResult from '../components/DemoResult'
const RDirective = defineComponent({
name: 'RDirective',
@@ -22,6 +23,7 @@ const RDirective = defineComponent({
throttleBtnClickCount: 0,
debounceBtnClickCount: 0,
disabledValue: false,
+ formCount: 0,
})
const ellipsisLineClamp = ref(2)
@@ -39,163 +41,173 @@ const RDirective = defineComponent({
},
render() {
return (
-
- 该页面展示如何使用已封装好的指令
-
-
-
-
- 你可以手动显示的声明水波纹效果,默认为 circle。你可以手动的声明为
- center。
-
-
- "v-ripple.center" 或者 "v-ripple.circle"。
-
-
- {JSON.stringify(`v-ripple={[true, ['center']]}`)} 或者
- {JSON.stringify(`v-ripple={[true, ['circle']]}`)}。
-
-
-
- 水波纹效果的Tag
-
-
- 水波纹效果的Tag
-
-
- 水波纹效果的Tag
-
-
- 水波纹效果的Button
-
-
- 原生元素绑定水波纹效果,并且手动绑定 modifiers 为 center
-
+
+
+
+
+
+
+ {this.$t('demoDetails.directive.ripplePointer')}
+
+
+ {this.$t('demoDetails.directive.rippleCenter')}
+
+
-
-
-
-
-
-
- 我是一段很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长的文本。
-
-
-
-
-
- 该方法基于非标准属性实现(-webkit-line-clamp),可能会有兼容性问题,所以请谨慎使用。
- 详情参考:
- can i use
-
+
+
+
+
我是一段很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长的文本。
-
-
-
-
-
-
-
-
- 复制
-
-
-
-
-
- 复制
-
-
-
-
-
- 点击执行
-
- 我执行了{this.throttleBtnClickCount}次
- 该方法 3s 内仅会执行一次
-
-
-
-
-
- 点击执行
-
- 我执行了{this.debounceBtnClickCount}次
- 该方法将延迟 3s 执行
-
-
-
-
-
- {{
- checked: () => '取消',
- unchecked: () => '禁用',
- }}
-
-
-
- 该指令会强制禁用(通过 css 层面)禁用元素交互。但是 naive ui
- 组件提供了完整的 disabled
- 属性,所以在组件库有禁用需求时,直接调用组件库 disabled
- 属性即可。但是值得注意的是,该指令优先级最高,会覆盖组件
- disabled 属性。
-
-
-
-
-
-
-
- 我是可以被禁用的文本内容
-
-
-
-
-
-
-
-
-
- 按钮
-
-
-
-
-
-
+
+
+
+
+ 该方法基于非标准属性实现(-webkit-line-clamp),可能会有兼容性问题,所以请谨慎使用。
+ 详情参考:
+
+ can i use
+
+
+
+ 我是一段很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长的文本。
+
+
+
+
+
+
+
+
+
+
+ {this.$t('demoDetails.directive.copy')}
+
+
+
+
+
+
+
+ {this.$t('demoDetails.directive.copy')}
+
+
+
+
+
+
+ {this.$t('demoDetails.directive.run')}
+
+
+ {this.throttleBtnClickCount}
+
+
+
+
+
+
+ {this.$t('demoDetails.directive.run')}
+
+
+ {this.debounceBtnClickCount}
+
+
+
+
+
+
+ {{
+ checked: () => '取消',
+ unchecked: () => '禁用',
+ }}
+
+
+
+
+ {this.formCount}
+
+
+
+
+
+ 我是可以被禁用的文本内容
+
+
+
+
+
+
+
+
+
+
+ 按钮
+
+
+
+
+
+
+
)
},
})
diff --git a/src/views/demo/draggable-card.tsx b/src/views/demo/draggable-card.tsx
index aad78898..edab336d 100644
--- a/src/views/demo/draggable-card.tsx
+++ b/src/views/demo/draggable-card.tsx
@@ -1,97 +1,92 @@
import { RDraggableCard } from '@/components'
import type { DefaultPosition } from '@/components'
-import { NButton, NCard, NFlex, NRadio, NRadioGroup, NSwitch } from 'naive-ui'
+import { useI18n } from '@/hooks'
+import { NButton, NCard, NFlex, NSelect, NSwitch, NTag } from 'naive-ui'
+import DemoPage from './components/DemoPage'
+
+const positions = [
+ 'center',
+ 'top-center',
+ 'bottom-center',
+ 'top-left',
+ 'top-right',
+ 'bottom-left',
+ 'bottom-right',
+] as const
+const options = positions.map((value) => ({ label: value, value }))
export default defineComponent({
name: 'DraggableCardDemo',
setup() {
- const card3 = ref(false)
- const domRef = useTemplateRef('domRef')
- const positionRadioOptions = [
- { label: 'center', value: 'center' },
- { label: 'top-center', value: 'top-center' },
- { label: 'bottom-center', value: 'bottom-center' },
- { label: 'top-left', value: 'top-left' },
- { label: 'top-right', value: 'top-right' },
- { label: 'bottom-left', value: 'bottom-left' },
- { label: 'bottom-right', value: 'bottom-right' },
- ]
- const positionRadioValue = ref('center')
- const card3Dad = ref(true)
+ const { t } = useI18n('demoDetails')
+ const target = useTemplateRef('target')
+ const position = ref('center')
+ const draggable = ref(true)
+ const scope = ref<'bounded' | 'body' | null>(null)
- return {
- card3,
- card3Dad,
- domRef,
- positionRadioOptions,
- positionRadioValue,
- }
- },
- render() {
- const { card3, domRef, positionRadioOptions } = this
-
- return (
-
-
-
- 我被限制在 body 中。
-
- {card3 ? (
-
(this.card3 = false)}
- defaultPosition={this.positionRadioValue as DefaultPosition}
- dad={this.card3Dad}
- >
- {{
- default: () =>
- '我被限制在红色区域中。并且我支持 NCard 的所有配置与插槽。',
- 'header-extra': () => '其实我就是 NCard 封装的',
- footer: () => '我支持 footer 插槽',
- action: () => '我支持 action 插槽',
- }}
-
- ) : null}
-
-
-
-
- {{
- checked: () => '拖拽',
- unchecked: () => '禁用',
+ return () => (
+
+
+
+
+ {
+ position.value = value
}}
-
-
-
-
- {positionRadioOptions.map((curr) => (
-
- {curr.label}
-
- ))}
-
-
-
+ />
+
+
+ {draggable.value ? t('drag.enable') : t('drag.locked')}
+
(this.card3 = !this.card3)}
+ onClick={() => {
+ scope.value = scope.value === 'bounded' ? null : 'bounded'
+ }}
>
- 点一下试试
+ {t('drag.bounded')}
+
+ {
+ scope.value = scope.value === 'body' ? null : 'body'
+ }}
+ >
+ {t('drag.body')}
-
+
+ {t('drag.bounds')}
+
+
-
+ {scope.value && target.value && (
+ {
+ scope.value = null
+ }}
+ >
+
+ {draggable.value ? t('drag.enable') : t('drag.locked')}
+
+
+ )}
+
)
},
})
diff --git a/src/views/demo/echart/index.scss b/src/views/demo/echart/index.scss
index 5b4631e9..49b4d667 100644
--- a/src/views/demo/echart/index.scss
+++ b/src/views/demo/echart/index.scss
@@ -12,6 +12,6 @@
& .chart--container {
width: 100%;
- height: 500px;
+ height: clamp(300px, 55vh, 500px);
}
}
diff --git a/src/views/demo/echart/index.tsx b/src/views/demo/echart/index.tsx
index ae79a5d2..54d3735c 100644
--- a/src/views/demo/echart/index.tsx
+++ b/src/views/demo/echart/index.tsx
@@ -1,3 +1,5 @@
+import DemoPage from '../components/DemoPage'
+import DemoResult from '../components/DemoResult'
import './index.scss'
import { RChart, useChart } from '@/components'
import type { RChartType } from '@/components'
@@ -23,6 +25,9 @@ const Echart = defineComponent({
const state = reactive({
loading: false,
loading1: false,
+ lineVisible: true,
+ barVisible: true,
+ revision: 1,
})
const baseOptions: GlobalEChartsCoreOption = {
@@ -209,6 +214,7 @@ const Echart = defineComponent({
const mountChart = () => {
if (isDisposed()) {
render()
+ state.lineVisible = true
} else {
window.$message.warning('图表已渲染~')
}
@@ -216,6 +222,7 @@ const Echart = defineComponent({
const unmountChart = () => {
dispose()
+ state.lineVisible = false
}
const updateChartOptions = () => {
@@ -232,6 +239,7 @@ const Echart = defineComponent({
.map(() => createData())
state.loading1 = false
+ state.revision += 1
}, 1000)
}
@@ -259,97 +267,124 @@ const Echart = defineComponent({
this
return (
-
-
- 该组件基于 ECharts, Vueuse 封装。默认做了最佳的优化封装实践。
-
- 开箱即用的优化策略:节流更新图表、异步渲染、自动销毁、贴花、加载、主题、视窗区域渲染、自动更新尺寸等高级特性。
-
-
-
-
- 渲染
- 卸载
-
- 更新配置项
-
- {
- this.loading1 = !this.loading1
- }}
- >
- {`${this.loading1 ? '关闭' : '开启'}`}加载动画
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+ {this.$t('demoDetails.chart.mount')}
+
+
+ {this.$t('demoDetails.chart.dispose')}
+
+
+ {this.$t('demoDetails.chart.update')}
+
{
- if (isDisposed2()) {
- render2()
- } else {
- window.$message.warning('不可以重复渲染图表~')
- }
+ this.loading1 = !this.loading1
}}
>
- 渲染
+ {this.$t(
+ loading1
+ ? 'demoDetails.chart.stopLoading'
+ : 'demoDetails.chart.showLoading',
+ )}
- 卸载
-
-
-
-
- {{
- checked: () => '隐藏加载动画',
- unchecked: () => '显示加载动画',
- }}
-
-
-
-
-
-
-
- {{
- checked: () => '隐藏贴花',
- unchecked: () => '显示贴花',
- }}
-
-
-
-
-
-
+
+ {this.lineVisible
+ ? this.$t('demoDetails.chart.revision', {
+ value: this.revision,
+ })
+ : this.$t('demoDetails.chart.unmounted')}
+
+
+
+
+
+ {
+ if (isDisposed2()) {
+ render2()
+ this.barVisible = true
+ } else {
+ window.$message.warning('不可以重复渲染图表~')
+ }
+ }}
+ >
+ {this.$t('demoDetails.chart.mount')}
+
+ {
+ dispose2()
+ this.barVisible = false
+ }}
+ >
+ {this.$t('demoDetails.chart.dispose')}
+
+
+
+
+
+
+
+
+
+ {{
+ checked: () => this.$t('demoDetails.chart.stopLoading'),
+ unchecked: () => this.$t('demoDetails.chart.showLoading'),
+ }}
+
+
+
+
+
+
+
+ {{
+ checked: () => this.$t('demoDetails.chart.hidePattern'),
+ unchecked: () => this.$t('demoDetails.chart.pattern'),
+ }}
+
+
+
+
+
+
+
)
},
})
diff --git a/src/views/demo/flow-demo.tsx b/src/views/demo/flow-demo.tsx
index b0913568..c1c6f5ee 100644
--- a/src/views/demo/flow-demo.tsx
+++ b/src/views/demo/flow-demo.tsx
@@ -1,86 +1,97 @@
-import { RFlow, RForm, useFlow } from '@/components'
-import type { FlowGraphData } from '@/components'
-import { NCard, NFlex, NFormItemGridItem, NGrid, NSwitch } from 'naive-ui'
+import { RFlow, useFlow } from '@/components'
+import { useI18n } from '@/hooks'
+import { NButton, NCard, NFlex, NSwitch, NTag } from 'naive-ui'
+import DemoPage from './components/DemoPage'
+import DemoResult from './components/DemoResult'
export default defineComponent({
name: 'RFlowDemo',
setup() {
+ const { t } = useI18n('demoDetails')
const [register, { getFlowInstance }] = useFlow()
- const flowDataRef = ref()
- const settingRef = ref({
- readonly: false,
+ const readonlyMode = ref(false)
+ const canvasKey = ref(0)
+ const ready = ref(false)
+ const output = ref('')
+ const graph = () => ({
+ nodes: [
+ { id: 'review', type: 'rect', x: 100, y: 105, text: t('flow.review') },
+ { id: 'done', type: 'circle', x: 235, y: 215, text: t('flow.done') },
+ ],
+ edges: [
+ {
+ id: 'review-to-done',
+ type: 'polyline',
+ sourceNodeId: 'review',
+ targetNodeId: 'done',
+ },
+ ],
})
- const getInst = () => {
- console.log(getFlowInstance())
-
- window.$message.info('获取实例成功,请在 console 中查看')
- }
-
- setTimeout(() => {
- flowDataRef.value = {
- // 节点
- nodes: [
- {
- id: '21',
- type: 'rect',
- x: 300,
- y: 100,
- text: 'rect node',
- },
- {
- id: '50',
- type: 'circle',
- x: 500,
- y: 100,
- text: 'circle node',
- },
- ],
- // 边
- edges: [
- {
- id: '21',
- type: 'polyline',
- sourceNodeId: '50',
- targetNodeId: '21',
- },
- ],
- }
- }, 1000)
-
- onMounted(() => {
- getInst()
- })
-
- return {
- register,
- flowDataRef,
- settingRef,
- }
- },
- render() {
- const { register, flowDataRef, settingRef } = this
-
- return (
-
-
-
-
-
-
-
-
-
+ return () => (
+
+
+
+
+
+
+ {readonlyMode.value ? t('flow.readonly') : t('flow.editable')}
+
+ getFlowInstance().fitView(24, 24)}
+ >
+ {t('flow.fit')}
+
+ {
+ ready.value = false
+ output.value = ''
+ canvasKey.value += 1
+ }}
+ >
+ {t('flow.reset')}
+
+ {
+ output.value = JSON.stringify(
+ getFlowInstance().getGraphData(),
+ null,
+ 2,
+ )
+ }}
+ >
+ {t('flow.inspect')}
+
+
+
+ {
+ register(flow)
+ flow.render(graph())
+ flow.fitView(24, 24)
+ ready.value = true
+ }}
+ />
+
+ {output.value && (
+
+ {output.value}
+
+ )}
+
-
-
-
-
+
)
},
})
diff --git a/src/views/demo/form/index.tsx b/src/views/demo/form/index.tsx
index 1c04d7d1..33c91dda 100644
--- a/src/views/demo/form/index.tsx
+++ b/src/views/demo/form/index.tsx
@@ -1,5 +1,5 @@
-import { useHookPlusRequest } from '@/axios'
import { RForm, useForm } from '@/components'
+import { useI18n } from '@/hooks'
import {
NButton,
NCard,
@@ -11,186 +11,201 @@ import {
NInputNumber,
NRadio,
NRadioGroup,
- NSwitch,
- NText,
} from 'naive-ui'
+import DemoPage from '../components/DemoPage'
+import DemoResult from '../components/DemoResult'
interface FormModel {
name: string | null
age: number | null
gender: string | null
- date: Date | null
+ date: number | null
remark: string | null
}
export default defineComponent({
name: 'RFormDemo',
setup() {
- // 使用以下 hooks 的时候,应该注意调用时机
+ const { t } = useI18n('demoDetails')
+ const rules = computed(() => ({
+ name: {
+ required: true,
+ message: t('form.nameRequired'),
+ trigger: ['blur', 'change'],
+ key: 'name',
+ },
+ age: {
+ required: true,
+ message: t('form.ageRequired'),
+ trigger: ['blur', 'change'],
+ type: 'number' as const,
+ min: 0,
+ max: 120,
+ },
+ date: {
+ required: true,
+ message: t('form.dateRequired'),
+ trigger: ['blur', 'change'],
+ type: 'number' as const,
+ },
+ gender: {
+ required: true,
+ message: t('form.genderRequired'),
+ trigger: 'change',
+ },
+ }))
const [
register,
{
validate,
restoreValidation,
- formRules,
- reset,
validateTargetField,
- formConditionRef,
+ reset,
+ formConditionRef: model,
},
- ] = useForm(
- {
- name: null,
- age: null,
- gender: null,
- date: null,
- remark: null,
- },
- {
- name: {
- required: true,
- message: '请输入姓名',
- trigger: ['blur', 'change'],
- key: 'name',
- },
- date: {
- required: true,
- message: '请选择日期',
- trigger: ['blur', 'change'],
- type: 'number',
- },
- gender: {
- required: true,
- message: '请选择性别',
- trigger: 'change',
- },
- age: {
- required: true,
- message: '请输入年龄',
- trigger: ['blur', 'change'],
- type: 'number',
- },
- },
- )
+ ] = useForm({
+ name: null,
+ age: null,
+ gender: null,
+ date: null,
+ remark: null,
+ })
+ const ids = { name: useId(), age: useId(), remark: useId() }
+ const submission = ref()
+ const status = ref('form.waiting')
- const formLoading = ref(false)
+ const submit = async (event: Event) => {
+ event.preventDefault()
- const { run: runHookPlusRequest } = useHookPlusRequest(
- () => {
- return new Promise((resolve, reject) => {
- validate()
- .then(() => {
- formLoading.value = true
-
- setTimeout(() => {
- window.$message.success('校验成功')
- resolve(true)
- }, 500)
- })
- .catch(reject)
- .finally(() => {
- formLoading.value = false
- })
- })
- },
- {
- manual: true,
- },
- )
-
- return {
- register,
- formConditionRef,
- restoreValidation,
- validate,
- formRules,
- validateTargetField,
- reset,
- formLoading,
- runHookPlusRequest,
+ try {
+ await validate()
+ submission.value = JSON.stringify(model.value, null, 2)
+ status.value = 'form.submitted'
+ } catch {
+ submission.value = void 0
+ status.value = 'form.invalid'
+ }
}
- },
- render() {
- const { formConditionRef } = this
- const {
- register,
- restoreValidation,
- formRules,
- validateTargetField,
- reset,
- runHookPlusRequest,
- } = this
- return (
- (
-
- useForm 表单校验
-
-
- )}
- >
- {{
- default: () => (
+ return () => (
+
+
+
{
- window.$message.success('表单提交成功')
- }}
- loading={this.formLoading}
+ onSubmit={submit}
>
-
-
-
-
-
-
+
+
-
-
+
+
-
-
- 女
- 男
+
+
+
+
+
+ {t('form.female')}
+ {t('form.male')}
-
+
-
-
- reset()}>
- 重置表单为初始状态
-
-
- 移除校验状态
-
- validateTargetField('name')}
- >
- 仅校验姓名字段
-
-
- 校验
-
-
-
+
+
+ {t('form.submit')}
+
+ {
+ reset({
+ name: 'Ray',
+ age: 28,
+ gender: 'female',
+ date: new Date(1998, 6, 12).getTime(),
+ remark: null,
+ })
+ submission.value = void 0
+ status.value = 'form.waiting'
+ }}
+ >
+ {t('form.sample')}
+
+ {
+ void validateTargetField('name')
+ .then(() => {
+ status.value = 'form.nameValid'
+ })
+ .catch(() => {
+ status.value = 'form.nameRequired'
+ })
+ }}
+ >
+ {t('form.validateName')}
+
+ {
+ restoreValidation()
+ status.value = 'form.waiting'
+ }}
+ >
+ {t('form.clear')}
+
+ {
+ reset()
+ submission.value = void 0
+ status.value = 'form.waiting'
+ }}
+ >
+ {t('form.reset')}
+
+
- ),
- 'header-extra': () => '输入表单的时候,试试按下 Enter 键',
- }}
-
+
+
+
+ {submission.value ?? t('empty')}
+
+
+
+
)
},
})
diff --git a/src/views/demo/iframe/index.tsx b/src/views/demo/iframe/index.tsx
index 0673bad5..8bd2a0fc 100644
--- a/src/views/demo/iframe/index.tsx
+++ b/src/views/demo/iframe/index.tsx
@@ -1,31 +1,59 @@
import { RIframe } from '@/components'
-import { NCard, NFlex } from 'naive-ui'
+import { useI18n } from '@/hooks'
+import { NButton, NCard, NTag } from 'naive-ui'
+import DemoPage from '../components/DemoPage'
-const IframeDemo = defineComponent({
+export default defineComponent({
name: 'IframeDemo',
setup() {
- return {}
- },
- render() {
- return (
-
-
-
-
-
-
-
-
+ const { t } = useI18n('demoDetails')
+ const lazyMounted = ref(false)
+ const loaded = reactive({ eager: false, lazy: false })
+ const source = `${import.meta.env.BASE_URL}examples/embed.html`
+
+ return () => (
+
+
+ {(['eager', 'lazy'] as const).map((mode) => (
+
+ {{
+ 'header-extra': () => (
+
+ {loaded[mode] ? t('iframe.loaded') : t('iframe.pending')}
+
+ ),
+ default: () =>
+ mode === 'eager' || lazyMounted.value ? (
+ {
+ loaded[mode] = true
+ }}
+ />
+ ) : (
+
+ {
+ lazyMounted.value = true
+ }}
+ >
+ {t('iframe.mount')}
+
+
+ ),
+ }}
+
+ ))}
+
+
)
},
})
-
-export default IframeDemo
diff --git a/src/views/demo/modal-demo/index.tsx b/src/views/demo/modal-demo/index.tsx
index 9319eddb..c3f54cf2 100644
--- a/src/views/demo/modal-demo/index.tsx
+++ b/src/views/demo/modal-demo/index.tsx
@@ -1,113 +1,113 @@
import { RModal, useModal } from '@/components'
-import { NButton, NCard, NFlex } from 'naive-ui'
+import { useI18n } from '@/hooks'
+import { NButton, NCard, NFlex, NInputNumber, NTag } from 'naive-ui'
+import DemoPage from '../components/DemoPage'
+import DemoResult from '../components/DemoResult'
+
+const variants = ['card', 'dialog', 'fullscreen'] as const
export default defineComponent({
name: 'ModalDemo',
setup() {
- const state = reactive({
- modal1: false,
- modal2: false,
- modal3: false,
- })
+ const { t } = useI18n('demoDetails')
+ const variant = ref<(typeof variants)[number]>('card')
+ const visible = ref(false)
+ const width = ref(480)
+ const last = ref()
const { create } = useModal()
- const createCardModal = () => {
- create({
- title: '卡片模态框',
- draggable: true,
- preset: 'card',
- content: () => (
- 我可以被拖拽的全屏card模态框
- ),
- fullscreen: true,
- })
+ const open = (mode: (typeof variants)[number]) => {
+ variant.value = mode
+ visible.value = true
}
+ const content = () => (
+
+ RAY-024
+
+ )
- const createDialogModal = () => {
- create({
- title: '模态框',
- content: '内容',
- preset: 'dialog',
- draggable: true,
- })
- }
+ return () => (
+
+
+ {variants.map((mode) => (
+
+
+
+
+
+
open(mode)}>
+ {t(`modal.open.${mode}`)}
+
+
+
+ ))}
+
+
+
+
+ px
+
+ open('card')}>
+ {t('modal.applyWidth')}
+
+
+
+
+
+
+ create({ preset: 'card', title: t('modal.card'), content })
+ }
+ >
+ {t('modal.createCard')}
+
+
+ create({
+ preset: 'dialog',
+ title: t('modal.dialog'),
+ content,
+ })
+ }
+ >
+ {t('modal.createDialog')}
+
+
+
+
- return {
- ...toRefs(state),
- createCardModal,
- createDialogModal,
- }
- },
- render() {
- const { createCardModal, createDialogModal } = this
+
+ {last.value ? t(`modal.${last.value}`) : t('empty')}
+
- return (
-
-
-
- fullscreen: 全屏模态框。
-
-
{
+ last.value = variant.value
+ }}
>
- 我可以被拖拽的全屏card模态框
+ {content()}
-
- 我可以被拖拽
-
-
- 我可以被拖拽
-
-
- (this.modal2 = true)}>卡片模态框
- (this.modal3 = true)}>对话框模态框
-
-
-
-
- 全屏模态框需要同时设置:fullscreen 为 true,并且 preset 为 card
- 时才会生效。
-
- (this.modal1 = true)}>打开
-
-
-
-
- width(--r-modal-width): 当 preset 不为 dialog 或者 card
- 的时候,你可能用得上。
-
-
- dialogWidth(--r-modal-dialog-width): 当 preset 为
- dialog,你可能用得上。
-
-
- cardWidth(--r-modal-card-width): 当 preset 为 card,你可能用得上。
-
-
- 所有的宽度配置属性都会注入一个对应的 `css variable`,有时候会用上。
-
-
-
- 创建卡片模态框
-
- 创建对话框模态框
-
-
-
+
)
},
})
diff --git a/src/views/demo/multi/views/multi-menu-one/index.tsx b/src/views/demo/multi/views/multi-menu-one/index.tsx
index a2b11a30..a8b9628a 100644
--- a/src/views/demo/multi/views/multi-menu-one/index.tsx
+++ b/src/views/demo/multi/views/multi-menu-one/index.tsx
@@ -1,22 +1,13 @@
-import { NInput } from 'naive-ui'
+import CacheRouteExample from '../../../components/CacheRouteExample'
-const MultiMenuOne = defineComponent({
+export default defineComponent({
name: 'MultiMenuOne',
- setup() {
- const inputValue = ref(null)
-
- return {
- inputValue,
- }
- },
render() {
return (
-
- 多级菜单-1
-
-
+
)
},
})
-
-export default MultiMenuOne
diff --git a/src/views/demo/multi/views/multi-menu-two/views/sub-menu-other/index.tsx b/src/views/demo/multi/views/multi-menu-two/views/sub-menu-other/index.tsx
index 89207744..9b08472b 100644
--- a/src/views/demo/multi/views/multi-menu-two/views/sub-menu-other/index.tsx
+++ b/src/views/demo/multi/views/multi-menu-two/views/sub-menu-other/index.tsx
@@ -1,22 +1,13 @@
-import { NInput } from 'naive-ui'
+import CacheRouteExample from '../../../../../components/CacheRouteExample'
-const SubMenuOther = defineComponent({
+export default defineComponent({
name: 'SubMenuOther',
- setup() {
- const inputValue = ref(null)
-
- return {
- inputValue,
- }
- },
render() {
return (
-
- 多级菜单-2-1
-
-
+
)
},
})
-
-export default SubMenuOther
diff --git a/src/views/demo/multi/views/multi-menu-two/views/sub-menu/views/multi-menu-two-one/index.tsx b/src/views/demo/multi/views/multi-menu-two/views/sub-menu/views/multi-menu-two-one/index.tsx
index 0a907012..5f357a08 100644
--- a/src/views/demo/multi/views/multi-menu-two/views/sub-menu/views/multi-menu-two-one/index.tsx
+++ b/src/views/demo/multi/views/multi-menu-two/views/sub-menu/views/multi-menu-two-one/index.tsx
@@ -1,26 +1,13 @@
-import { NInput } from 'naive-ui'
+import CacheRouteExample from '../../../../../../../components/CacheRouteExample'
-const MultiMenuTwoOne = defineComponent({
+export default defineComponent({
name: 'MultiMenuTwoOne',
- setup() {
- const inputValue = ref(null)
-
- return {
- inputValue,
- }
- },
render() {
return (
-
- 多级菜单2-2-1
-
-
+
)
},
})
-
-export default MultiMenuTwoOne
diff --git a/src/views/demo/precision/index.tsx b/src/views/demo/precision/index.tsx
index 1c2fbf49..e82da628 100644
--- a/src/views/demo/precision/index.tsx
+++ b/src/views/demo/precision/index.tsx
@@ -1,149 +1,107 @@
+import { useI18n } from '@/hooks'
import { add, distribute, divide, format, multiply, subtract } from '@/utils'
-import { NCard, NDynamicTags, NFlex, NInputNumber, NLayout } from 'naive-ui'
+import {
+ NCard,
+ NDynamicTags,
+ NFormItem,
+ NGrid,
+ NGridItem,
+ NInputNumber,
+} from 'naive-ui'
+import DemoPage from '../components/DemoPage'
+import DemoResult from '../components/DemoResult'
-const CalculatePrecision = defineComponent({
+const operations = { add, subtract, multiply, divide }
+
+export default defineComponent({
name: 'CalculatePrecision',
setup() {
- const state = reactive({
- addOptions: ['1', '0.2', '0.1', '1.1'],
- subtractOptions: ['1', '0.2', '0.1', '1.1'],
- multiplyOptions: ['1', '0.2', '0.1', '1.1'],
- divideOptions: ['1', '0.2', '0.1', '1.1'],
- distributeValue: 12,
- distributeOutputValue: [] as unknown[],
- distributeLength: 3,
+ const { t } = useI18n('demoDetails')
+ const operands = reactive({
+ add: ['0.1', '0.2'],
+ subtract: ['1', '0.7'],
+ multiply: ['0.1', '0.2'],
+ divide: ['1', '3'],
})
- const actionMap = {
- addOptions: add,
- subtractOptions: subtract,
- multiplyOptions: multiply,
- divideOptions: divide,
- }
+ const amount = ref(10)
+ const parts = ref(3)
+ const allocation = computed(() =>
+ amount.value === null || parts.value === null
+ ? []
+ : distribute(amount.value, parts.value),
+ )
- const copilotFunc = (value: string[], path: keyof typeof actionMap) => {
- const action = actionMap[path]
- const result = action(...value)
+ return () => (
+
+
+ {(Object.keys(operations) as (keyof typeof operations)[]).map(
+ (operation) => {
+ const values = operands[operation]
+ const invalid =
+ !values.length ||
+ values.some(
+ (value) => !/^-?(?:\d+(?:\.\d*)?|\.\d+)$/.test(value),
+ )
+ const zeroDivisor =
+ operation === 'divide' &&
+ values.slice(1).some((value) => Number(value) === 0)
+ let result = t('precision.invalid')
- return '结果: ' + format(result)
- }
+ if (!invalid && !zeroDivisor) {
+ try {
+ result = String(format(operations[operation](...values)))
+ } catch {
+ result = t('precision.invalid')
+ }
+ }
- const updateDistributeValue = () => {
- nextTick().then(() => {
- state.distributeOutputValue = distribute(
- state.distributeValue,
- state.distributeLength,
- )
- })
- }
-
- updateDistributeValue()
-
- return {
- ...toRefs(state),
- copilotFunc,
- updateDistributeValue,
- }
- },
- render() {
- return (
-
-
- 计算方法,默认都保留八位小数与四舍五入,可以根据 format 方法自行转换
-
-
- 示例方法都基于 currency.js
- 封装,利用其精度处理能力封装了常用的一些计算方法,解决精度问题。如果需要其他的方法请阅读官方文档
- https://currency.js.org/#subtract
-
-
-
-
- {{
- default: () => (
- {
- this.copilotFunc(value, 'addOptions')
- }}
- />
- ),
- footer: () => {
- return this.copilotFunc(this.addOptions, 'addOptions')
- },
- }}
+ return (
+
+
+
+
+
+ {zeroDivisor ? t('precision.zero') : result}
+
+
+
+
+ )
+ },
+ )}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {allocation.value.length
+ ? allocation.value.join(' + ')
+ : t('empty')}
+
+
+
-
- {{
- default: () => (
- {
- this.copilotFunc(value, 'subtractOptions')
- }}
- />
- ),
- footer: () => {
- return this.copilotFunc(this.subtractOptions, 'subtractOptions')
- },
- }}
-
-
- {{
- default: () => (
- {
- this.copilotFunc(value, 'multiplyOptions')
- }}
- />
- ),
- footer: () => {
- return this.copilotFunc(this.multiplyOptions, 'multiplyOptions')
- },
- }}
-
-
- {{
- default: () => (
- {
- this.copilotFunc(value, 'divideOptions')
- }}
- />
- ),
- footer: () => {
- return this.copilotFunc(this.divideOptions, 'divideOptions')
- },
- }}
-
-
- {{
- default: () => (
-
- {
- this.updateDistributeValue()
- }}
- />
- {
- this.updateDistributeValue()
- }}
- />
-
- ),
- footer: () => {
- return '结果: ' + this.distributeOutputValue.join(', ')
- },
- }}
-
-
-
+
+
)
},
})
-
-export default CalculatePrecision
diff --git a/src/views/demo/qrcode/index.tsx b/src/views/demo/qrcode/index.tsx
index 9c4088e6..c6fee8dc 100644
--- a/src/views/demo/qrcode/index.tsx
+++ b/src/views/demo/qrcode/index.tsx
@@ -1,95 +1,130 @@
import LOGO from '@/assets/images/ray.svg'
-import { NButton, NCard, NFlex } from 'naive-ui'
+import { useI18n } from '@/hooks'
+import {
+ NButton,
+ NCard,
+ NFlex,
+ NFormItem,
+ NInput,
+ NRadioButton,
+ NRadioGroup,
+ NSwitch,
+} from 'naive-ui'
import { Vue3NextQrcode } from 'vue3-next-qrcode'
import type { QRCodeInst, QRCodeStatus } from 'vue3-next-qrcode'
+import DemoPage from '../components/DemoPage'
+import DemoResult from '../components/DemoResult'
+
+const initial = 'https://xiaodaigua-ray.github.io/ray-template/'
export default defineComponent({
name: 'RQRCodeDemo',
setup() {
- const qrcodeText = ref('ray template yes')
- const qrcodeStatus = ref()
- const rayQRCodeRef = ref()
+ const { t } = useI18n('demoDetails')
+ const text = ref(initial)
+ const brand = ref(true)
+ const animated = ref(false)
+ const status = ref<'ready' | QRCodeStatus>('ready')
+ const rendered = ref(false)
+ const failed = ref(false)
+ const instance = useTemplateRef('qrcode')
+ const id = useId()
- return {
- qrcodeText,
- qrcodeStatus,
- rayQRCodeRef,
- }
- },
- render() {
- return (
-
-
-
- 基于 awesome-qr 进行封装,支持 LOGO、gif、backgroundImage 等属性。
-
- 该组件会自动监听文本内容变化,然后重新渲染(watchText)
- 具体使用请参考 props 配置项
-
-
-
-
-
-
-
-
-
-
- {
- window.$message.info('reload event')
- }}
- />
-
-
-
-
-
-
- {
- this.qrcodeStatus = 'loading'
+ watch([text, brand, animated], () => {
+ rendered.value = false
+ failed.value = false
+ })
- setTimeout(() => {
- this.qrcodeText = 'text updated: ' + new Date().getTime()
- this.qrcodeStatus = void 0
- }, 1000)
- }}
+ return () => (
+
+
+
+
+
- 更新二维码内容
-
+
+
+
+
+ {t('qr.brand')}
+
+ {t('qr.animated')}
+
+
+ {(['ready', 'loading', 'error'] as const).map((state) => (
+
+ {t(`qr.${state}`)}
+
+ ))}
+
{
- this.rayQRCodeRef?.downloadQRCode()
- }}
+ type="primary"
+ disabled={
+ !rendered.value || failed.value || status.value !== 'ready'
+ }
+ onClick={() => instance.value?.downloadQRCode()}
>
- 下载二维码
+ {t('qr.download')}
-
-
-
- 当前二维码内容:{this.qrcodeText}
-
-
-
-
+
+
+
+
+
+ {text.value.trim() && !failed.value ? (
+ {
+ status.value = 'ready'
+ }}
+ onSuccess={() => {
+ rendered.value = true
+ }}
+ onError={() => {
+ failed.value = true
+ }}
+ />
+ ) : (
+ {failed.value ? t('qr.failed') : t('qr.noText')}
+ )}
+
+
+ {text.value || t('empty')}
+
+
+
+
+
)
},
})
diff --git a/src/views/demo/rely/views/rely-about/index.scss b/src/views/demo/rely/views/rely-about/index.scss
index cd64631a..650c679d 100644
--- a/src/views/demo/rely/views/rely-about/index.scss
+++ b/src/views/demo/rely/views/rely-about/index.scss
@@ -1,9 +1,27 @@
.rely-about {
- & .n-card {
- margin-top: 18px;
+ &__search {
+ inline-size: min(100%, 240px);
+ }
- &:first-child {
- margin-top: 0;
+ &__packages {
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(min(100%, 235px), 1fr));
+ gap: 8px;
+ list-style: none;
+ margin: 0;
+ padding: 0;
+
+ li {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ justify-content: space-between;
+ gap: 8px;
+ padding: 10px;
+ border: 1px solid var(--r-line);
+ border-radius: 8px;
+ background: var(--r-surface-muted);
+ overflow-wrap: anywhere;
}
}
}
diff --git a/src/views/demo/rely/views/rely-about/index.tsx b/src/views/demo/rely/views/rely-about/index.tsx
index 2e1e25f6..43faf4ce 100644
--- a/src/views/demo/rely/views/rely-about/index.tsx
+++ b/src/views/demo/rely/views/rely-about/index.tsx
@@ -1,137 +1,97 @@
import './index.scss'
-import { NCard, NDescriptions, NDescriptionsItem, NTag } from 'naive-ui'
-
-interface RelyDataOptions {
- name: string
- relyVersion: string
- relyAddress: string
-}
-
-interface TemplateOptions {
- name: string
- label: string
- url?: string
-}
+import { useI18n } from '@/hooks'
+import {
+ NButton,
+ NCard,
+ NFlex,
+ NInput,
+ NRadioButton,
+ NRadioGroup,
+ NTag,
+} from 'naive-ui'
+import DemoPage from '../../../components/DemoPage'
export default defineComponent({
name: 'RelyAbout',
setup() {
- const { pkg } = __APP_CFG__
- const { dependencies, devDependencies, name, version } = pkg
+ const { t } = useI18n('demoDetails')
+ const { dependencies, devDependencies, name, version } = __APP_CFG__.pkg
+ const groups = { runtime: dependencies, development: devDependencies }
+ const scope = ref('runtime')
+ const query = ref('')
+ const packages = computed(() =>
+ Object.entries(groups[scope.value]).filter(([pkg]) =>
+ pkg.toLowerCase().includes(query.value.trim().toLowerCase()),
+ ),
+ )
- const columns = [
- {
- title: '依赖名称',
- key: 'name',
- },
- {
- title: '依赖版本',
- key: 'relyVersion',
- },
- {
- title: '依赖地址',
- key: 'relyAddress',
- },
- ]
- const dependenciesOptions = ref([])
- const devDependenciesOptions = ref([])
-
- const templateOptions = [
- {
- name: '项目名称',
- label: name,
- },
- {
- name: '版本信息',
- label: version,
- },
- {
- name: '项目地址',
- label: 'GitHub',
- url: 'https://github.com/XiaoDaiGua-Ray/ray-template',
- },
- ]
-
- const handleGetRelyData = () => {
- const _arrayFrom = (obj: object) =>
- Object.keys(obj).reduce((pre, curr) => {
- pre.push({
- name: curr,
- relyVersion: obj[curr as keyof typeof obj],
- relyAddress: '',
- })
-
- return pre
- }, [] as RelyDataOptions[])
-
- dependenciesOptions.value = _arrayFrom(dependencies)
- devDependenciesOptions.value = _arrayFrom(devDependencies)
- }
-
- const handleTagClick = (item: TemplateOptions) => {
- if (item.url) {
- window.open(item.url)
- }
- }
-
- onBeforeMount(() => {
- handleGetRelyData()
- })
-
- return {
- columns,
- dependenciesOptions,
- devDependenciesOptions,
- templateOptions,
- handleTagClick,
- }
- },
- render() {
- return (
-
-
- ray template 是一个基于: tsx pinia vue3.x vite sass 的中后台解决方案.
- 项目干净与轻巧,
- 已经集成了很多项目中可能需要的搬砖工具可以让你快速起一个相关项目,
- 并且不需要剔除大量无用页面与组件.
-
-
-
- {this.templateOptions.map((curr) => (
-
-
- {curr.label}
-
-
- ))}
-
-
-
-
- {this.dependenciesOptions.map((curr) => (
-
- {curr.relyVersion}
-
- ))}
-
-
-
-
- {this.devDependenciesOptions.map((curr) => (
-
- {curr.relyVersion}
-
- ))}
-
-
-
+ return () => (
+
+ {{
+ actions: () => (
+
+ GitHub
+
+ ),
+ default: () => (
+
+ {{
+ 'header-extra': () => (
+
+ v{version}
+
+ ),
+ default: () => (
+
+
+
+
+ {t('about.runtime')}
+
+
+ {t('about.development')}
+
+
+
+
+ {packages.value.length ? (
+
+ {packages.value.map(([pkg, installed]) => (
+ -
+
{pkg}
+
+ {installed}
+
+
+ ))}
+
+ ) : (
+
{t('about.noMatch')}
+ )}
+
+ ),
+ }}
+
+ ),
+ }}
+
)
},
})
diff --git a/src/views/demo/router-demo/people.ts b/src/views/demo/router-demo/people.ts
new file mode 100644
index 00000000..dd913248
--- /dev/null
+++ b/src/views/demo/router-demo/people.ts
@@ -0,0 +1,8 @@
+export const routeDemoPeople = Array.from({ length: 10 }, (_, index) => ({
+ key: index,
+ name: `张三${index}`,
+ address: 'New York No. 1 Lake Park',
+ phone: '010-121212',
+}))
+
+export type RouteDemoPerson = (typeof routeDemoPeople)[number]
diff --git a/src/views/demo/router-demo/router-demo-detail/index.tsx b/src/views/demo/router-demo/router-demo-detail/index.tsx
index 5562a38b..95c28fff 100644
--- a/src/views/demo/router-demo/router-demo-detail/index.tsx
+++ b/src/views/demo/router-demo/router-demo-detail/index.tsx
@@ -1,33 +1,72 @@
-import { NCard, NFlex } from 'naive-ui'
+import { useI18n } from '@/hooks'
+import {
+ NButton,
+ NCard,
+ NDescriptions,
+ NDescriptionsItem,
+ NTag,
+} from 'naive-ui'
+import DemoPage from '../../components/DemoPage'
+import DemoResult from '../../components/DemoResult'
+import { routeDemoPeople } from '../people'
-const RouterDemoDetail = defineComponent({
+export default defineComponent({
name: 'RouterDemoDetail',
setup() {
+ const { t } = useI18n()
const route = useRoute()
+ const router = useRouter()
+ const person = computed(() =>
+ routeDemoPeople.find(({ key, name }) =>
+ route.query.id == null
+ ? route.query.name === name
+ : route.query.id === String(key),
+ ),
+ )
- return {
- route,
- }
- },
- render() {
- const { route } = this
-
- return (
-
-
- 你好 {route.query.name}
-
- 我是平层路由详情页面
-
- 1. 可以点击面包屑或者菜单返回到主页面
-
- 2. 如果这个页面需要配置多个详情页面,只需将该路由所在的 children
- 中,将所需页面配置为 sameLevel 即可。
-
-
-
+ return () => (
+
+ {{
+ actions: () => (
+ router.push('/router-demo/router-demo-home')}
+ >
+ {t('demoDetails.detail.back')}
+
+ ),
+ default: () => (
+
+
+ {person.value ? (
+
+
+ {person.value.address}
+
+
+ {person.value.phone}
+
+
+ ) : (
+ t('demoDetails.detail.missing')
+ )}
+
+
+
+
+ sameLevel
+
+
+ {JSON.stringify(route.query, null, 2)}
+
+
+
+
+ ),
+ }}
+
)
},
})
-
-export default RouterDemoDetail
diff --git a/src/views/demo/router-demo/router-demo-home/index.tsx b/src/views/demo/router-demo/router-demo-home/index.tsx
index 55f9223d..e603b48d 100644
--- a/src/views/demo/router-demo/router-demo-home/index.tsx
+++ b/src/views/demo/router-demo/router-demo-home/index.tsx
@@ -1,34 +1,31 @@
import { RTablePro } from '@/components'
+import { useI18n } from '@/hooks'
import { NButton, NFlex } from 'naive-ui'
import type { DataTableColumns } from 'naive-ui'
-
-export interface RowData {
- key: string | number
- name: string
- phone: string
- address: string
-}
+import { routeDemoPeople } from '../people'
+import type { RouteDemoPerson } from '../people'
const RouterDemoHome = defineComponent({
name: 'RouterDemoHome',
setup() {
const router = useRouter()
+ const { t } = useI18n('demoDetails')
- const columns: Ref> = ref([
+ const columns = computed>(() => [
{
- title: '姓名',
+ title: t('detail.name'),
key: 'name',
},
{
- title: '地址',
+ title: t('detail.address'),
key: 'address',
},
{
- title: '联系方式',
+ title: t('detail.phone'),
key: 'phone',
},
{
- title: '操作',
+ title: t('detail.action'),
key: '',
render: (row) => {
return (
@@ -41,31 +38,22 @@ const RouterDemoHome = defineComponent({
router.push({
path: '/router-demo/router-demo-detail',
query: {
+ id: String(row.key),
name: row.name,
},
})
}}
>
- 详情
+ {t('detail.open')}
)
},
},
])
- const dataSource: RowData[] = []
-
- for (let i = 0; i < 10; i++) {
- dataSource.push({
- name: '张三' + i,
- address: 'New York No. 1 Lake Park',
- phone: '010-121212',
- key: i,
- })
- }
return {
- dataSource,
+ dataSource: routeDemoPeople,
columns,
}
},
diff --git a/src/views/demo/scroll-reveal/index.scss b/src/views/demo/scroll-reveal/index.scss
index b5c1d796..3f490ca5 100644
--- a/src/views/demo/scroll-reveal/index.scss
+++ b/src/views/demo/scroll-reveal/index.scss
@@ -1,4 +1,32 @@
.scroll-reveal {
- width: 100%;
- height: 100%;
+ display: grid;
+ gap: 20px;
+
+ .n-card {
+ min-block-size: 220px;
+ background: var(--r-surface-muted);
+ }
+
+ &__number {
+ color: var(--r-primary-text);
+ font-size: clamp(2rem, 7vw, 4rem);
+ font-variant-numeric: tabular-nums;
+ }
+}
+
+@supports (animation-timeline: view()) {
+ @media (prefers-reduced-motion: no-preference) {
+ .scroll-reveal .n-card {
+ animation: reveal-example linear both;
+ animation-timeline: view();
+ animation-range: entry 5% entry 85%;
+ }
+ }
+}
+
+@keyframes reveal-example {
+ from {
+ opacity: 0.35;
+ transform: translateY(20px);
+ }
}
diff --git a/src/views/demo/scroll-reveal/index.tsx b/src/views/demo/scroll-reveal/index.tsx
index c3d96a00..53067e94 100644
--- a/src/views/demo/scroll-reveal/index.tsx
+++ b/src/views/demo/scroll-reveal/index.tsx
@@ -1,18 +1,27 @@
import './index.scss'
import { NCard } from 'naive-ui'
+import DemoPage from '../components/DemoPage'
-const ScrollReveal = defineComponent({
+export default defineComponent({
name: 'ScrollReveal',
render() {
return (
-
-
- RayScrollReveal组件有点问题, 暂时移除. 不能正常的实现滚动动画.
- 很是操蛋!!!
-
-
+
+
+
)
},
})
-
-export default ScrollReveal