Commit 14fe440e authored by 杨硕's avatar 杨硕

修改富文本图片上传问题

parent d757efcf
<template>
<quill-editor
ref="myQuillEditor"
v-model="content"
style="padding: 0px;line-height: 0px"
class="ql-editor"
:options="editorOption"
@blur="onEditorBlur($event)"
@focus="onEditorFocus($event)"
@change="onEditorChange($event)"
/>
<div>
<!-- 图片上传组件辅助-->
<el-upload
class="avatar-uploader"
action="#"
:http-request="uploadStart"
:accept="accept"
name="img"
:show-file-list="false"
:on-success="uploadSuccess"
:before-upload="beforeUpload"
/>
<quill-editor
ref="myQuillEditor"
v-model="content"
style="padding: 0px;line-height: 0px"
class="ql-editor"
:options="editorOption"
@blur="onEditorBlur($event)"
@focus="onEditorFocus($event)"
@change="onEditorChange($event)"
/>
</div>
</template>
<script>
import Quill from 'quill'
import editor from 'quill/core/editor' // 引入编辑器
import editor from 'quill/core/editor'
import { activityupload } from '@/api/activity' // 引入编辑器
// 自定义字体大小
const fontSizeStyle = Quill.import('attributors/style/size')
fontSizeStyle.whitelist = ['10px', '12px', '14px', '16px', '18px', '20px', '30px', '32px']
......@@ -42,6 +56,7 @@ const toolbarOptions = [
['image'] // 链接、图片、视频
]
export default {
name: 'Index',
props: {
// 编辑器的内容
value: String,
......@@ -49,6 +64,7 @@ export default {
},
data() {
return {
accept: '.jpg, .png, .jpeg, .JPEG.JPG, .PNG,.bmp,.DMP',
content: '', // 双向数据绑定数据
// 富文本编辑器配置
editorOption: {
......@@ -56,7 +72,17 @@ export default {
theme: 'snow',
modules: {
toolbar: {
container: toolbarOptions
container: toolbarOptions,
handlers: {
image: function (value) {
if (value) {
// 调用element的图片上传组件
document.querySelector('.avatar-uploader input').click()
} else {
this.quill.format('image', false)
}
}
}
}
}
}
......@@ -84,6 +110,31 @@ export default {
editor.enable(false)
}
},
/** 上传接口*/
uploadStart(file) {
const formData = new FormData()
formData.append('file', file.file)
formData.append('temp', 'activity')
// TODO: clear this log
console.log(`formData`, formData)
activityupload(formData).then(res => {
if (res.code === 200) {
// 获取富文本组件实例
const quill = this.$refs.myQuillEditor.quill
// 如果上传成功
// 获取光标所在位置
const length = quill.getSelection().index
// 插入图片,res为服务器返回的图片链接地址
quill.insertEmbed(length, 'image', res.data.url)
// 调整光标到最后
quill.setSelection(length + 1)
}
})
},
beforeUpload(file) { },
uploadSuccess(res) {
console.log('res', res)
},
// 获得焦点事件
onEditorFocus(quill) {
console.log('editor focus!', quill)
......
......@@ -30,15 +30,18 @@
:disabled="formdisable"
placeholder="活动开始时间"
value-format="yyyy-MM-dd HH:mm:ss"
:picker-options="pickoptions"
@change="beginchange"
/>
<div class="reach-title"></div>
<el-date-picker
v-model="form.activityEndDate"
style="width: 100%"
:disabled="formdisable"
:disabled="endtimedisable"
type="datetime"
placeholder="活动结束时间"
value-format="yyyy-MM-dd HH:mm:ss"
:picker-options="endtimepickoptions"
/>
</div>
</el-form-item>
......@@ -80,7 +83,6 @@
list-type="picture"
:show-file-list="false"
:on-success="handleAvatarSuccess"
:before-upload="beforeAvatarUpload"
>
<img v-if="imageUrl" :src="imageUrl" class="avatar">
......@@ -91,12 +93,14 @@
<div v-if="!imageUrl" slot="tip" class="el-upload__tip">支持文件格式:.jpg .gpeg .png.单个文件不能超过4M,推荐上传文件大小:110px*83px</div>
</el-upload>
</el-form-item>
<el-form-item label="活动内容" prop="activityDetails">
<quilleditor v-if="type !== 2" :value="form.activityDetails" :type="richtexttype" @value="getvalue" />
<div v-else style="display: flex;justify-content: center">
<div v-html="form.activityDetails" />
</div>
</el-form-item>
<div :class="type===2? 'editorstyle':''">
<el-form-item label="活动内容" prop="activityDetails">
<quilleditor v-if="type !== 2" :value="form.activityDetails" :type="richtexttype" @value="getvalue" />
<div v-else style="display: flex;justify-content: center;width: 50%">
<div v-html="form.activityDetails" />
</div>
</el-form-item>
</div>
</el-form>
<div v-if="type !== 2 " slot="footer" class="dialog-footer">
<el-button type="primary" :loading="manageLoading" :disabled="manageLoading" @click="submitForm">确 定</el-button>
......@@ -117,10 +121,19 @@ export default {
},
data() {
const dateprop = (rule, value, callback) => {
// const that = this
const begintime = new Date(this.form.activityBeginDate).getTime()
const endtime = new Date(this.form.activityEndDate).getTime()
// TODO: clear this log
console.log(`begintime`, begintime)
// TODO: clear this log
console.log(`endtime`, endtime)
if (!this.form.activityBeginDate) {
callback('请选择活动开始时间')
} else if (!this.form.activityEndDate) {
callback('请选择活动结束时间')
} else if (endtime < begintime) {
callback('活动结束时间不能早于开始时间')
} else {
callback()
}
......@@ -150,7 +163,21 @@ export default {
}
}
return {
pickoptions: {
disabledDate: time => {
const oneDay = 60 * 60 * 24 * 1000
return time.getTime() < Date.now() - oneDay
}
},
endtimepickoptions: {
disabledDate: time => {
if (this.form.activityBeginDate) {
return time.getTime() < new Date(this.form.activityBeginDate).getTime()
}
}
},
richtexttype: '',
endtimedisable: true,
// 图片地址
imageUrl: '',
imgid: '',
......@@ -230,18 +257,21 @@ export default {
this.form = {}
this.richtexttype = '0'
this.formdisable = false
// this.endtimedisable = false
} else if (this.type === 1) {
this.form = this.$route.query.data
this.style = this.$route.query.data.style
this.imageUrl = baseURL + this.form.imgUrl
this.richtexttype = '1'
this.formdisable = false
// this.endtimedisable = false
} else if (this.type === 2) {
this.form = this.$route.query.data
this.style = this.$route.query.data.style
this.imageUrl = baseURL + this.form.imgUrl
this.richtexttype = '2'
this.formdisable = true
// this.endtimedisable = true
this.numinputdisable = true
this.form.activityDetails = this.form.activityDetails.replace(/\<p/gi,
'<p style=" margin: 0px;" ')
......@@ -256,16 +286,22 @@ export default {
// TODO: clear this log
console.log(`this.imageUrl`, this.imageUrl)
},
// 开始时间选择器
beginchange(val) {
if (val) {
this.endtimedisable = false
}
},
getBusiness() {
getbusinessList().then(res => {
this.busoptions = res.data
})
},
beforeAvatarUpload(file) {
const isJPG = file.type === 'image/jpeg'
const isJPG = file.type === 'image/jpeg' || 'image/png' || 'image/jpg'
const isLt2M = file.size / 1024 / 1024 < 2
if (!isJPG) {
this.$message.error('上传图片只能是 JPG 格式!')
this.$message.error('请上传正确格式的图片!')
}
if (!isLt2M) {
this.$message.error('上传图片大小不能超过 2MB!')
......@@ -400,5 +436,15 @@ export default {
color: #999999;
line-height: 10px !important;
}
}
</style>
<style lang="scss">
.editorstyle {
.el-form-item__content {
//width: 50%;
display: flex;
justify-content: center;
}
}
</style>
......@@ -328,9 +328,6 @@
<script>
import {
listType,
delType,
updateType,
exportType,
clearCache
} from '@/api/system/dict/type'
......@@ -514,7 +511,7 @@ export default {
businessId: row.businessId,
status: changestaus
}
this.$confirm('确认要"' + text + '""' + row.name + '"吗?', '提示', {
this.$confirm('是否确认操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
......@@ -615,15 +612,6 @@ export default {
},
// 查看详情
handleDetail(res) {
// this.activityDetail = res
// this.detailopen = open
// this.$router.push({
// path: '/activity/activitydetail',
// query: {
// data: res.businessId,
// routertype: 1 // 判断园区活动跳新增还是商家活动跳新增,0是园区活动,1是商家活动
// }
// })
activitydetail(res.businessId).then(res => {
// TODO: clear this log
console.log(`res`, res)
......
......@@ -461,7 +461,7 @@ export default {
businessId: row.businessId,
status: changestaus
}
this.$confirm('确认要"' + text + '""' + row.name + '"吗?', '提示', {
this.$confirm('是否确认操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
......
......@@ -61,6 +61,11 @@
{{ scope.row.pushTime || '-' }}
</template>
</el-table-column>
<el-table-column label="创建人" prop="pushTime" :show-overflow-tooltip="true">
<template slot-scope="scope">
{{ scope.row.pushTime || '-' }}
</template>
</el-table-column>
<el-table-column label="公告状态" align="center" prop="status">
<template slot-scope="scope">
<!-- <span v-if="scope.row.status === 0" style="color: #D84848 ">未发布</span>-->
......@@ -257,7 +262,7 @@ export default {
businessId: row.businessId,
status: changestaus
}
this.$confirm('确认要"' + text + '""' + row.title + '"吗?', '提示', {
this.$confirm('是否确认操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
......
......@@ -326,4 +326,3 @@ export default {
border-color: #c2e7b0;
}
</style>
......@@ -116,9 +116,9 @@
<img v-if="scope.row.status === 6 || scope.row.status === 7" src="../../assets/image/order/dingdan_icon_tuikuanwancheng@2x.png" style="width: 20px;height: 20px">
<!-- <span v-if="scope.row.status === 7">后台退款完成</span>-->
<span v-if="scope.row.status === 8">支付中</span>
<img v-if="scope.row.status === 9" src="../../assets/image/order/dingdan_icon_zhifuchenggong@2x.png" style="width: 20px;height: 20px">
<img v-if="scope.row.status === 9 || scope.row.status === 11" src="../../assets/image/order/dingdan_icon_zhifuchenggong@2x.png" style="width: 20px;height: 20px">
<img v-if="scope.row.status === 10" src="../../assets/image/order/dingdan_icon_guanbi@2x.png" style="width: 20px;height: 20px">
<span v-if="scope.row.status === 11">已核销</span>
<!-- <span v-if="scope.row.status === 11">已核销</span>-->
</template>
</el-table-column>
<el-table-column label="操作" class-name="small-padding fixed-width" width="150">
......
......@@ -128,7 +128,6 @@
v-hasPermi="['sys:dictConfig:edit']"
size="mini"
type="text"
style="color: #49cec9"
@click="handleUpdate(scope.row)"
>修改</el-button>
<el-button
......
......@@ -159,7 +159,7 @@
<el-form-item label="菜单权限">
<el-checkbox v-model="menuExpand" @change="handleCheckedTreeExpand($event, 'menu')">展开/折叠</el-checkbox>
<el-checkbox v-model="menuNodeAll" @change="handleCheckedTreeNodeAll($event, 'menu')">全选/全不选</el-checkbox>
<el-checkbox v-model="form.menuCheckStrictly" @change="handleCheckedTreeConnect($event, 'menu')">父子联动</el-checkbox>
<!-- <el-checkbox v-model="form.menuCheckStrictly" @change="handleCheckedTreeConnect($event, 'menu')">父子联动</el-checkbox>-->
<el-tree
ref="menu"
class="tree-border"
......@@ -236,7 +236,7 @@
<el-form-item v-show="form.dataScope == 2" label="数据权限">
<el-checkbox v-model="deptExpand" @change="handleCheckedTreeExpand($event, 'dept')">展开/折叠</el-checkbox>
<el-checkbox v-model="deptNodeAll" @change="handleCheckedTreeNodeAll($event, 'dept')">全选/全不选</el-checkbox>
<el-checkbox v-model="form.deptCheckStrictly" @change="handleCheckedTreeConnect($event, 'dept')">父子联动</el-checkbox>
<!-- <el-checkbox v-model="form.deptCheckStrictly" @change="handleCheckedTreeConnect($event, 'dept')">父子联动</el-checkbox>-->
<el-tree
ref="dept"
class="tree-border"
......
......@@ -254,7 +254,18 @@
<el-table-column label="序号" type="index" align="center" width="55" />
<el-table-column label="会员账号" prop="userName" :show-overflow-tooltip="true">
<template slot-scope="scope">
{{ scope.row.userName || '-' }}
<!-- {{ scope.row.userName || '-' }}-->
<el-popover
placement="right"
width="400"
trigger="click">
<el-table :data="gridData">
<el-table-column width="150" property="date" label="日期"></el-table-column>
<el-table-column width="100" property="name" label="姓名"></el-table-column>
<el-table-column width="300" property="address" label="地址"></el-table-column>
</el-table>
<el-button slot="reference">{{scope.row.userName}}</el-button>
</el-popover>
</template>
</el-table-column>
<el-table-column label="有效期开始时间" prop="useBeginTime" :show-overflow-tooltip="true">
......@@ -488,7 +499,7 @@ export default {
businessId: row.businessId,
status: changestaus
}
this.$confirm('确认要"' + text + '""' + row.name + '"吗?', '提示', {
this.$confirm('是否确认操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment