|
|
@@ -0,0 +1,167 @@
|
|
|
+<script setup lang="ts">
|
|
|
+import {ElForm, ElFormItem, ElMessage} from "element-plus";
|
|
|
+import {ref, computed} from 'vue';
|
|
|
+import {createStore} from "../../api/store.ts";
|
|
|
+import {uploadFile} from "../../api/tool.ts";
|
|
|
+
|
|
|
+// 输入框值
|
|
|
+const name = ref('');
|
|
|
+const location = ref('')
|
|
|
+
|
|
|
+// 用于前端阻拦不合法输入
|
|
|
+const hasNameInput = computed(() => name.value != '')
|
|
|
+const hasLocationInput = computed(() => location.value != '')
|
|
|
+
|
|
|
+const nameLegal = hasNameInput
|
|
|
+const locationLegal = hasLocationInput
|
|
|
+
|
|
|
+const isDragging = ref(false)
|
|
|
+const files = ref([])
|
|
|
+const fileInputRef = ref(null)
|
|
|
+
|
|
|
+function onChange() {
|
|
|
+ files.value = [...fileInputRef.value.files]
|
|
|
+}
|
|
|
+
|
|
|
+function dragover(e) {
|
|
|
+ e.preventDefault()
|
|
|
+ isDragging.value = true
|
|
|
+}
|
|
|
+
|
|
|
+function dragleave() {
|
|
|
+ isDragging.value = false
|
|
|
+}
|
|
|
+
|
|
|
+function drop(e) {
|
|
|
+ e.preventDefault()
|
|
|
+ fileInputRef.value.files = e.dataTransfer.files
|
|
|
+ onChange()
|
|
|
+ isDragging.value = false
|
|
|
+}
|
|
|
+
|
|
|
+function remove(i) {
|
|
|
+ files.value.splice(i, 1);
|
|
|
+ console.log(files.value)
|
|
|
+}
|
|
|
+
|
|
|
+const createDisabled = computed(() => {
|
|
|
+ return !(nameLegal.value && locationLegal.value && files.value);
|
|
|
+})
|
|
|
+
|
|
|
+function handleCreateStore() {
|
|
|
+ const payload1 = {
|
|
|
+ name: name,
|
|
|
+ location: location,
|
|
|
+ logoUrl: logoUrl
|
|
|
+ };
|
|
|
+ const payload2 = {
|
|
|
+ file: files[0]
|
|
|
+ };
|
|
|
+ createStore(payload1).then(res => {
|
|
|
+ uploadFile(payload2).then(res => {
|
|
|
+ ElMessage.success(`添加商户成功!`);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<template>
|
|
|
+ <div class="flex flex-col items-center justify-center px-6 py-6 space-y-10 min-h-screen">
|
|
|
+
|
|
|
+ <span class="flex items-center text-2xl font-semibold text-gray-900">
|
|
|
+ Blue Whale Shopping Online
|
|
|
+ </span>
|
|
|
+
|
|
|
+ <el-card class="w-full bg-white rounded-lg shadow-md md:mt-0 sm:max-w-md xl:p-0">
|
|
|
+
|
|
|
+ <div class="p-6 space-y-4 md:space-y-6 sm:p-8">
|
|
|
+
|
|
|
+ <h1 class="text-2xl font-bold leading-tight tracking-tight text-gray-900">
|
|
|
+ 添加商店
|
|
|
+ </h1>
|
|
|
+
|
|
|
+ <el-form class="space-y-4 md:space-y-6">
|
|
|
+
|
|
|
+ <el-form-item>
|
|
|
+ <label for="name" class="inline-block mb-2 text-sm font-medium text-gray-900">商店名</label>
|
|
|
+ <input id="name" v-model="name"
|
|
|
+ required
|
|
|
+ class="bg-gray-50 border border-gray-300 text-gray-900 focus:outline-primary-600 sm:text-sm rounded-lg block w-full p-2.5"
|
|
|
+ placeholder="请输入商店名">
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item>
|
|
|
+ <label for="location" class="inline-block mb-2 text-sm font-medium text-gray-900">商店地址</label>
|
|
|
+ <input id="location" v-model="location"
|
|
|
+ required
|
|
|
+ class="bg-gray-50 border border-gray-300 text-gray-900 focus:outline-primary-600 sm:text-sm rounded-lg block w-full p-2.5"
|
|
|
+ placeholder="楼层-门牌号 如:3楼-305">
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item>
|
|
|
+ <label for="logoUrl" class="inline-block mb-2 text-sm font-medium text-gray-900">商店Logo</label>
|
|
|
+ <div class="main">
|
|
|
+ <div
|
|
|
+ class="dropzone-container"
|
|
|
+ @dragover="dragover"
|
|
|
+ @dragleave="dragleave"
|
|
|
+ @drop="drop"
|
|
|
+ >
|
|
|
+ <input
|
|
|
+ type="file"
|
|
|
+ multiple
|
|
|
+ name="file"
|
|
|
+ id="fileInput"
|
|
|
+ class="hidden-input"
|
|
|
+ @change="onChange"
|
|
|
+ ref="fileInputRef"
|
|
|
+ accept=".pdf,.jpg,.jpeg,.png"
|
|
|
+ />
|
|
|
+
|
|
|
+ <label for="fileInput" class="file-label">
|
|
|
+ <div v-if="isDragging">释放以将文件放到此处。</div>
|
|
|
+ <div v-else>将文件拖到此处或单击此处上传。</div>
|
|
|
+ </label>
|
|
|
+
|
|
|
+ <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)" />
|
|
|
+ <p>
|
|
|
+ {{ file.name }}
|
|
|
+ </p>
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <button
|
|
|
+ class="ml-2"
|
|
|
+ type="button"
|
|
|
+ @click="remove(files.indexOf(file))"
|
|
|
+ title="Remove file"
|
|
|
+ >
|
|
|
+ <b>×</b>
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item>
|
|
|
+ <button @click.prevent="handleCreateStore()"
|
|
|
+ :disabled="createDisabled"
|
|
|
+ class="block my-3 w-full text-white bg-primary-600 hover:bg-primary-700 focus:ring-4 focus:outline-none focus:ring-primary-300 font-medium rounded-lg text-sm px-5 py-3 text-center disabled:bg-primary-100">
|
|
|
+ 添加
|
|
|
+ </button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ </div>
|
|
|
+ </el-card>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+
|
|
|
+</style>
|