|
1 | 1 | <script setup lang="ts"> |
2 | 2 | import { ElMessage } from 'element-plus' |
3 | | -import { reactive, ref } from 'vue' |
| 3 | +import { reactive, ref, watch } from 'vue' |
4 | 4 | import { Edit, Delete } from '@element-plus/icons-vue' |
5 | 5 | import type { FormInstance, FormRules } from 'element-plus' |
6 | 6 | import type { Pair } from './types' |
7 | 7 | import { API } from './net' |
| 8 | +import { UIAPI } from './net-vue' |
8 | 9 | import { SupportedExtensions } from './store' |
9 | 10 | import { useI18n } from 'vue-i18n' |
10 | 11 |
|
@@ -115,44 +116,25 @@ const rules = reactive<FormRules<Store>>({ |
115 | 116 | }) |
116 | 117 | const submitForm = async (formEl: FormInstance | undefined) => { |
117 | 118 | if (!formEl) return |
118 | | - await formEl.validate((valid: boolean, fields) => { |
| 119 | + await formEl.validate((valid: boolean) => { |
119 | 120 | if (valid) { |
120 | | - creatingLoading.value = true |
121 | | -
|
122 | | - const requestOptions = { |
123 | | - method: 'POST', |
124 | | - headers: { |
125 | | - 'X-Auth': API.getToken() |
126 | | - }, |
127 | | - body: JSON.stringify(storeForm) |
128 | | - } |
129 | | - |
130 | | - let api = '/server.Runner/CreateStore' |
131 | | - if (!createAction.value) { |
132 | | - api = '/server.Runner/UpdateStore' |
133 | | - } |
134 | | -
|
135 | | - fetch(api, requestOptions) |
136 | | - .then((response) => { |
137 | | - if (!response.ok) { |
138 | | - throw new Error(response.statusText) |
139 | | - } else { |
140 | | - return response.json() |
141 | | - } |
142 | | - }) |
143 | | - .then(() => { |
| 121 | + UIAPI.CreateOrUpdateStore(storeForm, createAction.value, () => { |
144 | 122 | loadStores() |
145 | 123 | dialogVisible.value = false |
146 | 124 | formEl.resetFields() |
147 | | - }) |
148 | | - .catch((e) => { |
149 | | - ElMessage.error('Oops, ' + e) |
150 | | - }) |
151 | | - creatingLoading.value = false |
| 125 | + }, creatingLoading) |
152 | 126 | } |
153 | 127 | }) |
154 | 128 | } |
155 | 129 |
|
| 130 | +watch(storeForm, (e) => { |
| 131 | + if (e.kind.name === '') { |
| 132 | + if (e.url.startsWith('https://github.com') || e.url.startsWith('https://gitee.com')) { |
| 133 | + e.kind.name = 'atest-store-git' |
| 134 | + } |
| 135 | + } |
| 136 | +}) |
| 137 | +
|
156 | 138 | function storeVerify(formEl: FormInstance | undefined) { |
157 | 139 | if (!formEl) return |
158 | 140 | |
|
0 commit comments