unknown
2021-01-05 07fae6b200ff7001c9eeef231b928fe0a6d6206c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<!-- 基础配置 -->
<template>
  <div class="app-container">
 
    <el-form ref="basicForm" label-position="left" :model="basicData" label-width="150px" :rules="rules">
 
      <el-form-item label="分享标题:" prop="shareTitle">
        <el-input v-model="basicData.shareTitle" placeholder="请输入分享标题" class="com-edit-input" />
      </el-form-item>
 
      <el-form-item prop="uploadShareImgs">
        <span slot="label">
          分享图片:<br><span>(500*400像素)</span>
        </span>
        <!-- 上传图片组件(单图) -->
        <el-upload
          ref="refUploadShareImg"
          :auto-upload="false"
          list-type="picture-card"
          :class="{disabled:uploadDisabled}"
          action="#"
          :limit="1"
          :file-list="basicData.uploadShareImgs"
          :on-change="addUploadFiles"
          :on-remove="delUploadFiles"
          :http-request="uploadFileHandle"
          :on-preview="uploadPreview"
          :before-upload="beforeUploadImg"
        >
          <i class="el-icon-plus" />
        </el-upload>
      </el-form-item>
    </el-form>
 
    <div v-if="getAuthValueFN('system_set')" class="com-edit-bottom-btns flex flex-align-center">
      <el-button size="mini" @click="jumpBack">取消</el-button>
      <el-button size="mini" type="primary" @click="submit">提交</el-button>
    </div>
 
    <!-- upload放大图片 -->
    <el-dialog :visible.sync="uploadPreviewVisible" style="text-align:center">
      <img style="max-width:100%" :src="uploadPreviewUrl" alt="">
    </el-dialog>
  </div>
</template>
 
<script>
import mixin_upload from '@/mixins/upload.js' // 通用上传图片预览
export default {
  components: {},
  mixins: [mixin_upload],
  data() {
    return {
      basicData: {
        shareTitle: '',
        uploadShareImgs: [] // 上传分享图
      },
 
      // 表单校验
      rules: {
        shareTitle: [{
          required: true, message: '请填写分享标题', trigger: 'change'
        }],
        uploadShareImgs: [{
          required: true, message: '请选择图片'
        }]
      }
    }
  },
  computed: {
    uploadDisabled() {
      return this.basicData.uploadShareImgs.length > 0
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      this.getBasicData()
    },
 
    // 获取基础配置数据
    getBasicData() {
      this.postFN({
        url: 'admin/systemParameter/info',
        params: {},
        mockData: {
          code: 100,
          msg: '',
          data: {
            'shareImg': 'q1rYm',
            'shareTitle': 'yaD(jiP'
          }
        }
      }, (inf) => {
        this.basicData.shareTitle = inf.shareTitle
        if (inf.shareImg) this.basicData.uploadShareImgs = [{ url: inf.shareImg, status: 'success' }]
      })
    },
 
    jumpBack() {
      this.$router.go(-1)
    },
 
    // 上传支付文件 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
    // 上传前确认格式
    beforeUploadImg(file) {
      const isImg = file.type.indexOf('image/') > -1
      if (!isImg) {
        this.$message.error('必须是选择图片文件')
      }
      return isImg
    },
    // 增加文件
    addUploadFiles(file) {
      this.basicData.uploadShareImgs = [file]
    },
    // 删除文件
    delUploadFiles(file, fileList) {
      this.basicData.uploadShareImgs = fileList
    },
    // 执行上传单文件
    runUploadFiles(cb) {
      if (this.checkNeedUpload(this.basicData.uploadShareImgs)) {
        this.$refs.refUploadShareImg.submit()
      } else {
        cb && cb()
      }
    },
    // 上传分享图
    uploadFileHandle(res) {
      const file = res.file
      const formData = new FormData()
      formData.append('file', file)
      console.log(formData)
      this.postFN({
        url: 'admin/image/upload',
        header: { 'Content-Type': 'multipart/form-data' },
        params: formData,
        mockData: {
          code: 100,
          msg: '',
          data: {
            imgUrl: 'xxx'
          }
        }
      }, (inf) => {
        this.basicData.shareImg = inf.imgUrl
        // this.$refs.refUploadShareImg.clearFiles();
        this.submitReq()
      })
    },
    // 上传支付文件 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
 
    // 提交编辑
    submit() {
      this.$refs['basicForm'].validate(valid => {
        if (valid) {
          this.runUploadFiles(() => {
            this.submitReq()
          })
        }
      })
    },
 
    submitReq() {
      var { basicData } = this
      var {
        shareTitle,
        shareImg
      } = basicData
 
      const params = {
        shareTitle: shareTitle,
        shareImg: shareImg
      }
 
      this.postFN({
        url: 'admin/systemParameter/edit',
        params: params,
        mockData: {
          code: 100,
          msg: '',
          data: {}
        }
      }, () => {
        this.getBasicData()
        this.$messageSuc('保存成功')
      })
    }
  }
}
</script>
 
<style lang="scss" scoped>
 
</style>