zhengyiming
2025-02-13 52e3cfc5c8267a079ed0d3c32758124fc74ea8ea
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<template>
  <nut-popup v-model:visible="innerVisible" class="new-prompt" @close="emit('close')">
    <div class="new-prompt-content">
      <div class="new-prompt-title-wrapper">
        <div class="new-prompt-title">{{ title }}</div>
        <Close color="#8C8C8C" class="new-prompt-title-close" @click="emit('onClose')" />
      </div>
      <div class="new-prompt-content-wrapper">
        <div class="new-prompt-oneline-content">
          <div class="new-prompt-oneline-input-wrapper">
            <nut-input
              type="text"
              class="bole-input-text"
              :placeholder="placeholder"
              v-model.trim="inputValue"
              @confirm="handleConfirm"
              autofocus
              v-bind="props.inputProps"
            />
            <div v-if="showCount" class="new-prompt-oneline-input-limit">
              <!-- @ts-ignore -->
              {{ inputValue.length }}/{{
                Number(props.inputProps.maxLength) < 0 ? 0 : props.inputProps.maxLength
              }}
            </div>
          </div>
        </div>
        <div class="new-prompt-oneline-actions">
          <nut-button class="new-prompt-oneline-action confirm" @click="handleConfirm">
            {{ confirmText }}
          </nut-button>
        </div>
      </div>
    </div>
  </nut-popup>
</template>
 
<script setup lang="ts">
import { Close } from '@nutui/icons-vue-taro';
import _ from 'lodash';
import { Message } from '@12333/utils';
import Taro from '@tarojs/taro';
import { Input } from '@nutui/nutui-taro';
import { ExtractPropTypes, computed, ref } from 'vue';
import './newPrompt.scss';
 
defineOptions({
  name: 'NewPromptOneLine',
});
 
type InputInstance = InstanceType<typeof Input>;
 
type InputProps = ExtractPropTypes<InputInstance['$props']>;
 
type Props = {
  visible: boolean;
  title?: string;
  placeholder?: string;
  inputProps?: Partial<InputProps>;
  showCount?: boolean;
  confirmText?: string;
};
 
const props = withDefaults(defineProps<Props>(), {
  confirmText: '确认',
});
 
const emit = defineEmits<{
  (e: 'confirm', value: string): void;
  (e: 'close'): void;
  (e: 'onClose'): void;
  (e: 'update:visible', value: boolean): void;
}>();
 
const innerVisible = computed({
  get() {
    return props.visible;
  },
  set(val) {
    emit('update:visible', val);
  },
});
 
const inputValue = ref('');
 
function handleConfirm() {
  const value = _.trim(inputValue.value);
  if (!value) {
    Message.warning('内容不能为空');
  } else {
    emit('confirm', value);
    Taro.hideKeyboard();
  }
}
</script>