|
|
@ -1,8 +1,8 @@ |
|
|
|
<template> |
|
|
|
<template> |
|
|
|
<!-- 内容 --> |
|
|
|
<!-- 内容 --> |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
<el-dialog title="编辑内容" :visible.sync="visible" width="600px" custom-class="module" :close-on-click-modal="false" :before-close="close"> |
|
|
|
<el-dialog title="编辑内容" :visible.sync="visible" width="70%" custom-class="module" :close-on-click-modal="false" :before-close="close"> |
|
|
|
<el-table class="module-table" :data="data.list" header-align="center" row-key="id"> |
|
|
|
<el-table class="module-table" :data="list" header-align="center" row-key="id"> |
|
|
|
<el-table-column type="index" width="60" label="序号" align="center"></el-table-column> |
|
|
|
<el-table-column type="index" width="60" label="序号" align="center"></el-table-column> |
|
|
|
<el-table-column label="图片" min-width="140" align="center"> |
|
|
|
<el-table-column label="图片" min-width="140" align="center"> |
|
|
|
<template slot-scope="scope"> |
|
|
|
<template slot-scope="scope"> |
|
|
@ -30,50 +30,36 @@ |
|
|
|
:active-value="1" |
|
|
|
:active-value="1" |
|
|
|
:inactive-value="0"> |
|
|
|
:inactive-value="0"> |
|
|
|
</el-switch> |
|
|
|
</el-switch> |
|
|
|
<i v-if="data.type === 'introduce'" class="el-icon-edit-outline del" @click="editIntro(scope.row, scope.$index)"></i> |
|
|
|
<i class="el-icon-edit-outline del" @click="editHistory(scope.row, scope.$index)"></i> |
|
|
|
<i class="el-icon-delete del" @click="delRow(data.list, scope.$index)"></i> |
|
|
|
<i class="el-icon-delete del" @click="delRow(data.list, scope.$index)"></i> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
</el-table-column> |
|
|
|
</el-table-column> |
|
|
|
</el-table> |
|
|
|
</el-table> |
|
|
|
|
|
|
|
<div class="plus"> |
|
|
|
|
|
|
|
<i class="el-icon-circle-plus-outline" @click="editHistory(data.originForm, -1)"></i> |
|
|
|
|
|
|
|
</div> |
|
|
|
<span slot="footer" class="dialog-footer"> |
|
|
|
<span slot="footer" class="dialog-footer"> |
|
|
|
<el-button @click="$emit('update:visible', false)">取消</el-button> |
|
|
|
<el-button @click="$emit('update:visible', false)">取消</el-button> |
|
|
|
<el-button type="primary" @click="contentSubmit">确定</el-button> |
|
|
|
<el-button type="primary" @click="historySubmit">确定</el-button> |
|
|
|
</span> |
|
|
|
</span> |
|
|
|
</el-dialog> |
|
|
|
</el-dialog> |
|
|
|
|
|
|
|
|
|
|
|
<Link ref="link" :visible.sync="linkVisible" :data.sync="linkForm" @linkSubmit="linkSubmit" /> |
|
|
|
<Content :data.sync="data" :visible.sync="contentVisible" @contentSubmit="contentSubmit" /> |
|
|
|
|
|
|
|
|
|
|
|
<!-- 剪裁组件弹窗 --> |
|
|
|
|
|
|
|
<el-dialog title="图片裁剪" append-to-body :visible.sync="cropperModel" width="1100px" :close-on-click-modal="false"> |
|
|
|
|
|
|
|
<Cropper |
|
|
|
|
|
|
|
ref="cropper" |
|
|
|
|
|
|
|
:img-file.sync="file" |
|
|
|
|
|
|
|
:is-upload="isUpload" |
|
|
|
|
|
|
|
:fixed="fixed" |
|
|
|
|
|
|
|
:fixedNumber.sync="fixedNumber" |
|
|
|
|
|
|
|
@upload="customUpload" /> |
|
|
|
|
|
|
|
</el-dialog> |
|
|
|
|
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
<script> |
|
|
|
import Link from '@/components/modules/link' |
|
|
|
|
|
|
|
import Setting from '@/setting' |
|
|
|
import Setting from '@/setting' |
|
|
|
import Util from '@/libs/util' |
|
|
|
import Util from '@/libs/util' |
|
|
|
import Cropper from '@/components/img-upload/Cropper' |
|
|
|
import Content from '@/components/modules/content' |
|
|
|
import Axios from 'axios' |
|
|
|
|
|
|
|
export default { |
|
|
|
export default { |
|
|
|
props: ['data', 'visible'], |
|
|
|
props: ['data', 'visible', 'list'], |
|
|
|
components: { |
|
|
|
components: { |
|
|
|
Link, |
|
|
|
Content |
|
|
|
Cropper |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
data() { |
|
|
|
data() { |
|
|
|
return { |
|
|
|
return { |
|
|
|
headers: { |
|
|
|
|
|
|
|
token: Util.local.get(Setting.tokenKey) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
rules: {}, |
|
|
|
rules: {}, |
|
|
|
linkVisible: false, |
|
|
|
linkVisible: false, |
|
|
|
linkForm: {}, |
|
|
|
linkForm: {}, |
|
|
@ -83,176 +69,45 @@ export default { |
|
|
|
file: {}, // 当前被选择的图片文件 |
|
|
|
file: {}, // 当前被选择的图片文件 |
|
|
|
fileId: '', |
|
|
|
fileId: '', |
|
|
|
curForm: {}, |
|
|
|
curForm: {}, |
|
|
|
fixed: false, |
|
|
|
contentVisible: false, |
|
|
|
fixedNumber: [0.88, 1] |
|
|
|
curModule: 0, |
|
|
|
|
|
|
|
curData: {}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
}, |
|
|
|
}, |
|
|
|
watch: { |
|
|
|
|
|
|
|
visible(open) { |
|
|
|
|
|
|
|
// 每次打开的时候处理参数 |
|
|
|
|
|
|
|
open && this.handleForm() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
mounted() { |
|
|
|
mounted() { |
|
|
|
this.handleForm() |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
methods: { |
|
|
|
// 处理form表单参数 |
|
|
|
// 添加行 |
|
|
|
handleForm() { |
|
|
|
addRow() { |
|
|
|
const { forms, type } = this.data |
|
|
|
this.editHistory(this.data.originForm, -1) |
|
|
|
// 这两张类型的模块才需要处理参数 |
|
|
|
}, |
|
|
|
if (type === 'form' || type === 'introduce') { |
|
|
|
// 编辑内容 |
|
|
|
forms.map(e => { |
|
|
|
editHistory(row, i = 0) { |
|
|
|
if (e.type === 'upload') { |
|
|
|
this.data.form = JSON.parse(JSON.stringify(row)) |
|
|
|
if (e.fixedNumber) { |
|
|
|
this.curModule = i |
|
|
|
this.fixed = true |
|
|
|
this.contentVisible = true |
|
|
|
this.fixedNumber = e.fixedNumber |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.fixed = false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (e.required) { |
|
|
|
|
|
|
|
this.rules[e.prop] = [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
required: true, |
|
|
|
|
|
|
|
message: `请${e.type === 'input' ? '输入' : '选择'}${e.label}`, |
|
|
|
|
|
|
|
trigger: e.type === 'input' ? 'blur' : 'change' |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
close() { |
|
|
|
close() { |
|
|
|
this.$emit('update:visible', false) |
|
|
|
this.$emit('update:visible', false) |
|
|
|
}, |
|
|
|
}, |
|
|
|
// 图片裁剪上传事件 |
|
|
|
// 模块设置提交 |
|
|
|
customUpload(data) { |
|
|
|
contentSubmit() { |
|
|
|
const formData = new FormData() |
|
|
|
this.contentVisible = false |
|
|
|
formData.append('file', data, this.file.name) |
|
|
|
const { form } = this.data |
|
|
|
this.imgUpload(formData) |
|
|
|
if (this.curModule === -1) { |
|
|
|
}, |
|
|
|
this.list.push(JSON.parse(JSON.stringify(this.data.form))) |
|
|
|
// 压缩图片 |
|
|
|
|
|
|
|
compress(img) { |
|
|
|
|
|
|
|
const canvas = document.createElement('canvas') |
|
|
|
|
|
|
|
const ctx = canvas.getContext('2d') |
|
|
|
|
|
|
|
// let initSize = img.src.length; |
|
|
|
|
|
|
|
const width = img.width |
|
|
|
|
|
|
|
const height = img.height |
|
|
|
|
|
|
|
canvas.width = width |
|
|
|
|
|
|
|
canvas.height = height |
|
|
|
|
|
|
|
// 铺底色 |
|
|
|
|
|
|
|
ctx.fillStyle = '#fff' |
|
|
|
|
|
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height) |
|
|
|
|
|
|
|
ctx.drawImage(img, 0, 0, width, height) |
|
|
|
|
|
|
|
// 进行压缩 |
|
|
|
|
|
|
|
const ndata = canvas.toDataURL('image/jpeg', 0.8) |
|
|
|
|
|
|
|
return ndata |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// base64转成bolb对象 |
|
|
|
|
|
|
|
dataURItoBlob(base64Data) { |
|
|
|
|
|
|
|
let byteString |
|
|
|
|
|
|
|
if (base64Data.split(',')[0].indexOf('base64') >= 0) { |
|
|
|
|
|
|
|
byteString = atob(base64Data.split(',')[1]) |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
byteString = unescape(base64Data.split(',')[1]) |
|
|
|
const list = this.list[this.curModule] |
|
|
|
} |
|
|
|
for (const i in form) { |
|
|
|
const mimeString = base64Data |
|
|
|
this.$set(list, i, form[i]) |
|
|
|
.split(',')[0] |
|
|
|
|
|
|
|
.split(':')[1] |
|
|
|
|
|
|
|
.split(';')[0] |
|
|
|
|
|
|
|
const ia = new Uint8Array(byteString.length) |
|
|
|
|
|
|
|
for (let i = 0; i < byteString.length; i++) { |
|
|
|
|
|
|
|
ia[i] = byteString.charCodeAt(i) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return new Blob([ia], { |
|
|
|
|
|
|
|
type: mimeString |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 图片上传到服务器 |
|
|
|
|
|
|
|
imgUpload(formData) { |
|
|
|
|
|
|
|
this.isUpload = true |
|
|
|
|
|
|
|
Axios({ |
|
|
|
|
|
|
|
method: 'post', |
|
|
|
|
|
|
|
url: this.api.upload, |
|
|
|
|
|
|
|
data: formData, |
|
|
|
|
|
|
|
headers: { |
|
|
|
|
|
|
|
'Content-Type': 'multipart/form-data', |
|
|
|
|
|
|
|
token: Util.local.get(Setting.tokenKey) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}).then(({ data }) => { |
|
|
|
|
|
|
|
this.$set(this.curForm, 'pic', data.url) |
|
|
|
|
|
|
|
}).catch(res => {}) |
|
|
|
|
|
|
|
this.$refs.cropper.isDisabled = false |
|
|
|
|
|
|
|
this.isUpload = false |
|
|
|
|
|
|
|
this.cropperModel = false |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 图片改变钩子 |
|
|
|
|
|
|
|
changeFile(file, form) { |
|
|
|
|
|
|
|
const { size, name } = file |
|
|
|
|
|
|
|
const ext = name.substring(name.lastIndexOf('.') + 1) |
|
|
|
|
|
|
|
if (!Util.isImg(ext)) { |
|
|
|
|
|
|
|
this.$message.error('请上传图片!') |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (size / 1024 / 1024 > 5) { |
|
|
|
|
|
|
|
this.$message.error('请上传5M以内的图片!') |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.file = file |
|
|
|
|
|
|
|
this.curForm = form |
|
|
|
|
|
|
|
this.cropperModel = true |
|
|
|
|
|
|
|
this.$nextTick(() => { |
|
|
|
|
|
|
|
this.$refs.cropper.updateImg({ |
|
|
|
|
|
|
|
url: window.URL.createObjectURL(file.raw), |
|
|
|
|
|
|
|
size: file.size |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 上传成功 |
|
|
|
|
|
|
|
uploadSuccess(res, row) { |
|
|
|
|
|
|
|
this.$set(row, 'pic', res.url) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 展示链接设置 |
|
|
|
|
|
|
|
toLink(row, i = 0) { |
|
|
|
|
|
|
|
this.linkVisible = true |
|
|
|
|
|
|
|
this.curIndex = i |
|
|
|
|
|
|
|
this.linkForm = row.link |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 链接设置提交 |
|
|
|
|
|
|
|
linkSubmit() { |
|
|
|
|
|
|
|
const el = this.$refs.link |
|
|
|
|
|
|
|
const data = this.data.form ? this.data.form.link : this.data.list[this.curIndex].link |
|
|
|
|
|
|
|
let name |
|
|
|
|
|
|
|
// 站内链接 |
|
|
|
|
|
|
|
if (data.connectionType === 1) { |
|
|
|
|
|
|
|
if (!data.columnId.length) return Util.errorMsg('请选择站内链接') |
|
|
|
|
|
|
|
// 如果选择了文章,则取文章标题作为链接名称,否则取栏目标题 |
|
|
|
|
|
|
|
if (data.articleId) { |
|
|
|
|
|
|
|
const item = el.articles.find(e => e.id == data.articleId) |
|
|
|
|
|
|
|
name = item ? item.title : '' |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
name = el.$refs.column.getCheckedNodes()[0].pathLabels.join('/') |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} else if (data.connectionType === 3) { // 其他站点链接 |
|
|
|
|
|
|
|
if (!data.otherColumnId.length) return Util.errorMsg('请选择栏目') |
|
|
|
|
|
|
|
// 如果选择了文章,则取文章标题作为链接名称,否则取栏目标题 |
|
|
|
|
|
|
|
if (data.otherArticleId) { |
|
|
|
|
|
|
|
const item = el.articles.find(e => e.id == data.otherArticleId) |
|
|
|
|
|
|
|
name = item ? item.title : '' |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
name = el.$refs.otherColumn.getCheckedNodes()[0].pathLabels.join('/') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { // 站外链接 |
|
|
|
|
|
|
|
if (!data.linkAddress) return Util.errorMsg('请输入站外链接') |
|
|
|
|
|
|
|
name = data.linkAddress |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
data.linkName = name |
|
|
|
this.data.form = JSON.parse(JSON.stringify(this.data.originForm)) |
|
|
|
this.linkVisible = false |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
// 模块设置提交 |
|
|
|
// 模块设置提交 |
|
|
|
contentSubmit() { |
|
|
|
historySubmit() { |
|
|
|
this.$emit('contentSubmit') |
|
|
|
this.$emit('historySubmit') |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|