处理图片链接

This commit is contained in:
熊丽君
2021-08-17 10:04:11 +08:00
parent c4727d712f
commit e6ed881b22
4 changed files with 142 additions and 78 deletions

View File

@ -83,3 +83,11 @@ export function getCityByLevel(params) {
params params
}); });
} }
// 中转图片
export function handlePic(data) {
return request({
url: '/mobile/handlePic',
method: 'post',
data
});
}

View File

@ -1,12 +1,33 @@
export function formatRichText(url) { import { handlePic } from '@/api/policy/library';
let src = document.querySelectorAll('#text .ql-editor img'); export function formatRichText(url, id) {
console.log(src); // let src = document.querySelectorAll('#text .ql-editor img');
/**
* 不需要判断域名存不存在
*/
let status = true;
let src = document.querySelectorAll('#text img');
let endUrl = [];
for (let i = 0; i < src.length; i++) { for (let i = 0; i < src.length; i++) {
const string = src[i].getAttribute('src'); const string = src[i].getAttribute('src');
const flag = string.includes('http://'); endUrl.push(string);
if (!flag) src[i].setAttribute('src', url + string);
} }
let src2 = document.querySelectorAll('#text .ql-editor a'); if (endUrl.length) {
const data = {
startUrl: url,
policyId: id,
endUrl
};
handlePic(data).then(({ data: res }) => {
console.log(res);
for (let i = 0; i < src.length; i++) {
src[i].setAttribute('src', res[i].name);
}
});
}
// let src2 = document.querySelectorAll('#text .ql-editor a');
let src2 = document.querySelectorAll('#text a');
for (let i = 0; i < src2.length; i++) { for (let i = 0; i < src2.length; i++) {
const string = src2[i].getAttribute('href'); const string = src2[i].getAttribute('href');
const flag = string.includes('http://'); const flag = string.includes('http://');

View File

@ -73,10 +73,11 @@
</el-form-item> </el-form-item>
<el-form-item label="正文" prop="text"> <el-form-item label="正文" prop="text">
<div id="text"> <div id="text">
<editor v-model="ruleForm.text" :min-height="192" /> <editor v-model="ruleForm.text" :min-height="192" v-if="!editPage" />
<el-input v-html="ruleForm.text" v-else></el-input>
</div> </div>
</el-form-item> </el-form-item>
<el-form-item label="附件"> <el-form-item label="附件" v-if="ruleForm.method !== 1">
<!-- <el-upload <!-- <el-upload
action="https://jsonplaceholder.typicode.com/posts/" action="https://jsonplaceholder.typicode.com/posts/"
:on-preview="handlePreview" :on-preview="handlePreview"
@ -100,10 +101,11 @@
<div class="el-upload__tip" style="color:red" slot="tip">提示仅允许导入xlsxlsx格式文件</div> <div class="el-upload__tip" style="color:red" slot="tip">提示仅允许导入xlsxlsx格式文件</div>
</el-upload> --> </el-upload> -->
<el-button type="info" size="small" @click="upload.open = true">添加附件</el-button> <el-button type="info" size="small" @click="upload.open = true"
>添加附件</el-button
>
</el-form-item> </el-form-item>
<el-form-item v-if="ruleForm.method!==1"> <el-form-item v-if="ruleForm.method !== 1">
<!-- <el-form-item v-if="!editPage"> --> <!-- <el-form-item v-if="!editPage"> -->
<el-button type="primary" @click="submitForm('ruleForm')" <el-button type="primary" @click="submitForm('ruleForm')"
>确定</el-button >确定</el-button
@ -111,16 +113,32 @@
<!-- <el-button @click="resetForm('ruleForm')">重置</el-button> --> <!-- <el-button @click="resetForm('ruleForm')">重置</el-button> -->
</el-form-item> </el-form-item>
</el-form> </el-form>
<el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body> <el-dialog
<el-upload ref="upload" :limit="1" accept=".xlsx, .xls, .docx" :headers="upload.headers" :title="upload.title"
:action="upload.url" :disabled="upload.isUploading" :visible.sync="upload.open"
:on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag> width="400px"
append-to-body
>
<el-upload
ref="upload"
:limit="1"
accept=".xlsx, .xls, .docx"
:headers="upload.headers"
:action="upload.url"
:disabled="upload.isUploading"
:on-progress="handleFileUploadProgress"
:on-success="handleFileSuccess"
:auto-upload="false"
drag
>
<i class="el-icon-upload"></i> <i class="el-icon-upload"></i>
<div class="el-upload__text"> <div class="el-upload__text">
将文件拖到此处 将文件拖到此处
<em>点击上传</em> <em>点击上传</em>
</div> </div>
<div class="el-upload__tip" style="color:red" slot="tip">提示仅允许导入xlsxlsx格式文件</div> <div class="el-upload__tip" style="color: red" slot="tip">
提示仅允许导入xlsxlsx格式文件
</div>
</el-upload> </el-upload>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitFileForm"> </el-button> <el-button type="primary" @click="submitFileForm"> </el-button>
@ -131,7 +149,7 @@
</template> </template>
<script> <script>
import Editor from '@/components/Editor'; import Editor from '@/components/Editor';
import { getToken } from "@/utils/auth"; import { getToken } from '@/utils/auth';
import { addPolicy, updatePolicy, getPolicyInfo } from '@/api/policy/library'; import { addPolicy, updatePolicy, getPolicyInfo } from '@/api/policy/library';
import { getCityByLevel } from '@/api/policy/library'; import { getCityByLevel } from '@/api/policy/library';
export default { export default {
@ -144,13 +162,13 @@ export default {
// 是否显示弹出层(用户导入) // 是否显示弹出层(用户导入)
open: false, open: false,
// 弹出层标题(用户导入) // 弹出层标题(用户导入)
title: "添加附件", title: '添加附件',
// 是否禁用上传 // 是否禁用上传
isUploading: false, isUploading: false,
// 设置上传的请求头部 // 设置上传的请求头部
headers: { Authorization: "Bearer " + getToken() }, headers: { Authorization: 'Bearer ' + getToken() },
// 上传的地址 // 上传的地址
url: process.env.VUE_APP_BASE_API + "/minio/upload" url: process.env.VUE_APP_BASE_API + '/minio/upload',
}, },
editPage: false, editPage: false,
ruleForm: { ruleForm: {
@ -232,7 +250,7 @@ export default {
this.msgSuccess(message); this.msgSuccess(message);
}); });
} }
// this.$router.go(-1); this.$router.go(-1);
} else { } else {
console.log('error submit!!'); console.log('error submit!!');
return false; return false;
@ -243,19 +261,21 @@ export default {
// this.$refs[formName].resetFields(); // this.$refs[formName].resetFields();
// } // }
// 文件上传中处理 // 文件上传中处理
handleFileUploadProgress (event, file, fileList) { handleFileUploadProgress(event, file, fileList) {
this.upload.isUploading = true; this.upload.isUploading = true;
}, },
// 文件上传成功处理 // 文件上传成功处理
handleFileSuccess (response, file, fileList) { handleFileSuccess(response, file, fileList) {
this.ruleForm.text+=`<div>附件<a href="${response.data.url}">${response.data.name}</a></div>` this.ruleForm.text += `<div>附件<a href="${response.data.url}">${response.data.name}</a></div>`;
this.upload.open = false; this.upload.open = false;
this.upload.isUploading = false; this.upload.isUploading = false;
this.$refs.upload.clearFiles(); this.$refs.upload.clearFiles();
this.$alert(response.message, "导入结果", { dangerouslyUseHTMLString: true }); this.$alert(response.message, '导入结果', {
dangerouslyUseHTMLString: true,
});
}, },
// 提交上传文件 // 提交上传文件
submitFileForm () { submitFileForm() {
this.$refs.upload.submit(); this.$refs.upload.submit();
}, },
}, },

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="app-container" style="background-color:#e6e6e6;"> <div class="app-container" style="background-color: #e6e6e6">
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :span="6"> <el-col :span="6">
<div class="box_l"> <div class="box_l">
@ -12,23 +12,24 @@
> >
<div class="user_item_l"> <div class="user_item_l">
<div class="el-avatar"> <div class="el-avatar">
<span :class="item.status?'el-avatar2':''"></span> <span
<img :src="item.icon" alt=""> :class="item.status ? 'el-avatar2' : ''"
v-if="item.msgNoReadCount != 0"
></span>
<img :src="item.icon" alt="" />
</div> </div>
<div class="info"> <div class="info">
<div class="phone">{{item.username}}</div> <div class="phone">{{ item.username }}</div>
<div class="company">科大讯飞股份有限公司</div> <div class="company">{{ num }}--msgNoReadCount:{{item.msgNoReadCount}}</div>
</div> </div>
</div> </div>
<div class="user_item_r"> <div class="user_item_r">14:19</div>
14:19
</div>
</div> </div>
</div> </div>
</el-col> </el-col>
<el-col :span="18"> <el-col :span="18">
<div class="box_r"> <div class="box_r">
<div class="box" v-if="!activeId"> <!-- <div class="box" v-if="!activeId">
<div class="famous-box"> <div class="famous-box">
<img src="~@/assets/image/chat.png" width="300" /> <img src="~@/assets/image/chat.png" width="300" />
<p> <p>
@ -37,9 +38,9 @@
加油吧! ...... 加油吧! ......
</p> </p>
</div> </div>
</div> </div> -->
<div class="box" v-else> <div class="box">
<div id="content" class="content"> <div id="content" class="content" @scroll="scroll">
<div v-for="(item, index) in info" :key="index"> <div v-for="(item, index) in info" :key="index">
<div class="info_r info_default" v-if="item.type == 'leftinfo'"> <div class="info_r info_default" v-if="item.type == 'leftinfo'">
<span class="circle circle_r"></span> <span class="circle circle_r"></span>
@ -72,13 +73,21 @@
<div class="setproblem"> <div class="setproblem">
<textarea <textarea
placeholder="请输入" placeholder="请输入"
style="height: 100%;width: 100%;resize:none;padding-right:125px;outline: none;border-color:#ccc;border-radius:5px;" style="
height: 100%;
width: 100%;
resize: none;
padding-right: 125px;
outline: none;
border-color: #ccc;
border-radius: 5px;
"
id="text" id="text"
v-model="customerText" v-model="customerText"
@keyup.enter="sentMsg()" @keyup.enter="sentMsg()"
></textarea> ></textarea>
<button @click="sentMsg()" class="setproblems"> <button @click="sentMsg()" class="setproblems">
<span style="vertical-align: 4px;"> </span> <span style="vertical-align: 4px"> </span>
</button> </button>
</div> </div>
</div> </div>
@ -89,18 +98,19 @@
</template> </template>
<script> <script>
import {getUsers} from '@/api/service' import { getUsers } from '@/api/service';
export default { export default {
data() { data() {
return { return {
num: 0,
queryParams: { queryParams: {
pageNum: 1, pageNum: 1,
pageSize: 10, pageSize: 10,
}, },
a:{}, a: {},
total:0, total: 0,
userList:[], userList: [],
activeId: null, activeId: '1424606573631770624',
customerText: '', customerText: '',
info: [ info: [
// { // {
@ -119,29 +129,29 @@ export default {
{ {
id: 4, id: 4,
content: '注册网站时需要一次填写完所有的客户资料吗', content: '注册网站时需要一次填写完所有的客户资料吗',
index: 4 index: 4,
}, },
{ id: 5, content: '注册时使用的手机号变更怎么办', index: 5 } { id: 5, content: '注册时使用的手机号变更怎么办', index: 5 },
], ],
robotAnswer: [ robotAnswer: [
{ {
id: 1, id: 1,
content: content:
'答案客户资料完善后是由谁来审批,答案客户资料完善后是由谁来审批,答案客户资料完善后是由谁来审批', '答案客户资料完善后是由谁来审批,答案客户资料完善后是由谁来审批,答案客户资料完善后是由谁来审批',
index: 1 index: 1,
}, },
{ id: 2, content: '测试', index: 2 }, { id: 2, content: '测试', index: 2 },
{ id: 3, content: '测试', index: 3 }, { id: 3, content: '测试', index: 3 },
{ {
id: 4, id: 4,
content: '3333333', content: '3333333',
index: 4 index: 4,
}, },
{ id: 5, content: '44444444', index: 5 } { id: 5, content: '44444444', index: 5 },
], ],
textarea: '', textarea: '',
path: 'ws://192.168.0.125:1919/webStock/' + this.$store.state.user.userId, path: 'ws://192.168.0.125:1919/webStock/' + this.$store.state.user.userId,
socket: '' socket: '',
}; };
}, },
mounted() { mounted() {
@ -151,15 +161,19 @@ export default {
// this.userList = data.list // this.userList = data.list
// this.total = data.total // this.total = data.total
// }) // })
this.getUserList() this.getUserList();
}, },
created() {}, created() {},
methods: { methods: {
getUserList(){ scroll(e) {
getUsers(this.queryParams).then(({data})=>{ // console.log(e.srcElement.scrollTop);
this.userList = data.list this.num = e.srcElement.scrollTop;
this.total = data.total },
}) getUserList() {
getUsers(this.queryParams).then(({ data }) => {
this.userList = data.list;
this.total = data.total;
});
}, },
// 用户发送消息 // 用户发送消息
sentMsg() { sentMsg() {
@ -169,7 +183,7 @@ export default {
var obj = { var obj = {
type: 'rightinfo', type: 'rightinfo',
time: this.getTodayTime(), time: this.getTodayTime(),
content: text content: text,
}; };
this.info.push(obj); this.info.push(obj);
this.appendRobotMsg(this.customerText); this.appendRobotMsg(this.customerText);
@ -250,7 +264,7 @@ export default {
active(id) { active(id) {
this.activeId = id; this.activeId = id;
}, },
init: function() { init: function () {
if (typeof WebSocket === 'undefined') { if (typeof WebSocket === 'undefined') {
alert('您的浏览器不支持socket'); alert('您的浏览器不支持socket');
} else { } else {
@ -265,29 +279,30 @@ export default {
this.socket.onmessage = this.getMessage; this.socket.onmessage = this.getMessage;
} }
}, },
open: function() { open: function () {
console.log('socket连接成功'); console.log('socket连接成功');
}, },
error: function() { error: function () {
console.log('连接错误'); console.log('连接错误');
}, },
getMessage(msg) { getMessage(msg) {
console.log(msg.data); console.log(msg.data);
console.log(JSON.parse(msg.data)); console.log(JSON.parse(msg.data));
this.a = JSON.parse(msg.data) this.a = JSON.parse(msg.data);
// sendUserId // sendUserId
}, },
send: function(params) { send: function (params) {
this.socket.send(params); this.socket.send(params);
}, },
close: function() { close: function () {
console.log('socket已经关闭'); console.log('socket已经关闭');
} },
}, },
destroyed() { destroyed() {
console.log('out');
// 销毁监听 // 销毁监听
this.socket.onclose = this.close; this.socket.onclose = this.close;
} },
}; };
</script> </script>
@ -313,9 +328,9 @@ export default {
.user_item_l { .user_item_l {
display: flex; display: flex;
align-items: center; align-items: center;
.el-avatar{ .el-avatar {
position: relative; position: relative;
span{ span {
width: 7px; width: 7px;
height: 7px; height: 7px;
border-radius: 50%; border-radius: 50%;
@ -324,7 +339,7 @@ export default {
top: 0; top: 0;
right: 0; right: 0;
} }
img{ img {
width: 40px; width: 40px;
height: 40px; height: 40px;
border-radius: 50%; border-radius: 50%;