upload
This commit is contained in:
parent
15ead8a9d2
commit
7c533aeda9
|
|
@ -1,4 +1,6 @@
|
||||||
<template />
|
<template>
|
||||||
|
<div />
|
||||||
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { isNullOrUndef } from '@/utils/is'
|
import { isNullOrUndef } from '@/utils/is'
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<n-upload
|
<n-upload
|
||||||
action="#"
|
|
||||||
:default-file-list="fileList"
|
:default-file-list="fileList"
|
||||||
list-type="image-card"
|
v-bind="getImgOptions"
|
||||||
|
:on-change="handleChange"
|
||||||
|
:on-before-upload="handleBeforeUpload"
|
||||||
>
|
>
|
||||||
点击上传
|
点击上传
|
||||||
</n-upload>
|
</n-upload>
|
||||||
|
|
@ -11,7 +12,6 @@
|
||||||
v-model:show="showModal"
|
v-model:show="showModal"
|
||||||
preset="card"
|
preset="card"
|
||||||
style="width: 600px"
|
style="width: 600px"
|
||||||
title="一张很酷的图片"
|
|
||||||
>
|
>
|
||||||
<img :src="previewImageUrl" style="width: 100%">
|
<img :src="previewImageUrl" style="width: 100%">
|
||||||
</n-modal>
|
</n-modal>
|
||||||
|
|
@ -19,18 +19,64 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
import { defineComponent, reactive, toRefs, computed, unref } from 'vue'
|
||||||
|
import { getToken } from '@/utils/token'
|
||||||
|
export default defineComponent({
|
||||||
name: 'ImgUpload',
|
name: 'ImgUpload',
|
||||||
props: {
|
props: {
|
||||||
options: {
|
options: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: null
|
default: null
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
type: Number,
|
||||||
|
default: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setup() {
|
setup(props, { emit }) {
|
||||||
|
const data = reactive({
|
||||||
|
fileList: []
|
||||||
|
})
|
||||||
|
const BaseURL = window.__APP__GLOB__CONF__?.VITE_APP_GLOB_BASE_API || import.meta.env.VITE_APP_GLOB_BASE_API
|
||||||
|
const getImgOptions = computed(() => {
|
||||||
|
return {
|
||||||
|
...unref(props.options),
|
||||||
|
listType: 'image-card',
|
||||||
|
defaultUpload: props.options.defaultUpload || false,
|
||||||
|
action: `${BaseURL}${props.options.action}`,
|
||||||
|
headers: {
|
||||||
|
'Authorization': getToken(),
|
||||||
|
...props.options.headers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
function handleChange(file) {
|
||||||
|
console.log(222, file)
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @description: 上传前判断文件是否符合条件
|
||||||
|
* @param {*} options
|
||||||
|
* @return {*}
|
||||||
|
*/
|
||||||
|
function handleBeforeUpload(options) {
|
||||||
|
const { file, fileList } = options
|
||||||
|
console.log(11, file, fileList)
|
||||||
|
if (props.size) {
|
||||||
|
const size = file.file.size
|
||||||
|
if (size < props.size * 1024 * 1024) {
|
||||||
|
fileList.splice(fileList.length - 1)
|
||||||
|
$message.error('选择的文件大小不满足条件!')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...toRefs(data),
|
||||||
|
getImgOptions,
|
||||||
|
handleChange,
|
||||||
|
handleBeforeUpload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<style scoped lang='scss'>
|
<style scoped lang='scss'>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
<template />
|
<template>
|
||||||
|
<div />
|
||||||
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { useMessage } from 'naive-ui'
|
import { useMessage } from 'naive-ui'
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
import { defineComponent, computed } from 'vue'
|
import { defineComponent, computed } from 'vue'
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
|
name: 'CardDialogModal',
|
||||||
props: {
|
props: {
|
||||||
options: {
|
options: {
|
||||||
type: Object,
|
type: Object,
|
||||||
|
|
|
||||||
|
|
@ -10,3 +10,9 @@
|
||||||
height: calc(100vh - 48px);
|
height: calc(100vh - 48px);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.n-data-table .n-data-table-tr{
|
||||||
|
th{
|
||||||
|
white-space:nowrap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,7 +11,14 @@
|
||||||
label="头像:"
|
label="头像:"
|
||||||
path="avatar"
|
path="avatar"
|
||||||
>
|
>
|
||||||
<n-upload
|
<uploadImage
|
||||||
|
:options="{
|
||||||
|
max:1,
|
||||||
|
action: '/upload/uploadImage/demo',
|
||||||
|
}"
|
||||||
|
size="2"
|
||||||
|
/>
|
||||||
|
<!-- <n-upload
|
||||||
action="https://www.mocky.io/v2/5e4bafc63100007100d8b70f"
|
action="https://www.mocky.io/v2/5e4bafc63100007100d8b70f"
|
||||||
:default-file-list="previewFileList"
|
:default-file-list="previewFileList"
|
||||||
list-type="image-card"
|
list-type="image-card"
|
||||||
|
|
@ -24,7 +31,7 @@
|
||||||
title="头像"
|
title="头像"
|
||||||
>
|
>
|
||||||
<img :src="form.avatar" style="width: 100%">
|
<img :src="form.avatar" style="width: 100%">
|
||||||
</n-modal>
|
</n-modal> -->
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
<n-form-item label="用户编号:" path="code">
|
<n-form-item label="用户编号:" path="code">
|
||||||
<n-input
|
<n-input
|
||||||
|
|
@ -138,12 +145,13 @@
|
||||||
<script>
|
<script>
|
||||||
import { defineComponent, computed, onMounted, reactive } from 'vue'
|
import { defineComponent, computed, onMounted, reactive } from 'vue'
|
||||||
import Modal from '@/components/Modal/index.vue'
|
import Modal from '@/components/Modal/index.vue'
|
||||||
|
import uploadImage from '@/components/ImgUpload/index.vue'
|
||||||
import { getDeptAll } from '@/api/system/dept/index'
|
import { getDeptAll } from '@/api/system/dept/index'
|
||||||
import { getRoleAll } from '@/api/system/role/index'
|
import { getRoleAll } from '@/api/system/role/index'
|
||||||
import { dataToSelect } from '@/utils/handleData.js'
|
import { dataToSelect } from '@/utils/handleData.js'
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'UserModal',
|
name: 'UserModal',
|
||||||
components: { Modal },
|
components: { Modal, uploadImage },
|
||||||
props: {
|
props: {
|
||||||
visible: {
|
visible: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue