index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. <script setup lang="ts">
  2. import { NAlert, NCard, useMessage, NButton, useModal, NModal, useNotification } from 'naive-ui'
  3. import { reactive } from 'vue'
  4. import type { ModalProps } from 'naive-ui'
  5. defineOptions({
  6. name: 'Feedback',
  7. })
  8. const APP_NAME = import.meta.env.VITE_APP_NAME
  9. const message = useMessage()
  10. const modal = useModal()
  11. import { useComponentModifier } from '@/composable/comp/useComponentModifier'
  12. import { useMessageDiscrete, useModalDiscrete, useNotificationDiscrete } from './discreteApi'
  13. const { getModalModifier } = useComponentModifier()
  14. const notification = useNotification()
  15. const showModal = reactive({
  16. modal1: false,
  17. modal2: false,
  18. modal3: false,
  19. modal4: false,
  20. })
  21. const changeMessageState = () => {
  22. let counter = 5
  23. let timer: ReturnType<typeof setInterval> | null = null
  24. const messageInstance = message.create('5秒后 根据状态更换图标', {
  25. type: 'info',
  26. duration: 0,
  27. closable: true,
  28. })
  29. timer = setInterval(() => {
  30. counter -= 1
  31. if (counter <= 0) {
  32. if (timer) {
  33. clearInterval(timer)
  34. }
  35. messageInstance.type = 'error'
  36. messageInstance.content = '切换图标了'
  37. return
  38. }
  39. messageInstance.content = `${counter}秒后 根据状态更换图标`
  40. }, 1000)
  41. }
  42. const createDialogApi = (type: ModalProps['type'] = 'success') => {
  43. const title = {
  44. success: '成功的Dialog',
  45. warning: '警告的Dialog',
  46. error: '失败的Dialog',
  47. info: '信息的Dialog',
  48. default: '默认的Dialog',
  49. } as const
  50. modal.create({
  51. ...getModalModifier(),
  52. title: `命令式${title[type]}`,
  53. content: `命令式${title[type]}`,
  54. preset: 'dialog',
  55. type,
  56. positiveText: '确认',
  57. negativeText: '算了',
  58. })
  59. }
  60. </script>
  61. <template>
  62. <div class="flex flex-col gap-y-2 p-4">
  63. <NAlert
  64. type="info"
  65. closable
  66. >
  67. {{ APP_NAME }} 修饰了一些反馈组件的默认设计,这似乎还不错
  68. </NAlert>
  69. <NAlert
  70. type="success"
  71. closable
  72. >
  73. {{ APP_NAME }} 修饰了一些反馈组件的默认设计,这似乎还不错
  74. </NAlert>
  75. <NAlert
  76. type="error"
  77. closable
  78. >
  79. {{ APP_NAME }} 修饰了一些反馈组件的默认设计,这似乎还不错
  80. </NAlert>
  81. <NAlert
  82. type="warning"
  83. closable
  84. >
  85. {{ APP_NAME }} 修饰了一些反馈组件的默认设计,这似乎还不错
  86. </NAlert>
  87. <NCard title="Message 消息">
  88. <div class="flex flex-wrap gap-4">
  89. <NButton
  90. type="success"
  91. @click="message.success('成功Message', { closable: true })"
  92. >
  93. 成功Message
  94. </NButton>
  95. <NButton
  96. type="warning"
  97. secondary
  98. @click="message.warning('警告Message', { closable: true })"
  99. >
  100. 警告Message
  101. </NButton>
  102. <NButton
  103. type="error"
  104. tertiary
  105. @click="message.error('失败Message', { closable: true })"
  106. >
  107. 失败Message
  108. </NButton>
  109. <NButton
  110. type="info"
  111. dashed
  112. @click="message.info('信息Message', { closable: true })"
  113. >
  114. 信息Message
  115. </NButton>
  116. <NButton
  117. type="primary"
  118. ghost
  119. @click="message.loading('加载Message', { closable: true })"
  120. >
  121. 加载Message
  122. </NButton>
  123. <NButton @click="changeMessageState"> 根据状态切换图标 </NButton>
  124. <NCard
  125. size="small"
  126. title="Setup 外使用"
  127. :bordered="false"
  128. >
  129. <div class="flex flex-wrap gap-4">
  130. <NButton
  131. type="success"
  132. @click="useMessageDiscrete('success')"
  133. size="small"
  134. >
  135. 成功Message
  136. </NButton>
  137. <NButton
  138. type="warning"
  139. secondary
  140. @click="useMessageDiscrete('warning')"
  141. size="small"
  142. >
  143. 警告Message
  144. </NButton>
  145. <NButton
  146. type="error"
  147. tertiary
  148. @click="useMessageDiscrete('error')"
  149. size="small"
  150. >
  151. Message失败
  152. </NButton>
  153. <NButton
  154. type="info"
  155. dashed
  156. @click="useMessageDiscrete('info')"
  157. size="small"
  158. >
  159. 信息Message
  160. </NButton>
  161. <NButton
  162. type="primary"
  163. ghost
  164. @click="useMessageDiscrete('loading')"
  165. size="small"
  166. >
  167. 加载Message
  168. </NButton>
  169. </div>
  170. </NCard>
  171. </div>
  172. </NCard>
  173. <NCard title="Modal 模态框">
  174. <div class="flex flex-wrap gap-4">
  175. <NCard
  176. size="small"
  177. title="Dialog 预设"
  178. :bordered="false"
  179. >
  180. <div class="flex flex-wrap gap-4">
  181. <NButton
  182. type="success"
  183. secondary
  184. @click="showModal.modal1 = true"
  185. >
  186. 成功Dialog
  187. </NButton>
  188. <NButton
  189. type="warning"
  190. tertiary
  191. @click="showModal.modal2 = true"
  192. >
  193. 警告Dialog
  194. </NButton>
  195. <NButton
  196. type="error"
  197. dashed
  198. @click="showModal.modal3 = true"
  199. >
  200. 失败Dialog
  201. </NButton>
  202. <NButton
  203. type="info"
  204. ghost
  205. @click="showModal.modal4 = true"
  206. >
  207. 信息Dialog
  208. </NButton>
  209. </div>
  210. </NCard>
  211. <NCard
  212. size="small"
  213. title="命令式 Dialog 预设"
  214. :bordered="false"
  215. >
  216. <div class="flex flex-wrap gap-4">
  217. <NButton
  218. type="success"
  219. size="small"
  220. secondary
  221. @click="createDialogApi('success')"
  222. >
  223. 成功Dialog
  224. </NButton>
  225. <NButton
  226. type="warning"
  227. size="small"
  228. tertiary
  229. @click="createDialogApi('warning')"
  230. >
  231. 警告Dialog
  232. </NButton>
  233. <NButton
  234. type="error"
  235. size="small"
  236. dashed
  237. @click="createDialogApi('error')"
  238. >
  239. 失败Dialog
  240. </NButton>
  241. <NButton
  242. type="info"
  243. size="small"
  244. ghost
  245. @click="createDialogApi('info')"
  246. >
  247. 信息Dialog
  248. </NButton>
  249. </div>
  250. </NCard>
  251. <NCard
  252. size="small"
  253. title="Setup 外使用 Dialog 预设"
  254. :bordered="false"
  255. >
  256. <div class="flex flex-wrap gap-4">
  257. <NButton
  258. type="success"
  259. size="small"
  260. secondary
  261. @click="useModalDiscrete('success')"
  262. >
  263. 成功Dialog
  264. </NButton>
  265. <NButton
  266. type="warning"
  267. size="small"
  268. tertiary
  269. @click="useModalDiscrete('warning')"
  270. >
  271. 警告Dialog
  272. </NButton>
  273. <NButton
  274. type="error"
  275. size="small"
  276. dashed
  277. @click="useModalDiscrete('error')"
  278. >
  279. 失败Dialog
  280. </NButton>
  281. <NButton
  282. type="info"
  283. size="small"
  284. ghost
  285. @click="useModalDiscrete('info')"
  286. >
  287. 信息Dialog
  288. </NButton>
  289. </div>
  290. </NCard>
  291. </div>
  292. </NCard>
  293. <NCard title="Notification 通知">
  294. <div class="flex flex-wrap gap-4">
  295. <NButton
  296. type="success"
  297. @click="
  298. notification.success({
  299. content: '说点啥呢',
  300. meta: '我不到啊',
  301. duration: 0,
  302. })
  303. "
  304. >
  305. 成功Notification
  306. </NButton>
  307. <NButton
  308. type="warning"
  309. secondary
  310. @click="
  311. notification.warning({
  312. content: '说点啥呢',
  313. meta: '我不到啊',
  314. duration: 5000,
  315. })
  316. "
  317. >
  318. 警告Notification
  319. </NButton>
  320. <NButton
  321. type="error"
  322. tertiary
  323. @click="
  324. notification.error({
  325. content: '说点啥呢',
  326. meta: '我不到啊',
  327. duration: 5000,
  328. })
  329. "
  330. >
  331. 错误Notification
  332. </NButton>
  333. <NButton
  334. type="info"
  335. ghost
  336. @click="
  337. notification.info({
  338. content: '说点啥呢',
  339. meta: '我不到啊',
  340. duration: 5000,
  341. })
  342. "
  343. >
  344. 信息Notification
  345. </NButton>
  346. </div>
  347. <NCard
  348. size="small"
  349. :bordered="false"
  350. title="Setup 外使用 Notification 通知"
  351. >
  352. <div class="flex flex-wrap gap-4">
  353. <NButton
  354. type="success"
  355. size="small"
  356. secondary
  357. @click="useNotificationDiscrete('success')"
  358. >
  359. 成功Notification
  360. </NButton>
  361. <NButton
  362. type="warning"
  363. secondary
  364. size="small"
  365. @click="useNotificationDiscrete('warning')"
  366. >
  367. 警告Notification
  368. </NButton>
  369. <NButton
  370. type="error"
  371. tertiary
  372. size="small"
  373. @click="useNotificationDiscrete('error')"
  374. >
  375. 错误Notification
  376. </NButton>
  377. <NButton
  378. type="info"
  379. ghost
  380. size="small"
  381. @click="useNotificationDiscrete('info')"
  382. >
  383. 信息Notification
  384. </NButton>
  385. </div>
  386. </NCard>
  387. </NCard>
  388. <NModal
  389. v-bind="
  390. getModalModifier({
  391. type: 'success',
  392. })
  393. "
  394. v-model:show="showModal.modal1"
  395. preset="dialog"
  396. title="确认"
  397. content="你确认?"
  398. positive-text="确认"
  399. negative-text="算了"
  400. >
  401. </NModal>
  402. <NModal
  403. v-bind="
  404. getModalModifier({
  405. type: 'info',
  406. })
  407. "
  408. v-model:show="showModal.modal2"
  409. preset="dialog"
  410. title="确认"
  411. content="你确认?"
  412. positive-text="确认"
  413. negative-text="算了"
  414. >
  415. </NModal>
  416. <NModal
  417. v-bind="
  418. getModalModifier({
  419. type: 'error',
  420. })
  421. "
  422. v-model:show="showModal.modal3"
  423. type="error"
  424. preset="dialog"
  425. title="确认"
  426. content="你确认?"
  427. positive-text="确认"
  428. negative-text="算了"
  429. >
  430. </NModal>
  431. <NModal
  432. v-bind="
  433. getModalModifier({
  434. type: 'info',
  435. })
  436. "
  437. v-model:show="showModal.modal4"
  438. preset="dialog"
  439. title="确认"
  440. content="你确认?"
  441. positive-text="确认"
  442. negative-text="算了"
  443. >
  444. </NModal>
  445. </div>
  446. </template>