This commit is contained in:
faiz 2024-07-31 09:31:25 +08:00
parent 3c0ca34c5c
commit ea5e45b584
1 changed files with 406 additions and 171 deletions

View File

@ -1,47 +1,112 @@
<template>
<div class="app-container">
<div class="filter-container">
<el-input v-model="listQuery.title" placeholder="标题" style="width: 200px;" class="filter-item" />
<el-select v-model="listQuery.status" filterable placeholder="状态" class="filter-item" style="width: 120px;">
<el-input
v-model="listQuery.title"
placeholder="标题"
style="width: 200px"
class="filter-item"
/>
<el-select
v-model="listQuery.status"
filterable
placeholder="状态"
class="filter-item"
style="width: 120px"
>
<el-option key="" label="请选择" value="" />
<el-option v-for="(v, k) in statusArr" :key="k" :label="v" :value="k" />
</el-select>
<el-button class="filter-item search" type="primary" icon="el-icon-search" @click="getList">搜索</el-button>
<el-button class="filter-item" type="primary" icon="el-icon-circle-plus" @click="onAdd">添加</el-button>
<el-button
class="filter-item search"
type="primary"
icon="el-icon-search"
@click="getList"
>搜索</el-button
>
<el-button
class="filter-item"
type="primary"
icon="el-icon-circle-plus"
@click="onAdd"
>添加</el-button
>
</div>
<el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%; padding-bottom: 60px !important">
<el-table
v-loading="listLoading"
:data="list"
border
fit
highlight-current-row
style="width: 100%; padding-bottom: 60px !important"
>
<el-table-column align="center" label="ID" width="80" prop="id" />
<el-table-column align="center" label="城市" width="80" prop="qaCitys.city_name" />
<el-table-column align="center" label="标题" width="280" style="overflow: hidden;">
<el-table-column
align="center"
label="城市"
width="80"
prop="qaCitys.city_name"
/>
<el-table-column
align="center"
label="标题"
width="280"
style="overflow: hidden"
>
<template slot-scope="scope">
<div class="ellipsis-text">{{ scope.row.title }}</div>
</template>
</el-table-column>
<el-table-column align="center" label="状态" width="100">
<template #default="scope">
<el-switch v-model="scope.row.status" :active-value="1" :inactive-value="0" @change="updateStatus(scope.row)" />
<el-switch
v-model="scope.row.status"
:active-value="1"
:inactive-value="0"
@change="updateStatus(scope.row)"
/>
</template>
</el-table-column>
<el-table-column align="center" width="220" label="操作">
<template #default="scope">
<el-button type="primary" size="small" icon="el-icon-edit" @click="onEdit(scope.row)">编辑</el-button>
<el-button type="danger" size="small" icon="el-icon-delete" @click="onDel(scope.row)">删除</el-button>
<el-button
type="primary"
size="small"
icon="el-icon-edit"
@click="onEdit(scope.row)"
>编辑</el-button
>
<el-button
type="danger"
size="small"
icon="el-icon-delete"
@click="onDel(scope.row)"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
<pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
<pagination
v-show="total > 0"
:total="total"
:page.sync="listQuery.page"
:limit.sync="listQuery.limit"
@pagination="getList"
/>
<el-dialog title="添加QA" :visible.sync="dialogCreate">
<el-form label-width="120px" :model="anchors">
<el-form-item label="城市">
<el-select v-model="anchors.city_id" placeholder="请选择">
<el-form-item style="display: inline-flex;text-align: left;width: 770px;">
<el-form-item
style="display: inline-flex; text-align: left; width: 770px"
>
<el-option
v-for="item in getQaCitys"
:key="item.city_id"
style="display: inline-flex;word-break: break-all;"
style="display: inline-flex; word-break: break-all"
:label="item.city_name"
:value="item.city_id"
/>
@ -49,23 +114,41 @@
</el-select>
</el-form-item>
<el-form-item label="旅游路线">
<el-input v-model="anchors.title" type="text" placeholder="请输入旅游路线" />
<el-input
v-model="anchors.title"
type="text"
placeholder="请输入旅游路线"
/>
</el-form-item>
<el-form-item label="QA内容">
<div class="mistake-content" v-for="(item, index) in anchors.qaQuestions">
<div
class="mistake-content"
v-for="(item, index) in anchors.qaQuestions"
>
<div class="mistake-left">
<div>副标题</div>
<div class="qa-desc">
<el-input style="width: 100px;margin-right: 10px;" v-model="item.sort" type="text" placeholder="序号" />
<el-input v-model="item.title" type="text" placeholder="请输入副标题" />
<el-input
style="width: 100px; margin-right: 10px"
v-model="item.sort"
type="text"
placeholder="序号"
/>
<el-input
v-model="item.title"
type="text"
placeholder="请输入副标题"
/>
</div>
<div>内容</div>
<div style="border: 1px solid #ccc;">
<div style="border: 1px solid #ccc">
<myEditor v-model="item.content" />
</div>
</div>
<div class="mistake-right">
<el-button @click="handleDel(index)" type="danger">删除</el-button>
<el-button @click="handleDel(index)" type="danger"
>删除</el-button
>
</div>
</div>
<div class="mistake-btn">
@ -73,7 +156,13 @@
</div>
</el-form-item>
<el-form-item label="状态">
<el-switch v-model="anchors.status" :active-value="1" :inactive-value="0" active-color="#13ce66" inactive-color="#ff4949" />
<el-switch
v-model="anchors.status"
:active-value="1"
:inactive-value="0"
active-color="#13ce66"
inactive-color="#ff4949"
/>
</el-form-item>
<el-form-item label="上传图片">
<el-upload
@ -82,10 +171,24 @@
:show-file-list="false"
:on-success="handleAvatarSuccess"
>
<div v-if="anchors.img_zip" class="img-box">
<i @click.stop="handleClose('img_zip')" class="close el-icon-close" />
<i v-if="!checkIfUrlContainsImage(anchors.img_zip)" class="el-icon-folder" />
<img v-else style="width: 100px;height: 100px;" :src="anchors.img_zip" class="avatar" alt="">
<div v-if="anchors.img_zip">
<div v-for="(item, index) in anchors.img_zip" class="img-box">
<i
@click.stop="handleClose('img_zip', index)"
class="close el-icon-close"
/>
<i
v-if="!checkIfUrlContainsImage(anchors.img_zip)"
class="el-icon-folder"
/>
<img
v-else
style="width: 100px; height: 100px"
:src="item"
class="avatar"
alt=""
/>
</div>
</div>
<i v-else class="el-icon-plus avatar-uploader-icon" />
</el-upload>
@ -99,10 +202,42 @@
:show-file-list="false"
:on-success="handleSuccess"
>
<div v-if="anchors.trip_zip" class="img-box">
<i @click.stop="handleClose('trip_zip')" class="close el-icon-close" />
<i v-if="!checkIfUrlContainsImage(anchors.trip_zip)" class="el-icon-folder" />
<img v-else style="width: 100px;height: 100px;" :src="anchors.trip_zip" class="avatar" alt="">
<!-- <div v-if="anchors.trip_zip" class="img-box">
<i
@click.stop="handleClose('trip_zip')"
class="close el-icon-close"
/>
<i
v-if="!checkIfUrlContainsImage(anchors.trip_zip)"
class="el-icon-folder"
/>
<img
v-else
style="width: 100px; height: 100px"
:src="anchors.trip_zip"
class="avatar"
alt=""
/>
</div>
<i v-else class="el-icon-plus avatar-uploader-icon" /> -->
<div v-if="anchors.trip_zip">
<div v-for="(item, index) in anchors.trip_zip" class="img-box">
<i
@click.stop="handleClose('trip_zip', index)"
class="close el-icon-close"
/>
<i
v-if="!checkIfUrlContainsImage(item)"
class="el-icon-folder"
/>
<img
v-else
style="width: 100px; height: 100px"
:src="item"
class="avatar"
alt=""
/>
</div>
</div>
<i v-else class="el-icon-plus avatar-uploader-icon" />
</el-upload>
@ -111,7 +246,9 @@
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button v-loading="loading" type="primary" @click="onSave"> </el-button>
<el-button v-loading="loading" type="primary" @click="onSave"
> </el-button
>
</div>
</el-dialog>
@ -119,11 +256,17 @@
<el-form label-width="120px" :model="anchors">
<el-form-item label="城市">
<el-select v-model="anchors.city_id" placeholder="请选择">
<el-form-item style="display: inline-flex;text-align: left;width: 770px;">
<el-form-item
style="display: inline-flex; text-align: left; width: 770px"
>
<el-option
v-for="item in getQaCitys"
:key="item.city_id"
style="width: 250px;display: inline-flex;word-break: break-all;"
style="
width: 250px;
display: inline-flex;
word-break: break-all;
"
:label="item.city_name"
:value="item.city_id"
/>
@ -131,23 +274,41 @@
</el-select>
</el-form-item>
<el-form-item label="旅游路线">
<el-input v-model="anchors.title" type="text" placeholder="请输入旅游路线" />
<el-input
v-model="anchors.title"
type="text"
placeholder="请输入旅游路线"
/>
</el-form-item>
<el-form-item label="QA内容">
<div class="mistake-content" v-for="(item,index) in anchors.qaQuestions">
<div
class="mistake-content"
v-for="(item, index) in anchors.qaQuestions"
>
<div class="mistake-left">
<div>副标题</div>
<div class="qa-desc">
<el-input style="width: 100px;margin-right: 10px;" v-model="item.sort" type="text" placeholder="序号" />
<el-input v-model="item.title" type="text" placeholder="请输入副标题" />
<el-input
style="width: 100px; margin-right: 10px"
v-model="item.sort"
type="text"
placeholder="序号"
/>
<el-input
v-model="item.title"
type="text"
placeholder="请输入副标题"
/>
</div>
<div>内容</div>
<div style="border: 1px solid #ccc;">
<div style="border: 1px solid #ccc">
<myEditor v-model="item.content" />
</div>
</div>
<div class="mistake-right">
<el-button @click="handleDel(index)" type="danger">删除</el-button>
<el-button @click="handleDel(index)" type="danger"
>删除</el-button
>
</div>
</div>
<div class="mistake-btn">
@ -155,7 +316,13 @@
</div>
</el-form-item>
<el-form-item label="状态">
<el-switch v-model="anchors.status" :active-value="1" :inactive-value="0" active-color="#13ce66" inactive-color="#ff4949" />
<el-switch
v-model="anchors.status"
:active-value="1"
:inactive-value="0"
active-color="#13ce66"
inactive-color="#ff4949"
/>
</el-form-item>
<el-form-item label="上传图片">
<el-upload
@ -165,9 +332,21 @@
:on-success="handleAvatarSuccess"
>
<div v-if="anchors.img_zip" class="img-box">
<i @click.stop="handleClose('img_zip')" class="close el-icon-close" />
<i v-if="!checkIfUrlContainsImage(anchors.img_zip)" class="el-icon-folder" />
<img v-else style="width: 100px;height: 100px;" :src="anchors.img_zip" class="avatar" alt="">
<i
@click.stop="handleClose('img_zip')"
class="close el-icon-close"
/>
<i
v-if="!checkIfUrlContainsImage(anchors.img_zip)"
class="el-icon-folder"
/>
<img
v-else
style="width: 100px; height: 100px"
:src="anchors.img_zip"
class="avatar"
alt=""
/>
</div>
<i v-else class="el-icon-plus avatar-uploader-icon" />
</el-upload>
@ -182,9 +361,21 @@
:on-success="handleSuccess"
>
<div v-if="anchors.trip_zip" class="img-box">
<i @click.stop="handleClose('trip_zip')" class="close el-icon-close" />
<i v-if="!checkIfUrlContainsImage(anchors.trip_zip)" class="el-icon-folder" />
<img v-else style="width: 100px;height: 100px;" :src="anchors.trip_zip" class="avatar" alt="">
<i
@click.stop="handleClose('trip_zip')"
class="close el-icon-close"
/>
<i
v-if="!checkIfUrlContainsImage(anchors.trip_zip)"
class="el-icon-folder"
/>
<img
v-else
style="width: 100px; height: 100px"
:src="anchors.trip_zip"
class="avatar"
alt=""
/>
</div>
<i v-else class="el-icon-plus avatar-uploader-icon" />
</el-upload>
@ -193,22 +384,24 @@
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button v-loading="loading" type="primary" @click="onSave"> </el-button>
<el-button v-loading="loading" type="primary" @click="onSave"
> </el-button
>
</div>
</el-dialog>
</div>
</template>
<script>
import Pagination from '@/components/PaginationFixed'
import myEditor from '@/components/Wangeditor/index.vue'
import Pagination from "@/components/PaginationFixed";
import myEditor from "@/components/Wangeditor/index.vue";
export default {
name: 'getQa',
name: "getQa",
components: { Pagination, myEditor },
data() {
return {
statusArr: { 0: '禁用', 1: '启用' },
statusArr: { 0: "禁用", 1: "启用" },
list: [],
total: 0,
loading: false,
@ -217,163 +410,205 @@ export default {
page: 1,
limit: 10,
status: null,
city_name: '',
title: '',
content: '',
img_zip:'',
trip_zip:''
city_name: "",
title: "",
content: "",
img_zip: [],
trip_zip: [],
},
dialogCreate: false,
dialogEdit: false,
item: {},
anchors: {
qaQuestions: [],
img_zip:'',
trip_zip:''
img_zip: [],
trip_zip: [],
},
getQaCitys: {}
}
getQaCitys: {},
};
},
created() {
this.listQuery.status = this.$route.query.status || null
this.listQuery.content = this.$route.query.content || null
this.getList()
this.getQaCity()
this.listQuery.status = this.$route.query.status || null;
this.listQuery.content = this.$route.query.content || null;
this.getList();
this.getQaCity();
// this.onChange()
},
methods: {
checkIfUrlContainsImage(url) {
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.svg', '.webp'];
console.log('========fffff====' + imageExtensions.some(extension => url.toLowerCase().endsWith(extension)))
return imageExtensions.some(extension => url.toLowerCase().endsWith(extension));
const imageExtensions = [
".jpg",
".jpeg",
".png",
".gif",
".bmp",
".svg",
".webp",
];
console.log(
"========fffff====" +
imageExtensions.some((extension) =>
url.toLowerCase().endsWith(extension)
)
);
return imageExtensions.some((extension) =>
url.toLowerCase().endsWith(extension)
);
},
handleClose(val) {
this.anchors[val] = ''
this.anchors[val] = "";
},
handleAdd() {
this.anchors.qaQuestions.push({
sort:this.anchors.qaQuestions[this.anchors.qaQuestions.length-1].sort+1,
title: '',
content: ''
})
sort:
this.anchors.qaQuestions[this.anchors.qaQuestions.length - 1].sort +
1,
title: "",
content: "",
});
},
handleDel(id) {
if (this.anchors.qaQuestions.length == 1) {
this.$message({
message: '至少保留一条',
type: 'warning'
message: "至少保留一条",
type: "warning",
});
return
return;
}
this.anchors.qaQuestions = this.anchors.qaQuestions.filter((item,i)=>i!==id)
this.anchors.qaQuestions = this.anchors.qaQuestions.filter(
(item, i) => i !== id
);
},
getList() {
this.listLoading = true
this.$axios.get('/admin/qa/getQa', { params: this.listQuery }).then(response => {
this.list = response.data.data
this.total = response.data.total
this.listLoading = false
}).catch(() => {
this.listLoading = false
this.listLoading = true;
this.$axios
.get("/admin/qa/getQa", { params: this.listQuery })
.then((response) => {
this.list = response.data.data;
this.total = response.data.total;
this.listLoading = false;
})
.catch(() => {
this.listLoading = false;
});
},
handleAvatarSuccess(res, file) {
console.log('====1111===' + res)
this.anchors.img_zip = `${window.location.protocol}//${window.location.host}${res.data}`
console.log('====111122222===' + this.anchors.img_zip)
console.log("====1111===" + res);
this.anchors.img_zip.push(
`${window.location.protocol}//${window.location.host}${res.data}`
);
console.log("====111122222===" + this.anchors.img_zip);
},
handleSuccess(res, file) {
console.log('====222222===' + res)
this.anchors.trip_zip = `${window.location.protocol}//${window.location.host}${res.data}`
console.log('====111122222===' + this.anchors.trip_zip)
console.log("====222222===" + res);
this.anchors.trip_zip.push(
`${window.location.protocol}//${window.location.host}${res.data}`
);
console.log("====111122222===" + this.anchors.trip_zip);
},
onAdd() {
this.anchors.qaQuestions=[{
this.anchors.qaQuestions = [
{
sort: 1,
title: '',
content: ''
}]
title: "",
content: "",
},
];
// 0
this.anchors.img_zip = ''
this.anchors.trip_zip = ''
this.dialogCreate = true
this.anchors.img_zip = [];
this.anchors.trip_zip = [];
this.dialogCreate = true;
},
onEdit(item) {
if (!item.qaQuestions.length) {
this.anchors = {
...item,
qaQuestions:[{
qaQuestions: [
{
sort: 1,
title: '',
content: ''
}]
}
title: "",
content: "",
},
],
};
} else {
this.anchors = { ...item}
this.anchors = { ...item };
}
this.anchors.img_zip = item.img_zip
this.anchors.trip_zip = item.trip_zip
this.dialogEdit = true
this.anchors.img_zip = item.img_zip;
this.anchors.trip_zip = item.trip_zip;
this.dialogEdit = true;
},
onSave() {
if (this.loading) return
this.loading = true
const api = this.dialogCreate ? '/admin/qa/addQa' : '/admin/qa/editQa'
this.$axios.post(api, this.anchors).then(() => {
this.dialogCreate = false
this.dialogEdit = false
this.loading = false
this.getList()
}).catch(() => {
this.loading = false
if (this.loading) return;
this.loading = true;
const api = this.dialogCreate ? "/admin/qa/addQa" : "/admin/qa/editQa";
this.$axios
.post(api, this.anchors)
.then(() => {
this.dialogCreate = false;
this.dialogEdit = false;
this.loading = false;
this.getList();
})
.catch(() => {
this.loading = false;
});
},
onDel(item) {
this.$axios.post('/admin/qa/delQa', { id: item.id }).then(() => {
this.getList()
}).catch(() => {
this.$axios
.post("/admin/qa/delQa", { id: item.id })
.then(() => {
this.getList();
})
.catch(() => {});
},
getQaCity() {
this.$axios.post('/admin/qacity/getQaCity').then(response => {
this.getQaCitys = response.data
this.getList()
}).catch(() => {
this.$axios
.post("/admin/qacity/getQaCity")
.then((response) => {
this.getQaCitys = response.data;
this.getList();
})
.catch(() => {});
},
updateSort(item) {
this.$axios.post('/admin/qa/editQa', { id: item.id, sort: item.sort }).then(() => {
this.getList()
}).catch(() => {
this.$axios
.post("/admin/qa/editQa", { id: item.id, sort: item.sort })
.then(() => {
this.getList();
})
.catch(() => {});
},
updateStatus(item) {
this.$axios.post('/admin/qa/editQa', { id: item.id, status: item.status }).then(() => {
this.getList()
}).catch(() => {
this.$axios
.post("/admin/qa/editQa", { id: item.id, status: item.status })
.then(() => {
this.getList();
})
}
.catch(() => {});
},
},
mounted() {
// ajax
setTimeout(() => {
this.html = '<p>模拟 Ajax 异步设置内容 HTML</p>'
}, 1500)
this.html = "<p>模拟 Ajax 异步设置内容 HTML</p>";
}, 1500);
},
beforeDestroy() {
const editor = this.editor
if (editor == null) return
editor.destroy() //
}
}
const editor = this.editor;
if (editor == null) return;
editor.destroy(); //
},
};
</script>
<style scoped>
.img-box {
position: relative;
display: inline-block;
}
.el-icon-folder {
color: #409EFF !important;
color: #409eff !important;
font-size: 100px;
}
.close {
@ -381,7 +616,7 @@ export default {
top: -10px;
right: -8px;
font-size: 18px;
color: #409EFF;
color: #409eff;
}
.qa-desc {
display: flex;
@ -425,7 +660,7 @@ export default {
overflow: hidden;
}
.avatar-uploader .el-upload:hover {
border-color: #409EFF;
border-color: #409eff;
}
.avatar-uploader-icon {
border: 1px solid #979797;