|
|
@@ -3,56 +3,134 @@
|
|
|
<el-row>
|
|
|
<el-card>
|
|
|
<el-row style="position: center">
|
|
|
- <h2>上传封面</h2>
|
|
|
- <el-upload
|
|
|
- class="avatar-uploader"
|
|
|
- action="//api.reghao.cn/api/file/upload/image"
|
|
|
- :show-file-list="false"
|
|
|
- :before-upload="beforeAvatarUpload"
|
|
|
- :on-success="handleAvatarSuccess"
|
|
|
- >
|
|
|
- <img v-if="imageUrl" :src="imageUrl" class="avatar">
|
|
|
- <i v-else class="el-icon-plus avatar-uploader-icon" />
|
|
|
- </el-upload>
|
|
|
+ <h2>发布图片</h2>
|
|
|
+ <file-pond
|
|
|
+ ref="pond"
|
|
|
+ name="file"
|
|
|
+ label-idle="选择图片或拖动图片到此处"
|
|
|
+ label-file-processing="图片正在上传,请稍后"
|
|
|
+ label-file-processing-aborted="图片上传被取消"
|
|
|
+ label-tap-to-retry="尝试重试"
|
|
|
+ label-file-processing-complete="图片上传成功!"
|
|
|
+ label-max-file-size="上传的图片大小不能超过 10MB"
|
|
|
+ label-max-file-size-exceeded="上传的图片大小不能超过 10MB"
|
|
|
+ allow-file-size-validation="true"
|
|
|
+ max-file-size="10MB"
|
|
|
+ accepted-file-types="image/png, image/jpeg, image/jpg, image/gif"
|
|
|
+ :allow-multiple="true"
|
|
|
+ :max-files="12"
|
|
|
+ :server="server"
|
|
|
+ :instant-upload="true"
|
|
|
+ @init="handleFilePondInit"
|
|
|
+ @processfile="handleFilePondSuccess"
|
|
|
+ @removefile="handleFilePondRemove"
|
|
|
+ />
|
|
|
</el-row>
|
|
|
+ <el-form ref="form" :model="form" label-width="80px">
|
|
|
+ <el-form-item label="标题">
|
|
|
+ <el-input v-model="form.title" style="width: 70%; padding-right: 2px" placeholder="标题不能超过 50 个字符" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-button type="primary" @click="onSubmit">立即投稿</el-button>
|
|
|
+ <el-button>取消</el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
</el-card>
|
|
|
</el-row>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import VueFilePond from 'vue-filepond'
|
|
|
+import 'filepond/dist/filepond.min.css'
|
|
|
+import FilePondPluginImagePreview from 'filepond-plugin-image-preview'
|
|
|
+import 'filepond-plugin-image-preview/dist/filepond-plugin-image-preview.min.css'
|
|
|
+import FilePondPluginFileValidateType from 'filepond-plugin-file-validate-type'
|
|
|
+import FilePondPluginFileValidateSize from 'filepond-plugin-file-validate-size'
|
|
|
+
|
|
|
+const FilePond = VueFilePond(
|
|
|
+ FilePondPluginFileValidateType,
|
|
|
+ FilePondPluginImagePreview,
|
|
|
+ FilePondPluginFileValidateSize
|
|
|
+)
|
|
|
+var imgFileIds = []
|
|
|
+
|
|
|
export default {
|
|
|
name: 'PublishImage',
|
|
|
+ components: { FilePond },
|
|
|
data() {
|
|
|
return {
|
|
|
rules: [
|
|
|
value => !value || value.size < 2000000 || 'Avatar size should be less than 2 MB!'
|
|
|
],
|
|
|
imageList: [],
|
|
|
- imageUrl: ''
|
|
|
+ imageUrl: '',
|
|
|
+ server: {
|
|
|
+ url: '//oss.reghao.cn/',
|
|
|
+ revert: null,
|
|
|
+ process: {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': this.$store.getters.token
|
|
|
+ },
|
|
|
+ ondata(formData) {
|
|
|
+ formData.append('channelId', 5)
|
|
|
+ return formData
|
|
|
+ },
|
|
|
+ onload(response) {
|
|
|
+ const resp = JSON.parse(response)
|
|
|
+ if (resp.code === 0) {
|
|
|
+ console.log(resp)
|
|
|
+ //imgFileIds.push(resp.data.imageUploadId)
|
|
|
+ } else {
|
|
|
+ if (resp.msg != null) {
|
|
|
+ this.message = '上传文件出现异常,请重新上传!' + resp.msg
|
|
|
+ } else {
|
|
|
+ this.message = '上传文件出现异常,请重新上传!'
|
|
|
+ }
|
|
|
+ this.showMessage = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ form: {
|
|
|
+ title: null,
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
|
},
|
|
|
methods: {
|
|
|
- beforeAvatarUpload(file) {
|
|
|
- const isJPG = file.type === 'image/jpeg'
|
|
|
- const isLt2M = file.size / 1024 / 1024 < 2
|
|
|
- if (!isJPG) {
|
|
|
- this.$message.error('上传头像图片只能是 JPG 格式!')
|
|
|
- }
|
|
|
- if (!isLt2M) {
|
|
|
- this.$message.error('上传头像图片大小不能超过 2MB!')
|
|
|
+ handleFilePondInit() {
|
|
|
+ // FilePond instance methods are available on `this.$refs.pond`
|
|
|
+ },
|
|
|
+ handleFilePondSuccess(error, metadata) {
|
|
|
+ if (error === null) {
|
|
|
+ return
|
|
|
}
|
|
|
- return isJPG && isLt2M
|
|
|
+ console.log('图片已上传')
|
|
|
+ console.log(metadata)
|
|
|
},
|
|
|
- handleAvatarSuccess(res, file) {
|
|
|
- this.imageList.push(file)
|
|
|
- console.log(this.imageList)
|
|
|
- this.imageUrl = URL.createObjectURL(file.raw)
|
|
|
+ handleFilePondRemove(error, metadata) {
|
|
|
+ console.log('删除已上传的图片')
|
|
|
+ /*if (error === null) {
|
|
|
+ const file = metadata.file
|
|
|
+ const uploadId = this.imgMap[file.name]
|
|
|
+ fetch('//oss.reghao.cn/' + uploadId, {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': this.$store.getters.token
|
|
|
+ },
|
|
|
+ method: 'DELETE'
|
|
|
+ }).then(response => response.json())
|
|
|
+ .then(json => {
|
|
|
+ console.log('删除 this.statusPost.imageFileIds 中相应的图片')
|
|
|
+ })
|
|
|
+ .catch(e => {
|
|
|
+ return null
|
|
|
+ })
|
|
|
+ }*/
|
|
|
},
|
|
|
onSubmit() {
|
|
|
- console.log('submit!')
|
|
|
+ console.log(this.form)
|
|
|
}
|
|
|
}
|
|
|
}
|