BatchSet.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <script setup lang="tsx">
  2. import { PropType, ref } from 'vue'
  3. import {
  4. ElTabs,
  5. ElTabPane,
  6. ElSelect,
  7. ElOption,
  8. ElDivider,
  9. ElRadioGroup,
  10. ElRadio,
  11. ElMessage
  12. } from 'element-plus'
  13. import { Dialog } from '@/components/Dialog'
  14. import { setGroup } from '@/api/user'
  15. const modelValue = defineModel({ type: Boolean, default: false })
  16. const props = defineProps({
  17. selectList: {
  18. type: Array as PropType<any[]>,
  19. default: () => []
  20. },
  21. where: {
  22. type: Object,
  23. default: () => {
  24. return {}
  25. }
  26. },
  27. groupList: {
  28. type: Array as PropType<any[]>,
  29. default: () => undefined
  30. }
  31. })
  32. const setType = ref('action')
  33. const saveLoading = ref(false)
  34. const group_id = ref()
  35. const save = async () => {
  36. saveLoading.value = true
  37. const re = await setGroup({
  38. group_id: group_id.value,
  39. uids: props.selectList
  40. .map((e) => {
  41. return e.uid
  42. })
  43. .join(','),
  44. all: setType.value == 'all' ? 1 : 0,
  45. where: props.where
  46. })
  47. saveLoading.value = false
  48. if (re && re.status == 200) {
  49. modelValue.value = false
  50. ElMessage.success('设置成功')
  51. emit('confirm')
  52. }
  53. }
  54. const emit = defineEmits(['confirm'])
  55. </script>
  56. <template>
  57. <Dialog v-model="modelValue" max-height="200px" title="批量设置" width="700px">
  58. <el-tabs tab-position="left" class="h-[200px]">
  59. <el-tab-pane label="设置用户分组">
  60. <ElDivider content-position="left">用户分组</ElDivider>
  61. <ElSelect v-model="group_id" placeholder="请选择分组" style="width: 100%">
  62. <ElOption
  63. v-for="item in groupList"
  64. :key="item.id"
  65. :label="item.label"
  66. :value="item.value"
  67. />
  68. </ElSelect>
  69. <ElDivider content-position="left">设置方式</ElDivider>
  70. <ElRadioGroup v-model="setType" style="width: 100%">
  71. <ElRadio value="action">当前页面</ElRadio>
  72. <ElRadio value="all">全部页面</ElRadio>
  73. </ElRadioGroup>
  74. </el-tab-pane>
  75. </el-tabs>
  76. <template #footer>
  77. <BaseButton type="primary" :loading="saveLoading" @click="save"> 保存 </BaseButton>
  78. <BaseButton @click="modelValue = false">关闭</BaseButton>
  79. </template>
  80. </Dialog>
  81. </template>