Blame view

Yi.Vben5.Vue3/apps/web-antd/src/views/system/client/secret-input.vue 1.16 KB
515fceeb   “wangming”   框架初始化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  <script setup lang="ts">
  import { IconifyIcon } from '@vben/icons';
  import { buildUUID } from '@vben/utils';
  
  import { Input } from 'ant-design-vue';
  
  defineOptions({ name: 'SecretInput' });
  
  withDefaults(defineProps<{ disabled?: boolean; placeholder?: string }>(), {
    disabled: false,
    placeholder: '请输入密钥或随机生成',
  });
  
  const value = defineModel<string>('value', {
    required: false,
  });
  
  function refreshSecret() {
    value.value = buildUUID();
  }
  
  /**
   * 万一要在每次新增时打开Drawer刷新
   * 需要调用实例方法
   */
  defineExpose({ refreshSecret });
  </script>
  
  <template>
    <Input v-model:value="value" :disabled="disabled" :placeholder="placeholder">
      <template v-if="!disabled" #addonAfter>
        <a-button type="primary" @click="refreshSecret">
          <div class="flex items-center gap-[4px]">
            <IconifyIcon icon="charm:refresh" />
            <span>随机生成</span>
          </div>
        </a-button>
      </template>
    </Input>
  </template>
  
  <style lang="scss" scoped>
  :deep(.ant-input-group-addon) {
    padding: 0;
    border: none;
  }
  
  :deep(.ant-btn-primary) {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }
  </style>