SUserSelectButton2.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. const n = `<template>
  2. <span class="s-user-select-button-common">
  3. <a-button :type="type" :size="size" :disabled="disabled" @click="open">
  4. <component v-if="icon" :is="icon" />
  5. <slot>{{ buttonText }}</slot>
  6. </a-button>
  7. <!-- 隐藏的人员选择器:点击按钮时调用其 open() 打开弹窗,确认后事件回传结果 -->
  8. <s-user-select
  9. v-show="false"
  10. ref="userSelectRef"
  11. :value="value"
  12. :multiple="multiple"
  13. :title="title"
  14. :placeholder="placeholder"
  15. @update:value="onUpdateValue"
  16. @change="onChange"
  17. />
  18. </span>
  19. </template>
  20. <script setup>
  21. import { ref } from 'vue'
  22. const props = defineProps({
  23. // 已选值:单选为字符串,多选为数组(与 s-user-select 的 value 一致),支持 v-model:value
  24. value: {
  25. type: [String, Array],
  26. default() {
  27. return ''
  28. }
  29. },
  30. // 是否多选,false 为单选
  31. multiple: {
  32. type: Boolean,
  33. default: true
  34. },
  35. // 按钮文案
  36. buttonText: {
  37. type: String,
  38. default() {
  39. return window.$l('选择人员')
  40. }
  41. },
  42. // 按钮类型:default / primary / dashed / link / text
  43. type: {
  44. type: String,
  45. default: 'default'
  46. },
  47. // 按钮尺寸:large / middle / small
  48. size: {
  49. type: String,
  50. default: 'middle'
  51. },
  52. // 是否禁用
  53. disabled: {
  54. type: Boolean,
  55. default: false
  56. },
  57. // 弹窗标题
  58. title: {
  59. type: String,
  60. default() {
  61. return window.$l('人员选择')
  62. }
  63. },
  64. // 未选择时的占位文案
  65. placeholder: {
  66. type: String,
  67. default() {
  68. return window.$l('请选择')
  69. }
  70. },
  71. // 是否显示按钮图标
  72. icon: {
  73. type: String,
  74. default: ''
  75. }
  76. })
  77. const emits = defineEmits(['change', 'update:value'])
  78. const userSelectRef = ref(null)
  79. // 点击按钮打开人员选择弹窗
  80. const open = () => {
  81. if (props.disabled) return
  82. userSelectRef.value && userSelectRef.value.open()
  83. }
  84. const onUpdateValue = (val) => {
  85. emits('update:value', val)
  86. }
  87. // 选择确认后回传:tags/nameList/idList/list
  88. const onChange = (...args) => {
  89. emits('change', ...args)
  90. }
  91. defineExpose({ open })
  92. <\/script>
  93. <style lang="less" scoped>
  94. .s-user-select-button-common {
  95. display: inline-block;
  96. }
  97. </style>
  98. `;
  99. export {
  100. n as default
  101. };