|
|
@@ -1,5 +1,4 @@
|
|
|
<script setup lang="ts">
|
|
|
-import {ElForm, ElFormItem, ElMessage} from "element-plus"
|
|
|
import {computed, ref} from 'vue'
|
|
|
import {createStore} from "../../api/store.ts"
|
|
|
import {uploadImage} from "../../api/image.ts"
|
|
|
@@ -7,7 +6,7 @@ import {uploadImage} from "../../api/image.ts"
|
|
|
// 输入框值
|
|
|
const name = ref('')
|
|
|
const location = ref('')
|
|
|
-const logoURL = ref('')
|
|
|
+let logoUrl = ref('')
|
|
|
|
|
|
// 用于前端阻拦不合法输入
|
|
|
const hasNameInput = computed(() => name.value != '')
|
|
|
@@ -42,19 +41,17 @@ function drop(e) {
|
|
|
|
|
|
function generateURL(file) {
|
|
|
let formData = new FormData();
|
|
|
- console.log(file)
|
|
|
formData.append('file', file);
|
|
|
uploadImage(formData).then(res => {
|
|
|
- console.log(res);
|
|
|
- this.logoURL = res.data;
|
|
|
- return this.logoUrl;
|
|
|
+ logoUrl = res.result;
|
|
|
});
|
|
|
- // let fileSrc = URL.createObjectURL(file);
|
|
|
- // setTimeout(() => {
|
|
|
- // URL.revokeObjectURL(fileSrc);
|
|
|
- // }, 1000);
|
|
|
- // console.log(fileSrc);
|
|
|
- // return fileSrc;
|
|
|
+
|
|
|
+ let fileSrc = URL.createObjectURL(file);
|
|
|
+ setTimeout(() => {
|
|
|
+ URL.revokeObjectURL(fileSrc);
|
|
|
+ }, 1000);
|
|
|
+
|
|
|
+ return fileSrc;
|
|
|
}
|
|
|
|
|
|
function remove(i) {
|
|
|
@@ -67,21 +64,27 @@ const createDisabled = computed(() => {
|
|
|
})
|
|
|
|
|
|
function handleCreateStore() {
|
|
|
- const payload1 = {
|
|
|
- name: name,
|
|
|
- location: location,
|
|
|
+ const payload = {
|
|
|
+ name: name.value,
|
|
|
+ location: location.value,
|
|
|
logoUrl: logoUrl
|
|
|
};
|
|
|
- const payload2 = {
|
|
|
- file: files[0]
|
|
|
- };
|
|
|
- createStore(payload1).then(res => {
|
|
|
- uploadImage(payload2).then(res => {
|
|
|
- ElMessage.success(`添加商户成功!`);
|
|
|
- });
|
|
|
+ createStore(payload).then(res => {
|
|
|
+ console.log(res);
|
|
|
+ if (res.code === '000') {
|
|
|
+ ElMessage({
|
|
|
+ message: '添加商户成功!',
|
|
|
+ type: 'success',
|
|
|
+ center: true,
|
|
|
+ })
|
|
|
+ } else if (res.code === '400') {
|
|
|
+ ElMessage({
|
|
|
+ message: res.msg,
|
|
|
+ type: 'error',
|
|
|
+ center: true,
|
|
|
+ })
|
|
|
+ }
|
|
|
});
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
@@ -146,7 +149,7 @@ function handleCreateStore() {
|
|
|
<div class="preview-container mt-4" v-if="files.length">
|
|
|
<div v-for="file in files" :key="file.name" class="preview-card">
|
|
|
<div>
|
|
|
- <img class="preview-img" :src="generateURL(file)" />
|
|
|
+ <img class="preview-img" :src="generateURL(file)"/>
|
|
|
<p>
|
|
|
{{ file.name }}
|
|
|
</p>
|