| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- <template>
- <div class="upload-file">
- <el-upload
- class="upload-demo"
- action="#"
- :http-request="handlRequest"
- :before-remove="beforeRemove"
- :on-remove="handleRemove"
- :on-preview="handleItem"
- multiple
- :before-upload="beforeUpload"
- :file-list="fileList"
- :show-file-list="!showLib"
- :disabled="disabled"
- >
- <slot>
-
- <el-button :disabled="disabled" type="primary" icon="el-icon-plus">点击上传</el-button>
- </slot>
- </el-upload>
- <el-button type="primary" class="lib" @click="handleOpenLib" v-if="showLib"
- >文档库</el-button
- >
- <div class="imgs-box" v-if="fileList.length && showLib">
- <p class="imgs-p">
- <span> {{ fileList[0].name }}</span>
- <el-link @click="delFileList" type="primary" class="link">删除</el-link>
- </p>
- </div>
- <!--图文档弹窗 -->
- <el-dialog
- title="图文档"
- append-to-body
- :visible.sync="documentVisible"
- width="72%"
- >
- <el-form label-width="100px">
- <el-row :gutter="12">
- <el-col :span="8">
- <el-form-item label-width="70px" label="文档名称">
- <el-input v-model="documentForm.name"></el-input>
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-button type="primary" @click="reload">搜索</el-button>
- </el-col>
- </el-row>
- </el-form>
- <ele-pro-table
- ref="table"
- :current.sync="selectItem"
- :columns="columns"
- highlight-current-row
- :datasource="datasource"
- :initLoad="false"
- height="500px"
- class="dict-table"
- tool-class="ele-toolbar-actions"
- >
- </ele-pro-table>
- <div slot="footer" class="dialog-footer">
- <el-button size="small" @click="documentVisible = false"
- >关 闭</el-button
- >
- <el-button size="small" @click="submitDocument" type="primary"
- >确 认</el-button
- >
- </div>
- </el-dialog>
- </div>
- </template>
- <script>
- import {
- uploadFile,
- removeFile,
- getFileList,
- getFile
- } from '@/api/system/file/index.js';
- import { getImageUrl, getImagePath } from '@/utils/file';
- export default {
- props: {
- value: {
- type: [Array,String],
- default: () => []
- },
- // 所属模块
- module: {
- type: String,
- required: true
- },
- // 文档库
- showLib: {
- type: Boolean,
- default: false
- },
- // 限制数量
- limit: {
- type: Number,
- default: -1
- },
- // 限制大小 mb
- size: {
- type: Number,
- default: 10
- },
- disabled:{
- default:false,
- type:Boolean
- }
- },
- data () {
- return {
- documentVisible: false,
- selectItem: null,
- documentForm: {
- name: ''
- },
- columns: [
- {
- label: '序号',
- type: 'index',
- width: 55,
- align: 'center'
- },
- {
- label: '文档名称',
- prop: 'name',
- minWidth: '180',
- showOverflowTooltip: true
- },
- {
- label: '文档类型',
- prop: 'type'
- },
- {
- label: '系统'
- },
- {
- label: '储存路径',
- prop: 'storePath',
- minWidth: '180',
- showOverflowTooltip: true
- },
- {
- label: '模块名',
- prop: 'module'
- },
- {
- label: '上传时间',
- prop: 'createTime'
- }
- ]
- };
- },
- computed: {
- fileList: {
- set (val) {
- // console.log(val);
- this.$emit(
- 'input',
- val.map((item) => ({
- ...item,
- url: getImagePath(item.url)
- }))
- );
- },
- get () {
- // console.log(this.value, 2);
- if(!Array.isArray(this.value)) return []
- const arr =
- (this.value &&
- this.value.map((item) => ({
- ...item,
- url: getImageUrl(item.url)
- }))) ||
- [];
- return arr;
- }
- }
- },
- methods: {
- //点击查看图片
- handleItem(file){
- console.log(file,'5555')
- getFile({ objectName: file.storePath }, file.name);
- },
- delFileList () {
- this.$emit('input', []);
- },
- handleOpenLib () {
- this.documentVisible = true;
- this.$nextTick(() => {
- this.reload();
- });
- },
- //图文档勾选
- submitDocument () {
- this.$emit('input', [
- { url: this.selectItem.storePath, ...this.selectItem }
- ]);
- this.documentVisible = false;
- },
- datasource ({ page, limit }) {
- return getFileList({
- ...this.documentForm,
- pageNum: page,
- size: limit
- });
- },
- reload () {
- this.$refs.table.reload();
- },
- beforeRemove (file) {
- if (file.id) {
- return removeFile({
- fileId: file.id
- }).then(() => {
- return true;
- });
- } else {
- return true;
- }
- },
- handleRemove (file, fileList) {
- this.fileList = fileList;
- },
- beforeUpload (file) {
- if (file.size / 1024 / 1024 > this.size) {
- this.$message.error(`大小不能超过 ${this.size}MB`);
- return false;
- }
- if (this.limit > 0 && this.fileList.length === this.limit) {
- this.$message.error(`最多上传 ${this.limit}个文件`);
- return false;
- }
- return uploadFile({
- module: this.module,
- multiPartFile: file
- }).then((res) => {
- if (res.data) {
- this.$emit('input', [
- ...(this.value || []),
- { ...file, url: res.data.storePath, ...res.data }
- ]);
- }
- return res.data;
- });
- },
- handlRequest () {
- return Promise.resolve();
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .upload-file {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- .lib {
- margin-left: 12px;
- }
- .imgs-box {
- margin-left: 10px;
- flex: 1;
- }
- .imgs-box .imgs-p {
- height: 30px;
- background: #f0f3f3;
- line-height: 30px;
- min-width: 480px;
- margin-bottom: 5px;
- padding: 0 10px;
- display: flex;
- justify-content: space-between;
- }
- }
- </style>
|