This commit is contained in:
faiz 2024-08-09 11:46:36 +08:00
parent 04f4850b1c
commit 18cdc81d38
2 changed files with 194 additions and 234 deletions

View File

@ -74,7 +74,7 @@
type="primary" type="primary"
size="small" size="small"
icon="el-icon-edit" icon="el-icon-edit"
@click="onEdit(scope.row)" @click="onAdd(scope.row)"
>编辑</el-button >编辑</el-button
> >
<el-button <el-button
@ -96,9 +96,16 @@
@pagination="getList" @pagination="getList"
/> />
<el-dialog title="添加QA" :visible.sync="dialogCreate"> <el-dialog :title="title" :visible.sync="dialogCreate">
<el-form label-width="120px" :model="anchors"> <el-button
<el-form-item label="城市"> class="filter-items"
v-loading="loading"
type="primary"
@click="onSave"
> </el-button
>
<el-form ref="addForm" label-width="120px" :model="anchors">
<el-form-item label="城市" prop="city_id">
<el-select v-model="anchors.city_id" placeholder="请选择"> <el-select v-model="anchors.city_id" placeholder="请选择">
<el-form-item <el-form-item
style="display: inline-flex; text-align: left; width: 770px" style="display: inline-flex; text-align: left; width: 770px"
@ -113,7 +120,7 @@
</el-form-item> </el-form-item>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="旅游路线"> <el-form-item label="旅游路线" prop="title">
<el-input <el-input
v-model="anchors.title" v-model="anchors.title"
type="text" type="text"
@ -164,196 +171,93 @@
inactive-color="#ff4949" inactive-color="#ff4949"
/> />
</el-form-item> </el-form-item>
<div
style="display: flex; justify-content: flex-end; margin-bottom: 10px"
>
<el-button type="primary" @click="onAddImg()">添加图片</el-button>
</div>
<el-form-item label="上传图片"> <el-form-item label="上传图片">
<el-upload <div class="upload-list">
class="avatar-uploader" <div class="wu-yu" v-for="(item, index) in anchors.img_zip">
action="admin/upload/index"
:show-file-list="false"
:on-success="handleAvatarSuccess"
>
<div v-for="(item, index) in anchors.img_zip" class="img-box">
<i <i
@click.stop="handleClose('img_zip', index)" @click.stop="handleClose('img_zip', index)"
class="close el-icon-close" class="close el-icon-close"
/> />
<i v-if="!checkIfUrlContainsImage(item)" class="el-icon-folder" /> <el-input v-model="item.desc" placeholder="图片说明"></el-input>
<img <el-upload
v-else class="avatar-uploader"
style="width: 100px; height: 100px" action=""
:src="item" :show-file-list="false"
class="avatar" :http-request="handlesAvatarSuccess"
alt="" :on-success="
/> (response, file, fileList) =>
<div class="desc">{{ handleRegex(item) }}</div> handleAvatarSuccess(response, file, fileList, index)
</div>
<i class="el-icon-plus avatar-uploader-icon" />
</el-upload>
<div style="color: red">(请上传.jpg, png的图片)</div>
</el-form-item>
<el-form-item label="上传行程">
<el-upload
class="avatar-uploader"
action="admin/upload/index"
:show-file-list="false"
:on-success="handleSuccess"
>
<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 class="desc">{{ handleRegex(item) }}</div>
</div>
<i class="el-icon-plus avatar-uploader-icon" />
</el-upload>
<span style="color: red">(本行程请上传,ppt,word,pdf格式的文件)</span>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button v-loading="loading" type="primary" @click="onSave"
> </el-button
>
</div>
</el-dialog>
<el-dialog title="编辑内容" :visible.sync="dialogEdit">
<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-option
v-for="item in getQaCitys"
:key="item.city_id"
style="
width: 250px;
display: inline-flex;
word-break: break-all;
" "
:label="item.city_name"
:value="item.city_id"
/>
</el-form-item>
</el-select>
</el-form-item>
<el-form-item label="旅游路线">
<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-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="请输入副标题"
/>
</div>
<div>内容</div>
<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
> >
<div v-if="!!item.file" class="img-box">
<i
v-if="!checkIfUrlContainsImage(item.file)"
class="el-icon-folder"
/>
<img
v-else
style="width: 100px; height: 100px"
:src="item.file"
class="avatar"
alt=""
/>
<div class="desc">{{ handleRegex(item.file) }}</div>
</div>
<i v-else class="el-icon-plus avatar-uploader-icon" />
</el-upload>
</div> </div>
</div> </div>
<div class="mistake-btn">
<el-button type="primary" @click="handleAdd">添加</el-button>
</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-form-item>
<el-form-item label="上传图片">
<el-upload
class="avatar-uploader"
action="admin/upload/index"
:show-file-list="false"
:on-success="handleAvatarSuccess"
>
<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(item)" class="el-icon-folder" />
<img
v-else
style="width: 100px; height: 100px"
:src="item"
class="avatar"
alt=""
/>
<div class="desc">{{ handleRegex(item) }}</div>
</div>
<i class="el-icon-plus avatar-uploader-icon" />
</el-upload>
<div style="color: red">(请上传.jpg, png的图片)</div> <div style="color: red">(请上传.jpg, png的图片)</div>
</el-form-item> </el-form-item>
<div
style="display: flex; justify-content: flex-end; margin-bottom: 10px"
>
<el-button type="primary" @click="onAddtrip()">添加行程</el-button>
</div>
<el-form-item label="上传行程"> <el-form-item label="上传行程">
<el-upload <div class="upload-list">
class="avatar-uploader" <div class="wu-yu" v-for="(item, index) in anchors.trip_zip">
action="admin/upload/index"
:show-file-list="false"
:on-success="handleSuccess"
>
<div v-for="(item, index) in anchors.trip_zip" class="img-box">
<i <i
@click.stop="handleClose('trip_zip', index)" @click.stop="handleClose('trip_zip', index)"
class="close el-icon-close" class="close el-icon-close"
/> />
<i v-if="!checkIfUrlContainsImage(item)" class="el-icon-folder" /> <el-input v-model="item.desc" placeholder="行程说明"></el-input>
<img <el-upload
v-else class="avatar-uploader"
style="width: 100px; height: 100px" action="/dev-api/admin/upload/index"
:src="item" :show-file-list="false"
class="avatar" :on-success="
alt="" (response, file, fileList) =>
/> handleSuccess(response, file, fileList, index)
<div class="desc">{{ handleRegex(item) }}</div> "
>
<div v-if="!!item.file" class="img-box">
<i
v-if="!checkIfUrlContainsImage(item.file)"
class="el-icon-folder"
/>
<img
v-else
style="width: 100px; height: 100px"
:src="item.file"
class="avatar"
alt=""
/>
<div class="desc">{{ handleRegex(item.file) }}</div>
</div>
<i v-else class="el-icon-plus avatar-uploader-icon" />
</el-upload>
</div> </div>
<i class="el-icon-plus avatar-uploader-icon" /> </div>
</el-upload>
<span style="color: red">(本行程请上传,ppt,word,pdf格式的文件)</span> <span style="color: red">(本行程请上传,ppt,word,pdf格式的文件)</span>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer"></div>
<el-button v-loading="loading" type="primary" @click="onSave"
> </el-button
>
</div>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
@ -361,13 +265,14 @@
<script> <script>
import Pagination from "@/components/PaginationFixed"; import Pagination from "@/components/PaginationFixed";
import myEditor from "@/components/Wangeditor/index.vue"; import myEditor from "@/components/Wangeditor/index.vue";
import { getToken } from "@/utils/auth";
export default { export default {
name: "getQa", name: "getQa",
components: { Pagination, myEditor }, components: { Pagination, myEditor },
data() { data() {
return { return {
statusArr: { 0: "禁用", 1: "启用" }, statusArr: { 0: "禁用", 1: "启用" },
title: "",
list: [], list: [],
total: 0, total: 0,
loading: false, loading: false,
@ -387,8 +292,8 @@ export default {
item: {}, item: {},
anchors: { anchors: {
qaQuestions: [], qaQuestions: [],
img_zip: [], img_zip: [{ desc: "", file: "" }],
trip_zip: [], trip_zip: [{ desc: "", file: "" }],
}, },
getQaCitys: {}, getQaCitys: {},
}; };
@ -411,19 +316,42 @@ export default {
".svg", ".svg",
".webp", ".webp",
]; ];
console.log(url);
console.log(
"========fffff====" +
imageExtensions.some((extension) =>
url.toLowerCase().endsWith(extension)
)
);
console.log(url);
return imageExtensions.some((extension) => return imageExtensions.some((extension) =>
url.toLowerCase().endsWith(extension) url.toLowerCase().endsWith(extension)
); );
}, },
async handlesAvatarSuccess(file) {
try {
var formdata = new FormData();
formdata.append("file", file.file);
this.upLoading = true;
const _this = this;
const res = await this.$axios.post("/admin/upload/index", formdata, {
headers: {
"Content-type": "multipart/form-data",
"X-Token": getToken(),
},
});
// if (![200].includes(res.data.code)) {
// this.$message.error("");
// return;
// }
// success
file.onSuccess(res);
} catch (error) {
console.error(error);
}
},
handleClose(val, i) { handleClose(val, i) {
if (this.anchors[val].length == 1) {
this.$message({
message: "至少保留一条",
type: "warning",
});
return;
}
console.log("i===", i); console.log("i===", i);
this.anchors[val].splice(i, 1); this.anchors[val].splice(i, 1);
}, },
@ -461,19 +389,26 @@ export default {
this.listLoading = false; this.listLoading = false;
}); });
}, },
handleAvatarSuccess(res, file) { onAddImg() {
console.log("====1111===" + res); this.anchors.img_zip.push({ desc: "", file: "" });
this.anchors.img_zip.push(
`${window.location.protocol}//${window.location.host}${res.data}`
);
console.log("====111122222===" + this.anchors.img_zip);
}, },
handleSuccess(res, file) { onAddtrip() {
console.log("====222222===" + res); this.anchors.trip_zip.push({ desc: "", file: "" });
this.anchors.trip_zip.push( },
`${window.location.protocol}//${window.location.host}${res.data}` handleAvatarSuccess(res, file, fileList, index) {
); if (!res.data) return;
console.log("====111122222===" + this.anchors.trip_zip); this.anchors.img_zip[
index
].file = `${window.location.protocol}//${window.location.host}${res.data}`;
// this.anchors.img_zip.push(
// `${window.location.protocol}//${window.location.host}${res.data}`
// );
},
handleSuccess(res, file, fileList, index) {
if (!res.data) return;
this.anchors.trip_zip[
index
].file = `${window.location.protocol}//${window.location.host}${res.data}`;
}, },
handleRegex(val) { handleRegex(val) {
const regex = /\/([^\/]+)$/; const regex = /\/([^\/]+)$/;
@ -484,51 +419,54 @@ export default {
this.listQuery.page = 1; this.listQuery.page = 1;
this.getList(); this.getList();
}, },
onAdd() { onAdd(item) {
this.anchors.qaQuestions = [
{
sort: 1,
title: "",
content: "",
},
];
// 0
this.anchors.img_zip = [];
this.anchors.trip_zip = [];
this.dialogCreate = true; this.dialogCreate = true;
}, if (!item.id) {
onEdit(item) { this.title = "添加QA";
if (!item.qaQuestions.length) { this.anchors.qaQuestions = [
this.anchors = { {
...item, sort: 1,
qaQuestions: [ title: "",
{ content: "",
sort: 1, },
title: "", ];
content: "", // 0
}, this.anchors.img_zip = [{ desc: "", file: "" }];
], this.anchors.trip_zip = [{ desc: "", file: "" }];
};
} else { } else {
this.anchors = { ...item }; this.title = "编辑QA";
if (!item.qaQuestions.length) {
this.anchors = {
...item,
qaQuestions: [
{
sort: 1,
title: "",
content: "",
},
],
};
} else {
this.anchors = { ...item };
}
this.anchors.img_zip = item.img_zip
? item.img_zip
: [{ desc: "", file: "" }];
this.anchors.trip_zip = item.trip_zip
? item.trip_zip
: [{ desc: "", file: "" }];
} }
this.anchors.img_zip = item.img_zip;
this.anchors.trip_zip = item.trip_zip;
// this.anchors.img_zip =
// typeof item.img_zip == "string" ? [item.img_zip] : item.img_zip;
// this.anchors.trip_zip =
// typeof item.trip_zip == "string" ? [item.trip_zip] : item.trip_zip;
this.dialogEdit = true;
}, },
onSave() { onSave() {
if (this.loading) return; if (this.loading) return;
this.loading = true; this.loading = true;
const api = this.dialogCreate ? "/admin/qa/addQa" : "/admin/qa/editQa"; const api =
this.title == "添加QA" ? "/admin/qa/addQa" : "/admin/qa/editQa";
this.$axios this.$axios
.post(api, this.anchors) .post(api, this.anchors)
.then(() => { .then(() => {
this.dialogCreate = false; this.dialogCreate = false;
this.dialogEdit = false; // this.dialogEdit = false;
this.loading = false; this.loading = false;
this.getList(); this.getList();
}) })
@ -585,11 +523,33 @@ export default {
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.upload-list {
display: flex;
flex-wrap: wrap;
.wu-yu {
margin-bottom: 10px;
position: relative;
& + .wu-yu {
margin-left: 5px;
}
::v-deep.el-input {
width: 100px;
margin: 0 0 10px 10px;
}
}
}
.filter-items {
position: fixed;
// right: 0;
left: 70%;
z-index: 66;
}
.img-box { .img-box {
position: relative; position: relative;
display: inline-block; display: inline-block;
width: 100px; width: 100px;
margin-bottom: 10px; margin-bottom: 10px;
margin-left: 10px;
& + .img-box { & + .img-box {
margin-left: 10px; margin-left: 10px;
} }
@ -615,7 +575,7 @@ export default {
.close { .close {
position: absolute; position: absolute;
top: -10px; top: -10px;
right: -8px; right: -15px;
font-size: 18px; font-size: 18px;
color: #409eff; color: #409eff;
} }

View File

@ -39,7 +39,7 @@ module.exports = {
proxy: { proxy: {
'/dev-api': { // 接口地址 以 api开头的都走下面的配置 '/dev-api': { // 接口地址 以 api开头的都走下面的配置
// target: 'https://www.szjinao.cn', // 代理目标地址为后端服务器地址 127.0.0.1 192.168.1.2 // target: 'https://www.szjinao.cn', // 代理目标地址为后端服务器地址 127.0.0.1 192.168.1.2
target: 'http://0.0.0.0:8787', // 代理目标地址为后端服务器地址 127.0.0.1 192.168.1.2 target: 'http://192.168.1.4:8787', // 代理目标地址为后端服务器地址 127.0.0.1 192.168.1.2
ws: true, // 是否支持 websocket 请求 支持 ws: true, // 是否支持 websocket 请求 支持
changeOrigin: true, // 是否启用跨域 changeOrigin: true, // 是否启用跨域
pathRewrite: { pathRewrite: {