index.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import { PropType, defineComponent, ref } from 'vue'
  2. import { LoadingOutlined, ReloadOutlined, CopyTwoTone, EditOutlined } from '@ant-design/icons-vue'
  3. import { useCopy } from '@/hooks/dom'
  4. import { Input, Space, Button } 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. keys: {
  96. type: Object as PropType<{key: string, name: string, value: string}>,
  97. default: () => {}
  98. },
  99. styles: {
  100. type: Object,
  101. default: () => {}
  102. }
  103. },
  104. emits: ['update:value'],
  105. setup (props, context) {
  106. const list = ref<{
  107. name: string,
  108. value: any,
  109. key: string
  110. }[]>([])
  111. props.request().then((r: {
  112. name: string,
  113. value: any,
  114. key: string
  115. }[]) => {
  116. list.value = r
  117. })
  118. const onInput = (value: string) => context.emit('update:value', value)
  119. return () => (
  120. <a-select style={{ width: '170px', ...props.styles }} value={props.modelValue} allowClear onChange={(value: string) => onInput(value)}>
  121. {
  122. list.value.map(item => <a-select-option key={item[props.keys.key]} value={item[props.keys.value]}>{item[props.keys.name]}</a-select-option>)
  123. }
  124. </a-select>
  125. )
  126. }
  127. })
  128. export const InputTsx = defineComponent({
  129. name: 'input-tsx',
  130. props: {
  131. modelValue: {
  132. type: String,
  133. required: true,
  134. default: ''
  135. },
  136. placeholder: {
  137. type: String,
  138. default: '输入点什么...'
  139. },
  140. mode: {
  141. type: String as PropType<'normal' | 'edit'>,
  142. default: 'normal'
  143. },
  144. value: {
  145. type: String,
  146. required: true,
  147. default: ''
  148. },
  149. styles: {
  150. type: Object,
  151. default: () => {}
  152. }
  153. },
  154. emits: ['update:value', 'submit'],
  155. setup (props, ctx) {
  156. console.log('props.modelValue:', props.value)
  157. const editing = ref<boolean>(false)
  158. const onInput = (value: string) => ctx.emit('update:value', value)
  159. const submitUpdate = () => {
  160. ctx.emit('submit')
  161. editing.value = false
  162. }
  163. return () => (
  164. <span>
  165. {
  166. props.mode === 'normal'
  167. ? <Input style={{ minWidth: '170px', ...props.styles }} value={props.value} placeholder={props.placeholder} onChange={(e) => onInput(e.target.value!)} />
  168. : <>
  169. <Space>
  170. {
  171. editing.value ? <Input style={{ minWidth: '170px' }} placeholder={props.placeholder} value={props.modelValue} onChange={(e) => onInput(e.target.value!)} /> : <div style={{ minWidth: '170px' }} >{props.modelValue}</div>
  172. }
  173. {
  174. editing.value ? <EditOutlined style={{ cursor: 'pointer' }} onClick={() => editing.value = !editing.value} /> : null
  175. }
  176. </Space>
  177. {
  178. editing.value
  179. ? <Space>
  180. <Button type="primary" onClick={() => submitUpdate()}>确定</Button>
  181. <Button onClick={() => editing.value = false}>取消</Button>
  182. </Space>
  183. : null
  184. }
  185. </>
  186. }
  187. </span>
  188. )
  189. }
  190. })
  191. /**
  192. * @description 文字copy按钮
  193. */
  194. export const CopyTsx = defineComponent({
  195. name: 'copy-tsx',
  196. props: {
  197. text: {
  198. type: String,
  199. required: true
  200. }
  201. },
  202. emits: ['success'],
  203. setup (props, ctx) {
  204. if (!props.text) {
  205. console.warn('缺少必备的参数 text')
  206. }
  207. const onCopy = () => {
  208. useCopy(props.text)
  209. }
  210. return () => (
  211. <a-tooltip
  212. title='复制'
  213. >
  214. <CopyTwoTone style="font-size: 18px;" onClick={onCopy}/>
  215. </a-tooltip>
  216. )
  217. }
  218. })
  219. /**
  220. *
  221. */