edit.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <div class="edit">
  3. <div class="edit-top">
  4. <span>Host Setting</span>
  5. <Icon name="close" :size="20" @click="callBack(false)" />
  6. </div>
  7. <div class="edit-content">
  8. <Icon name="form" :size="240" />
  9. <div>
  10. <n-form ref="formRef" :model="formData" :rules="rules">
  11. <div>
  12. <n-form-item label="Address" path="host" inline>
  13. <n-input v-model:value="formData.host" placeholder="请输入" clearable />
  14. </n-form-item>
  15. <n-form-item label="Port" path="port" inline>
  16. <n-input v-model:value="formData.port" placeholder="请输入" clearable />
  17. </n-form-item>
  18. </div>
  19. <n-form-item label="Label" path="label">
  20. <n-input v-model:value="formData.label" placeholder="请输入" clearable />
  21. </n-form-item>
  22. <n-form-item label="UserName" path="userName">
  23. <n-input v-model:value="formData.userName" placeholder="请输入" clearable />
  24. </n-form-item>
  25. <n-form-item label="Passord" path="password">
  26. <n-input v-model:value="formData.password" placeholder="请输入" clearable />
  27. </n-form-item>
  28. </n-form>
  29. <div>
  30. <n-button ghost type="tertiary" @click="callBack(false)">
  31. Cancel
  32. </n-button>
  33. <n-button type="info" ghost @click="callBack(true)">
  34. Save
  35. </n-button>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <script setup lang='ts'>
  42. import { FormItemRule } from 'naive-ui'
  43. import { ref } from 'vue'
  44. export interface FormData {
  45. host: string,
  46. port: string,
  47. label: string,
  48. userName: string,
  49. password: string,
  50. icon?: string,
  51. size?: number,
  52. sshCom?: any,
  53. sftpCom?: any
  54. }
  55. const props = withDefaults(defineProps<{
  56. data?: FormData
  57. }>(), {
  58. data: () => ({
  59. host: '',
  60. port: '',
  61. label: '',
  62. userName: '',
  63. password: ''
  64. })
  65. })
  66. const emit = defineEmits<{ (evt: 'callBack', value: FormData | null): void }>()
  67. const formRef = ref()
  68. class FormOldData {
  69. host: string
  70. port: string
  71. label: string
  72. userName: string
  73. password: string
  74. constructor() {
  75. this.host = ''
  76. this.port = ''
  77. this.label = ''
  78. this.userName = ''
  79. this.password = ''
  80. }
  81. }
  82. const formData = ref(props.data || new FormOldData())
  83. const rules = ref({
  84. host: {
  85. required: true, message: '请输入', validator: (_: FormItemRule, value: string) => !!value
  86. },
  87. port: {
  88. required: true, message: '请输入', validator: (_: FormItemRule, value: string) => !!(/^[0-9]*$/.test(value)) && !!value
  89. },
  90. label: {
  91. required: true, message: '请输入', validator: (_: FormItemRule, value: string) => !!value
  92. },
  93. userName: {
  94. required: true, message: '请输入', validator: (_: FormItemRule, value: string) => !!value
  95. },
  96. password: {
  97. required: true, message: '请输入', validator: (_: FormItemRule, value: string) => !!value
  98. }
  99. })
  100. async function callBack(type: boolean) {
  101. const data = type ? { ...formData.value } : null
  102. if (type) await formRef.value.validate()
  103. emit('callBack', data)
  104. formData.value = new FormOldData()
  105. }
  106. </script>
  107. <style lang="scss" scoped>
  108. .edit {
  109. width: 90vw;
  110. height: 60vh;
  111. background: var(--background-color);
  112. border-radius: 10px;
  113. font-size: 14px;
  114. overflow: hidden;
  115. &-top {
  116. display: flex;
  117. align-items: center;
  118. justify-content: space-between;
  119. font-weight: bold;
  120. padding: 10px 15px;
  121. &>svg {
  122. cursor: pointer;
  123. }
  124. }
  125. &-content {
  126. padding: 10px 15px 0 0;
  127. display: flex;
  128. align-items: center;
  129. &>svg {
  130. margin-right: 10px;
  131. }
  132. &>div {
  133. width: 100%;
  134. :deep(.n-form) {
  135. .n-input {
  136. --n-border-focus: rgba(0, 0, 0, 0);
  137. --n-border-hover: rgba(0, 0, 0, 0);
  138. --n-box-shadow-focus: 0 0 0 2px rgba(0, 0, 0, .2);
  139. }
  140. &>div:first-child {
  141. display: flex;
  142. &>div:first-child {
  143. width: 78%;
  144. margin-right: 2%;
  145. }
  146. }
  147. }
  148. &>div:last-child {
  149. display: flex;
  150. align-items: center;
  151. justify-content: flex-end;
  152. &>button:last-child {
  153. margin-left: 15px;
  154. }
  155. :deep(.n-button) {
  156. --n-text-color-hover: none;
  157. --n-border-focus: 1px solid #0000;
  158. --n-border-hover: 1px solid #0000;
  159. }
  160. }
  161. }
  162. }
  163. }
  164. </style>