feat: 添加文件上传组件

This commit is contained in:
谢泓 2022-08-04 19:47:28 +08:00
parent 85b7a6645d
commit 33cd4431fe
4 changed files with 134 additions and 4 deletions

View File

@ -0,0 +1,18 @@
<template>
<el-dialog
:model-value="dialogVisible"
:title="dialogTitle"
width="30%"
@close="handleClose"
>
<el-form>
<el-form-item label="行政区划"></el-form-item>
<el-form-item label="隶属"></el-form-item>
<el-form-item label="海拔"></el-form-item>
</el-form>
</el-dialog>
</template>
<script setup></script>
<style lang="scss" scoped></style>

View File

@ -22,17 +22,27 @@
<template v-slot="scope"> <template v-slot="scope">
{{ scope.row[index] }} {{ scope.row[index] }}
</template> </template>
</el-table-column> <!-- <template #suffix>
<el-table-column label="操作" width="60" align="center"> <el-icon class="el-input__icon" @click="handleIconClick">
<el-icon><Edit /></el-icon> <edit />
</el-icon>
</template> -->
</el-table-column> </el-table-column>
</el-table> </el-table>
<el-button type="primary" @click="handleDialog()">编辑属性</el-button>
</div> </div>
<!-- <tableDialog
v-model="dialogVisible"
:dialogTitle="dialogTitle"
v-if="dialogVisible"
:dialogTableValue="dialogTableValue"
/> -->
</template> </template>
<script setup> <script setup>
import { onMounted, ref } from 'vue' import { onMounted, ref } from 'vue'
import { Edit } from '@element-plus/icons-vue' // import tableDialog from './tableDialog.vue'
// import { isNull } from '@/utils/filters'
const originData = ref([ const originData = ref([
{ {
@ -47,6 +57,10 @@ const originTitle = ref(['行政区划', '隶属', '海拔'])
const transTitle = ref(['字段名', '属性内容']) const transTitle = ref(['字段名', '属性内容'])
const transData = ref([]) const transData = ref([])
// const dialogVisible = ref(false)
// const dialogTitle = ref('')
// const dialogTableValue = ref({})
onMounted(() => { onMounted(() => {
// , // ,
const matrixData = originData.value.map((row) => { const matrixData = originData.value.map((row) => {
@ -68,6 +82,17 @@ onMounted(() => {
}) })
console.log(transData.value) console.log(transData.value)
}) })
// const handleDialog = (row) => {
// if (isNull(row)) {
// dialogTitle = ''
// dialogTableValue.value = {}
// } else {
// dialogTitle.value = ''
// dialogTableValue.value = JSON.parse(JSON.stringify(row))
// }
// dialogTableValue.value = true
// }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -0,0 +1,85 @@
<template>
<el-upload
ref="uploadRef"
class="upload-demo"
action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
:auto-upload="false"
:on-preview="handlePreview"
:on-remove="handleRemove"
:before-remove="beforeRemove"
multiple
:limit="2"
:on-exceed="handleExceed"
:file-list="fileList"
>
<template #tip>
<div class="el-upload__tip">
只能上传 doc/docx/pdf 文件且不超过 20MB
</div>
</template>
<template #trigger>
<el-button :icon="FolderAdd"></el-button>
</template>
<el-button
class="ml-3"
type="success"
@click="submitUpload"
:icon="UploadFilled"
>
</el-button>
</el-upload>
</template>
<script setup>
import { FolderAdd, UploadFilled } from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ref } from 'vue'
const fileList = ref([
{
name: 'food.jpeg',
url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'
}
// {
// name: 'food2.jpeg',
// url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'
// }
])
const uploadRef = ref()
const submitUpload = () => {
uploadRef.value.submit()
// uploadRef.value!.submit()
}
const handleRemove = (file, fileList) => {
console.log(file, fileList)
}
const handlePreview = (file) => {
console.log(file)
}
//
const handleExceed = (files, fileList) => {
ElMessage.warning({
message: `最多只能上传 2 个文件,本次添加了 ${files.length} 个文件,共添加
${files.length + fileList.length} 个文件`
})
}
//
const beforeRemove = (file, fileList) => {
return ElMessageBox.confirm(`确定移除 ${file.name}`, {
confirmButtonText: '确认',
cancelButtonText: '取消'
}).then(
() => true,
() => false
)
}
</script>
<style lang="scss" scoped>
.upload-demo {
width: 100%;
height: 100%;
.ml-3 {
margin-left: 15px;
}
}
</style>

View File

@ -1,10 +1,12 @@
<template> <template>
<div>表格纵向表头测试</div> <div>表格纵向表头测试</div>
<Tablelist /> <Tablelist />
<Tableupload />
</template> </template>
<script setup> <script setup>
import Tablelist from './components/tableList.vue' import Tablelist from './components/tableList.vue'
import Tableupload from './components/tableUpload.vue'
</script> </script>
<style lang="scss" scoped></style> <style lang="scss" scoped></style>