travel/admin/src/views/qa/problem.vue

246 lines
6.7 KiB
Vue
Raw Normal View History

2024-06-27 18:57:13 +08:00
<template>
<div class="problem">
<el-row>
2024-06-28 17:30:56 +08:00
<el-col :span="24">
<div class="problem_form">
<el-form :inline="true" ref="form" :model="dataForm" label-width="60px">
<el-form-item label="关键字:">
2024-07-01 18:41:28 +08:00
<el-input v-model="dataForm.keyword" placeholder="请输入搜索关键字" style="width: 400px;" class="filter-item" />
2024-06-28 17:30:56 +08:00
</el-form-item>
<el-form-item>
<el-button type="success" @click="onSubmit">查询</el-button>
</el-form-item>
</el-form>
2024-06-27 18:57:13 +08:00
</div>
2024-06-28 17:30:56 +08:00
</el-col>
2024-06-27 18:57:13 +08:00
</el-row>
<div class="problem_container">
2024-07-17 15:38:58 +08:00
<div class="problem_left" v-infinite-scroll="load" :infinite-scroll-immediate="false" style="overflow:auto;padding: 10px;">
2024-06-28 17:30:56 +08:00
<div @click="handleQacityl(item.city_id)" class="btn" v-for="item in getQaCityList">{{ item.city_name }}</div>
</div>
<div class="problem_right">
<ul class="infinite-list" v-infinite-scroll="load" :infinite-scroll-immediate="false" style="overflow:auto">
<li class="problem_right_container" v-for="item in getQaLists">
<div class="title">
2024-06-28 17:51:17 +08:00
<span v-html="handleprant(item.title)"></span>
2024-06-28 17:30:56 +08:00
<el-button @click="handleZip(item.img_zip)" type="primary">下载图片</el-button>
<el-button @click="handleZip(item.trip_zip)" type="primary">下载行程</el-button>
</div>
<div class="desc_container" v-for="list in item.qaQuestions">
2024-07-29 17:09:19 +08:00
<span style="font-weight: 700;color: #46a6ff;" class="desc" v-html="handleprant(list.title)">
</span>
<el-button @click="copyToClipboard(list.content)" type="primary" size="mini" style="margin-left: 10px;">复制</el-button>
<div class="desc" v-html="handleprantHtml(list.content)">
</div>
2024-06-28 17:30:56 +08:00
</div>
</li>
</ul>
</div>
2024-06-27 18:57:13 +08:00
</div>
</div>
</template>
<script>
2024-07-01 18:41:28 +08:00
import { getQaCityList, getQaList } from '@/api/qa'
2024-06-27 18:57:13 +08:00
export default {
2024-06-28 17:30:56 +08:00
data() {
return {
2024-07-01 18:41:28 +08:00
getQaCityList: [],
getQaLists: [],
dataForm: {
keyword: '',
city_id: ''
2024-06-28 17:30:56 +08:00
}
}
},
created() {
getQaCityList().then(res => {
this.getQaCityList = res.data
})
},
2024-07-01 18:41:28 +08:00
watch: {
'dataForm.keyword': function (newVal) {
if (newVal) {
this.onSubmit();
}
}
},
2024-06-28 17:30:56 +08:00
methods: {
2024-07-01 18:41:28 +08:00
handleQacityl(val) {
getQaList({ city_id: val }).then(res => {
2024-06-28 17:30:56 +08:00
this.getQaLists = res.data.data
})
2024-06-27 18:57:13 +08:00
},
2024-07-01 18:41:28 +08:00
handleZip(url) {
if (url) {
2024-07-30 15:00:46 +08:00
// window.open(url)
fetch(url)
.then(response => response.blob())
.then(blob => {
const link = document.createElement('a');
const objectUrl = URL.createObjectURL(blob);
link.href = objectUrl;
link.download = url.split('/').pop(); // Extract filename from URL
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(objectUrl);
})
.catch(error => {
this.$message({
showClose: true,
message: '下载失败',
type: 'error'
});
console.error('Download error:', error);
});
2024-07-01 18:41:28 +08:00
} else {
2024-06-28 17:30:56 +08:00
this.$message({
showClose: true,
2024-07-30 15:00:46 +08:00
message: '暂无下载链接',
type: 'warning'
});
2024-06-28 17:30:56 +08:00
}
2024-06-27 18:57:13 +08:00
},
2024-07-01 18:41:28 +08:00
load() {
2024-06-28 17:30:56 +08:00
console.log('load')
},
2024-07-01 18:41:28 +08:00
handleprant(val) {
2024-07-02 14:58:25 +08:00
if (!val) return ''; // 处理空值情况,避免返回 undefined 或其他非字符串值
2024-06-28 17:51:17 +08:00
let replaceReg = new RegExp(this.dataForm.keyword, "ig");
2024-07-03 18:01:39 +08:00
let replaceString = `<span style="color: #fff;background-color: #FC0421FF;">${this.dataForm.keyword}</span>`;
2024-06-28 17:30:56 +08:00
return val.replace(replaceReg, replaceString);
},
2024-07-02 14:58:25 +08:00
handleprantHtml(val) {
2024-07-03 17:19:22 +08:00
if (!val) return '';
2024-07-02 14:58:25 +08:00
2024-07-03 17:19:22 +08:00
let p = this.dataForm.keyword;
2024-07-02 14:58:25 +08:00
let regexp = new RegExp(p, "g");
2024-07-03 17:19:22 +08:00
let replacedHtml = val.replace(/(?<=>)[^>]+(?=<[/]?\w+.*>)/g, (v) => {
2024-07-03 18:01:39 +08:00
return v.replace(regexp, `<span style='color: #fff;background-color: #FC0421FF;'>${p}</span>`);
2024-07-02 14:58:25 +08:00
});
2024-07-03 17:19:22 +08:00
// 检查是否有替换发生
if (replacedHtml === val) {
2024-07-03 18:01:39 +08:00
// 如果没有替换发生则调用handleprant
2024-07-03 17:19:22 +08:00
return this.handleprant(val);
}
return replacedHtml;
2024-07-02 14:58:25 +08:00
},
2024-07-01 18:41:28 +08:00
onSubmit() {
2024-06-28 17:30:56 +08:00
getQaList(this.dataForm).then(res => {
2024-06-28 17:51:17 +08:00
this.getQaLists = res.data.data
2024-06-28 17:30:56 +08:00
})
},
copyToClipboard(html) {
const text = this.stripHtml(html);
const input = document.createElement('textarea');
input.value = text;
document.body.appendChild(input);
input.select();
document.execCommand('copy');
document.body.removeChild(input);
this.$message({
showClose: true,
message: '内容已复制'
});
},
stripHtml(html) {
const div = document.createElement('div');
div.innerHTML = html;
return div.textContent || div.innerText || '';
2024-06-27 18:57:13 +08:00
}
2024-06-28 17:30:56 +08:00
}
2024-06-27 18:57:13 +08:00
}
</script>
<style lang="scss" scoped>
2024-06-28 17:06:01 +08:00
@import "~@/assets/fonts/font.css";
2024-07-01 18:41:28 +08:00
body {
2024-06-28 17:06:01 +08:00
font-family: PingFang !important;
}
2024-07-01 18:41:28 +08:00
.infinite-list {
2024-06-28 17:30:56 +08:00
list-style-type: none;
height: calc(100vh - 154px);
padding: 0;
margin: 0;
2024-06-28 17:06:01 +08:00
}
2024-07-01 18:41:28 +08:00
.desc_container {
& + .desc_container {
2024-06-28 17:30:56 +08:00
margin-top: 10px;
padding-top: 10px;
}
2024-07-01 18:41:28 +08:00
.desc_title {
2024-06-28 17:30:56 +08:00
font-size: 18px;
font-weight: 500;
color: #333333;
line-height: 25px;
margin-bottom: 10px;
}
2024-07-01 18:41:28 +08:00
.desc_content {
2024-06-28 17:30:56 +08:00
font-size: 14px;
font-weight: 300;
}
2024-06-28 17:06:01 +08:00
}
2024-07-01 18:41:28 +08:00
.problem {
.problem_form {
2024-06-28 17:30:56 +08:00
margin-top: 10px;
display: flex;
justify-content: center;
}
2024-07-01 18:41:28 +08:00
.problem_container {
2024-06-28 17:30:56 +08:00
display: flex;
2024-07-01 18:41:28 +08:00
.problem_left {
2024-06-28 17:30:56 +08:00
font-family: PingFang, sans-serif;
font-weight: 300;
width: 18%;
background: #fff;
padding: 0 20px;
border-right: 2px solid #46a6ff;
height: calc(100vh - 154px);
2024-07-01 18:41:28 +08:00
.btn {
2024-07-01 11:25:55 +08:00
color: #fff;
2024-06-28 17:30:56 +08:00
padding: 10px 20px;
cursor: pointer;
text-align: center;
background: #46a6ff;
border-radius: 10px;
2024-07-01 18:41:28 +08:00
& + .btn {
2024-06-28 17:30:56 +08:00
margin-top: 10px;
}
}
2024-06-27 18:57:13 +08:00
}
2024-07-01 18:41:28 +08:00
.problem_right {
2024-06-28 17:30:56 +08:00
width: 100%;
background: #fff;
padding: 0 20px;
2024-07-01 18:41:28 +08:00
.problem_right_container {
& + .problem_right_container {
2024-06-28 17:30:56 +08:00
margin-top: 20px;
}
2024-07-01 18:41:28 +08:00
.title {
2024-06-28 17:30:56 +08:00
font-size: 20px;
font-weight: 600;
margin-bottom: 10px;
color: #46a6ff;
2024-07-01 18:41:28 +08:00
&>:nth-child(1) {
2024-06-28 17:30:56 +08:00
margin-right: 40px;
}
2024-06-27 18:57:13 +08:00
}
2024-07-01 18:41:28 +08:00
.desc {
2024-06-28 17:30:56 +08:00
font-size: 14px;
color: #666;
line-height: 24px;
.copy-button {
2024-07-29 17:09:19 +08:00
margin-left: 300px;
}
2024-06-27 18:57:13 +08:00
}
2024-06-28 17:30:56 +08:00
}
2024-06-27 18:57:13 +08:00
}
2024-06-28 17:30:56 +08:00
}
2024-06-27 18:57:13 +08:00
}
2024-06-28 17:30:56 +08:00
</style>