TerminalNickNameDialog.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <cwg-popup :title="'账户昵称'" :visible="props.visible" :showFooters="false"
  3. @update:visible="$emit('update:visible', $event)">
  4. <view class="popup-content">
  5. <text class="account-number">{{ accountLabel }} {{ account.login }}</text>
  6. <text class="account-hint">{{ hint }}</text>
  7. <view class="form-item">
  8. <view class="input-label">账户昵称</view>
  9. <input class="input-field" v-model="nickName" :maxlength="36" :placeholder="placeholder"
  10. @input="onInput" />
  11. <text class="input-hint">{{ constraint }}</text>
  12. </view>
  13. <view class="save-btn">
  14. <view class="btn primary" @click="save" :disabled="!isValid || !nickName.trim()" v-t="'Btn.Save'" />
  15. </view>
  16. </view>
  17. </cwg-popup>
  18. </template>
  19. <script setup>
  20. import { ref, computed, onMounted } from 'vue'
  21. import { customApi } from '@/service/custom';
  22. import { useI18n } from 'vue-i18n'
  23. const { t, locale } = useI18n()
  24. const props = defineProps({
  25. visible: { type: Boolean, default: false },
  26. // 账户编号
  27. account: { type: Object, default: {} },
  28. // 标题
  29. title: { type: String, default: '账户昵称' },
  30. // 账户标签前缀
  31. accountLabel: { type: String, default: '账户: #' },
  32. // 提示文字
  33. hint: { type: String, default: '为账户定制名称,以便快速查找。' },
  34. // 输入框占位符
  35. placeholder: { type: String, default: '为账户定制名称,以便快速查找。' },
  36. // 特殊字符限制说明
  37. constraint: { type: String, default: '昵称不可包含特殊字符:< > " \' & ? ^ * # @' }
  38. })
  39. const emit = defineEmits(['update:visible', 'save'])
  40. const nickName = ref(props.account.nickName)
  41. // 特殊字符正则
  42. const specialCharsRegex = /[<>"\'&?^*#@]/
  43. // 校验昵称是否合法
  44. const isValid = computed(() => {
  45. if (!nickName.value) return false
  46. return !specialCharsRegex.test(nickName.value)
  47. })
  48. // 输入时实时校验(可选,可去掉)
  49. const onInput = (e) => {
  50. // 实时过滤非法字符(也可以只是校验)
  51. }
  52. // 保存昵称
  53. const save = async () => {
  54. if (!isValid.value) {
  55. uni.showToast({
  56. title: '昵称包含非法字符,请重新输入',
  57. icon: 'none'
  58. })
  59. return
  60. }
  61. const nickname = nickName.value.trim()
  62. if (!nickname) {
  63. uni.showToast({
  64. title: '昵称不能为空',
  65. icon: 'none'
  66. })
  67. return
  68. }
  69. const res = await customApi.updateNick({ nickName: nickname, login: props.account.login })
  70. if (res.code == 200) {
  71. emit('update:visible', false)
  72. emit('save', nickname)
  73. }
  74. }
  75. </script>
  76. <style scoped lang="scss">
  77. @import "@/uni.scss";
  78. @media (min-width: 768px) {
  79. :deep(.cwg-dialog) {
  80. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  81. border-radius: px2rpx(8);
  82. width: px2rpx(480) !important;
  83. }
  84. }
  85. .popup-content {
  86. padding: px2rpx(16);
  87. }
  88. .account-number {
  89. display: block;
  90. font-size: px2rpx(14);
  91. color: #fff;
  92. margin-bottom: px2rpx(40);
  93. }
  94. .account-hint {
  95. display: block;
  96. font-size: px2rpx(13);
  97. color: #fff;
  98. margin-bottom: px2rpx(40);
  99. }
  100. .form-item {
  101. margin-bottom: px2rpx(20);
  102. }
  103. .input-label {
  104. font-size: px2rpx(12);
  105. color: #fff;
  106. margin-bottom: px2rpx(4);
  107. }
  108. .input-field {
  109. width: 100%;
  110. height: px2rpx(40);
  111. border: 1px solid #ddd;
  112. border-radius: px2rpx(6);
  113. padding: 0 px2rpx(12);
  114. font-size: px2rpx(14);
  115. box-sizing: border-box;
  116. }
  117. .input-hint {
  118. display: block;
  119. font-size: px2rpx(11);
  120. color: var(--bs-heading-color);
  121. margin-top: px2rpx(6);
  122. line-height: 1.4;
  123. }
  124. .save-btn {
  125. width: 100%;
  126. height: px2rpx(40);
  127. color: #fff;
  128. border-radius: px2rpx(8);
  129. font-size: px2rpx(16);
  130. font-weight: 500;
  131. display: flex;
  132. justify-content: flex-end;
  133. border: none;
  134. .btn {
  135. background: transparent;
  136. border: 1px solid rgba(108, 133, 149, 0);
  137. border-radius: px2rpx(8);
  138. padding: px2rpx(8) px2rpx(20);
  139. font-size: px2rpx(14);
  140. color: rgba(var(--bs-dark-rgb), var(--bs-text-opacity)) !important;
  141. display: inline-flex;
  142. align-items: center;
  143. justify-content: center;
  144. gap: px2rpx(8);
  145. cursor: pointer;
  146. transition: all 0.2s;
  147. height: px2rpx(40);
  148. box-sizing: border-box;
  149. background-color: rgba(108, 133, 149, 0.08);
  150. &.primary {
  151. background-color: #cf1322;
  152. ;
  153. color: #fff;
  154. svg {
  155. stroke: #fff;
  156. }
  157. &:hover {
  158. background-color: var(--color-navy-600);
  159. }
  160. }
  161. }
  162. }
  163. </style>