index.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import { defineComponent, ref } from 'vue'
  2. import { LoadingOutlined, ReloadOutlined, CopyTwoTone } from '@ant-design/icons-vue'
  3. import { useCopy } from '@/hooks/dom'
  4. import { Input } from 'ant-design-vue'
  5. /* 此代码导出一个名为“ReloadIconTsx”的 Vue
  6. 组件,该组件显示一个用于重新加载内容的图标。该组件有两个道具:`loading`(一个布尔值,指示内容当前是否正在加载)和`reload`(单击重新加载图标时调用的函数)。该组件使用 Vue
  7. 中的“defineComponent”函数来定义其行为,并使用“@ant-design/icons-vue”库中的“LoadingOutlined”和“ReloadOutlined”图标来显示适当的图标。该组件还使用
  8. Ant Design Vue 库中的“a-tooltip”组件在用户将鼠标悬停在图标上时显示工具提示。 */
  9. export const ReloadIconTsx = defineComponent({
  10. name: 'reload-icon-tsx',
  11. props: {
  12. loading: {
  13. type: Boolean,
  14. default: false
  15. },
  16. reload: {
  17. type: Function,
  18. default: () => {}
  19. }
  20. },
  21. setup (props, context) {
  22. return () => (
  23. <a-tooltip
  24. title="刷新"
  25. >
  26. { props.loading ? <LoadingOutlined /> : <ReloadOutlined onClick={() => props.reload()} /> }
  27. </a-tooltip>
  28. )
  29. }
  30. })
  31. /**
  32. * 这是一个 TypeScript React 组件,用于呈现带有可自定义内容和操作插槽的警报。
  33. * @param props - 包含两个属性的对象:
  34. * @param context - `setup` 函数中的 `context`
  35. * 参数是一个对象,它提供对当前组件实例的属性和方法的访问。它包括“attrs”、“emit”、“slots”和“refs”等属性。在此特定代码中,“slots”属性用于访问
  36. * @returns 呈现具有两列的行的功能组件。第一列的内容由 valueSlot 槽确定,第二列的内容由 operaSlot
  37. * 槽确定。该组件还接受字符串类型的“value”属性和对象类型的“operaSlot”属性。
  38. */
  39. export const AlertTsx = defineComponent({
  40. props: {
  41. value: {
  42. type: String,
  43. default: ''
  44. }
  45. },
  46. setup (props, context) {
  47. const { slots } = context
  48. return () => (
  49. <a-row
  50. justify='space-between'
  51. align="middle"
  52. style={{
  53. backgroundColor: '#e6f7ff',
  54. border: '1px solid #91d5ff',
  55. minHeight: '40px',
  56. padding: '0px 20px '
  57. }}
  58. >
  59. <a-col>{ props.value ? props.value : slots.valueSlot!()}</a-col>
  60. <a-col>{slots.operaSlot!()}</a-col>
  61. </a-row>
  62. )
  63. }
  64. })
  65. /**
  66. * @description iconfont矢量库 使用的svg的格式 svg导入在public下的index.html里
  67. */
  68. export const IconTsx = defineComponent({
  69. props: {
  70. name: {
  71. type: String,
  72. required: true
  73. }
  74. },
  75. setup (props, ctx) {
  76. return () => (
  77. <svg class="icon" aria-hidden="true" style={{ fill: '#fff' }} >
  78. <use style={{ fill: '#fff' }} xlinkHref={`#icon-${props.name}`}></use>
  79. </svg>
  80. )
  81. }
  82. })
  83. export const SelectTsx = defineComponent({
  84. name: 'select-tsx',
  85. props: {
  86. modelValue: {
  87. type: Object,
  88. required: true,
  89. default: () => ({})
  90. },
  91. request: {
  92. type: Function,
  93. default: () => {}
  94. }
  95. },
  96. emits: ['update:value'],
  97. setup (props, context) {
  98. const list = ref<{
  99. name: string,
  100. value: any,
  101. key: string
  102. }[]>([])
  103. props.request().then((r: {
  104. name: string,
  105. value: any,
  106. key: string
  107. }[]) => {
  108. list.value = r
  109. })
  110. const onInput = (value: string) => context.emit('update:value', value)
  111. return () => (
  112. <a-select value={props.modelValue} allowClear onChange={(value: string) => onInput(value)}>
  113. {
  114. list.value.map(item => <a-select-option key={item.key} value={item.value}>{item.name}</a-select-option>)
  115. }
  116. </a-select>
  117. )
  118. }
  119. })
  120. export const InputTsx = defineComponent({
  121. name: 'input-tsx',
  122. props: {
  123. modelValue: {
  124. type: String,
  125. required: true,
  126. default: ''
  127. },
  128. placeholder: {
  129. type: String,
  130. default: '输入点什么...'
  131. }
  132. },
  133. emits: ['update:value'],
  134. setup (props, ctx) {
  135. const onInput = (value: string) => ctx.emit('update:value', value)
  136. return () => (
  137. <Input style={{ minWidth: '170px' }} placeholder={props.placeholder} value={props.modelValue} onChange={(e) => onInput(e.target.value!)} />
  138. )
  139. }
  140. })
  141. /**
  142. * @description 文字copy按钮
  143. */
  144. export const CopyTsx = defineComponent({
  145. name: 'copy-tsx',
  146. props: {
  147. text: {
  148. type: String,
  149. required: true
  150. }
  151. },
  152. emits: ['success'],
  153. setup (props, ctx) {
  154. if (!props.text) {
  155. console.warn('缺少必备的参数 text')
  156. }
  157. const onCopy = () => {
  158. useCopy(props.text)
  159. }
  160. return () => (
  161. <a-tooltip
  162. title='复制'
  163. >
  164. <CopyTwoTone style="font-size: 20px;" onClick={onCopy}/>
  165. </a-tooltip>
  166. )
  167. }
  168. })
  169. /**
  170. *
  171. */