diff --git a/app.vue b/app.vue index 944d22d..81e1ff3 100644 --- a/app.vue +++ b/app.vue @@ -5,7 +5,6 @@ <div id="append_parent"></div> <div id="ajaxwaitid"></div> <div> - <Head> <Title>{{ `${seo["title"] || "问答"} - 寄托天下出国留学网` }}</Title> <Meta name="keyword" :content="seo['keyword']" /> @@ -56,7 +55,7 @@ </header> <div class="main flexflex" :class="{ 'mode-list': type == 'list' }"> <div class="list-box" @scroll="handleListScroll"> - <div class="main-header" :style="{paddingLeft: type == 'list' ? 0 : 'calc((100vw - 1200px) / 2)',}"> + <div class="main-header" :style="{ paddingLeft: type == 'list' ? 0 : 'calc((100vw - 1200px) / 2)' }"> <div class="flexacenter"> <template v-if="myModelState"> <div class="search-keyword flexacenter" @click="closeMyModel()"> @@ -75,24 +74,24 @@ </div> <div class="look-only flexcenter" v-if="type != 'details'" @click="handleLookOnly"> - <img class="look-icon" v-if="zeroreply == 0" src="@/img/tick-no.svg"> - <img class="look-icon" v-else src="@/img/tick-option.svg"> + <img class="look-icon" v-if="zeroreply == 0" src="@/img/tick-no.svg" /> + <img class="look-icon" v-else src="@/img/tick-option.svg" /> 只看0回答 </div> </div> <div class="list" id="list" :style="[listStyle(), { height: listHeight + 'px' }]"> <template v-for="(item, index) in list" :key="item.uniqid"> - <a v-if="item['isrecom']" class="item grid-item flexflex" :style="itemStyle(index, item['content'], item['type'])" :class="{pitch: index === pitchIndex,upLevel: index === pitchIndex - 1,}" target="_blank" :href="item['url']"> + <a v-if="item['isrecom']" class="item grid-item flexflex" :style="itemStyle(index, item['content'], item['type'])" :class="{ pitch: index === pitchIndex, upLevel: index === pitchIndex - 1 }" target="_blank" :href="item['url']"> <img class="dot" src="./img/dot.svg" /> <div class="content" :style="{ width: type == 'list' ? '531px' : '430px' }"> <div class="issue-title flexcenter"> <div class="recommend flexcenter">推荐阅读</div> - <div class="issue ellipsis flex1">{{ item['title'] }}</div> + <div class="issue ellipsis flex1">{{ item["title"] }}</div> </div> <template v-if="item['type'] == 'thread'"> - <div class="answer ellipsis" v-if="item['message']">{{ item['message'] }}</div> + <div class="answer ellipsis" v-if="item['message']">{{ item["message"] }}</div> </template> - <div class="answer" style="height: auto" v-else-if="item['type'] == 'vote'"> + <div class="answer" style="height: auto;" v-else-if="item['type'] == 'vote'"> <div v-for="(ite, i) in item['option'].slice(0, 2)" :key="i">{{ replaceNumberObj[i] + ite }}</div> <div>{{ replaceNumberObj[2] }} …</div> </div> @@ -109,14 +108,14 @@ </div> </div> </a> - <a v-else class="item grid-item flexflex" :style="itemStyle(index, item['content'])" :class="[{pitch: index === pitchIndex,upLevel: index === pitchIndex - 1,},`item${index}`,]" :href="setItemUrl(item['uniqid'])" @click.stop.prevent="getDetails(item['uniqid'], index)"> + <a v-else class="item grid-item flexflex" :style="itemStyle(index, item['content'])" :class="[{ pitch: index === pitchIndex, upLevel: index === pitchIndex - 1 }, `item${index}`]" :href="setItemUrl(item['uniqid'])" @click.stop.prevent="getDetails(item['uniqid'], index)"> <img class="dot" src="./img/dot.svg" /> <div class="content" :style="{ width: type == 'list' ? '531px' : '430px' }"> <div class="issue-title flexcenter"> <img class="hot-icon" v-if="item['ishot'] == 1" src="./img/hot-icon.png" /> - <div class="issue ellipsis flex1"> {{ item['title'] }}</div> + <div class="issue ellipsis flex1">{{ item["title"] }}</div> </div> - <div class="answer ellipsis" v-if="item['content']">{{ item['content'] }}</div> + <div class="answer ellipsis" v-if="item['content']">{{ item["content"] }}</div> <div class="bottom flexacenter"> <div class="typename flexcenter" v-if="item['typename']">{{ item["typename"] }}</div> <div v-else></div> @@ -199,8 +198,8 @@ 我来回答 </div> <div class="operate-list flexacenter"> - <div class="operate-item flexacenter" style="cursor: auto"> - <img class="operate-icon operate-collect-icon" style="width: 13px; height: 8px" src="./img/view-icon.svg" /> + <div class="operate-item flexacenter" style="cursor: auto;"> + <img class="operate-icon operate-collect-icon" style="width: 13px; height: 8px;" src="./img/view-icon.svg" /> {{ detailsInfo["viewnum"] || 0 }} </div> <div class="operate-item flexacenter" @click="operateCollect()"> @@ -211,7 +210,7 @@ <div class="operate-item flexacenter operate-transmit" @mouseenter.stop="closeTransmitState()" @mouseleave.stop="closeAllTransmitState()"> <img class="operate-icon operate-transmit-icon" src="./img/transmit-icon.png" /> 转发 - <div class="transmit-box flexflex" v-if="questionsTransmitState" @click.stop style="z-index: 10"> + <div class="transmit-box flexflex" v-if="questionsTransmitState" @click.stop style="z-index: 10;"> <img class="cross-icon" @click.stop="closeAllTransmitState()" src="./img/cross-icon.png" /> <div class="transmit-left transmit-web"> <div class="transmit-title">转发网页版</div> @@ -353,9 +352,7 @@ <div class="report-box flexcenter">举报</div> </div> <img class="comment-icon" @click="openAnswerCommentsChild(index, ind)" src="./img/comment-icon-gray.svg" /> - <div class="flexacenter like-box" @click=" - operateAnswerCommentsLike(it['token'], index, ind) - "> + <div class="flexacenter like-box" @click="operateAnswerCommentsLike(it['token'], index, ind)"> <img class="like-icon" v-if="it['islike'] == 0" src="./img/like-icon-gray.png" /> <img class="like-icon" v-else src="./img/like-icon-colours.png" /> <div class="like-quantity">{{ it["likenum"] || 0 }}</div> @@ -400,14 +397,7 @@ <div class="report-box flexcenter">举报</div> </div> <img class="comment-icon" @click="openAnswerCommentsChild(index, ind, i)" src="./img/comment-icon-gray.svg" /> - <div class="flexacenter like-box" @click=" - operateAnswerCommentsLike( - ite['token'], - index, - ind, - i - ) - "> + <div class="flexacenter like-box" @click="operateAnswerCommentsLike(ite['token'], index, ind, i)"> <img class="like-icon" v-if="ite['islike'] == 0" src="./img/like-icon-gray.png" /> <img class="like-icon" v-else src="./img/like-icon-colours.png" /> <div class="like-quantity">{{ ite["likenum"] || 0 }}</div> @@ -522,11 +512,7 @@ <div class="quantity">{{ myAnswerCount || myCount["answer"] || 0 }}</div> </div> </div> - <div class="empty-box flexcenter" v-if=" - (myType == 'collect' && myCollectionList.length == 0) || - (myType == 'answers' && myAnswerList.length == 0) || - (myType == 'questions' && myQuestionsList.length == 0) - "> + <div class="empty-box flexcenter" v-if="(myType == 'collect' && myCollectionList.length == 0) || (myType == 'answers' && myAnswerList.length == 0) || (myType == 'questions' && myQuestionsList.length == 0)"> <div class="dot-list flexacenter"> <img class="item" src="./img/dot-yellow.svg" /> <img class="item" src="./img/dot-yellow.svg" /> @@ -555,11 +541,7 @@ <div class="centre flexflex flex1"> <div class="titletitle ellipsis">{{ item["data"]["title"] }}</div> <div class="text ellipsis"> - {{ - item["data"]["answers"] > 0 - ? "共" + item["data"]["answers"] + "个回答" - : "暂无回答" - }} + {{ item["data"]["answers"] > 0 ? "共" + item["data"]["answers"] + "个回答" : "暂无回答" }} </div> </div> <div class="delete-box flexacenter"> @@ -613,11 +595,7 @@ 有{{ item["authornewnum"] }}个新回答 <div class="long-string"></div> </div> - {{ - item["answers"] == 0 - ? "暂无回答" - : "共" + item["answers"] + "个回答" - }} + {{ item["answers"] == 0 ? "暂无回答" : "共" + item["answers"] + "个回答" }} </div> </div> <div class="operate-box flexacenter"> @@ -625,15 +603,11 @@ <div class="text">{{ item["anonymous"] == 0 ? "公开" : "匿名" }}</div> <img class="arrows" src="./img/arrows-icon.svg" /> <div class="state-popup flexflex" v-if="item['popupState']"> - <div class="state-popup-item flexacenter flex1" :class="{ pitch: item['anonymous'] == 0 }" @click.stop=" - changeAnonymousQuestions(item['token'], 0, index) - "> + <div class="state-popup-item flexacenter flex1" :class="{ pitch: item['anonymous'] == 0 }" @click.stop="changeAnonymousQuestions(item['token'], 0, index)"> <div class>公开发表</div> <img class="state-popup-icon" src="./img/tick-orange.svg" /> </div> - <div class="state-popup-item flexacenter flex1" :class="{ pitch: item['anonymous'] == 1 }" @click.stop=" - changeAnonymousQuestions(item['token'], 1, index) - "> + <div class="state-popup-item flexacenter flex1" :class="{ pitch: item['anonymous'] == 1 }" @click.stop="changeAnonymousQuestions(item['token'], 1, index)"> <div class>匿名发表</div> <img class="state-popup-icon" src="./img/tick-orange.svg" /> </div> @@ -667,11 +641,11 @@ </div> <textarea class="issue-replenish" v-model="questionsObj.content" placeholder="欢迎补充,清晰表达问题的关键点,可获得更有效的解答(非必填)"></textarea> <div class="issue-bottom flexacenter"> - <div class="option-box flexacenter" @click="cutAnonymous" style="color: #333"> + <div class="option-box flexacenter" @click="cutAnonymous" style="color: #333;"> <img class="option-icon" v-if="questionsObj.anonymous == 0" src="./img/tick-no.svg" /> <img class="option-icon" v-else src="./img/tick-option.svg" /> 匿名发表 - <div class style="color: #aaa">(发布后只能修改是否匿名)</div> + <div class style="color: #aaa;">(发布后只能修改是否匿名)</div> </div> <div class="issue-btn flexcenter" @click="postingIssue">发布问题</div> @@ -741,9 +715,7 @@ <div class="alert-form" v-show="alertShow"> <div class="comments reports"> <div class="head"> - <span style="display: flex; align-items: center"> - <img style="width: 25px; margin-right: 7px" src="//app.gter.net/image/gter/offer/img/exclamationpoint.png?v=4.2.08_331040000" />举报投诉 - </span> + <span style="display: flex; align-items: center;"> <img style="width: 25px; margin-right: 7px;" src="//app.gter.net/image/gter/offer/img/exclamationpoint.png?v=4.2.08_331040000" />举报投诉 </span> <div class="close icon-close iconfont" @click="alertShow = false"></div> </div> <div class="form"> @@ -779,102 +751,99 @@ // "todaysigned": 0 // } - -import { onMounted, onUnmounted, ref, nextTick, watchEffect, watch } from "vue"; -import axios from "axios"; +import { onMounted, onUnmounted, ref, nextTick, watchEffect, watch } from "vue" +import axios from "axios" export default { name: "#answer-app", async setup() { - const $ajax = (url, data) => { - url = url.indexOf("//") > -1 ? url : baseURL + url; + url = url.indexOf("//") > -1 ? url : baseURL + url return new Promise(function (resolve, reject) { axios .post(url, data, { emulateJSON: true, withCredentials: true, headers: { - authorization: - process.env.NODE_ENV !== "production" && - "pa5o1v493ed5mahrcio66267e2", // 头部标记 ada + authorization: process.env.NODE_ENV !== "production" && "pa5o1v493ed5mahrcio66267e2", // 头部标记 ada // "7a89997c2ccd8cb5ed8cb20d843dafdd", // 头部标记 ada }, - }).then(function (res) { - var data = null; + }) + .then(function (res) { + var data = null try { - data = typeof res.data == "string" ? JSON.parse(res.data) : res.data; + data = typeof res.data == "string" ? JSON.parse(res.data) : res.data if (data["code"] == 401) { goLogin() // isNeedLogin.value = true; } - if (data["code"] != 200) handleMsg("error", data["message"] || "报错了,请重试!!!"); - } catch (error) { } - resolve(data); + if (data["code"] != 200) handleMsg("error", data["message"] || "报错了,请重试!!!") + } catch (error) {} + resolve(data) }) - .catch((err) => { + .catch(err => { if (err.response.status == 401) { goLogin() // isNeedLogin.value = true; } - resolve(err.response.data); - }); - }); - }; + resolve(err.response.data) + }) + }) + } const $ajaxGET = (url, data) => { - url = url.indexOf("//") > -1 ? url : baseURL + url; + url = url.indexOf("//") > -1 ? url : baseURL + url return new Promise(function (resolve, reject) { - axios.get(url, data, { - emulateJSON: true, - withCredentials: true, - headers: { - authorization: - process.env.NODE_ENV !== "production" && - "pa5o1v493ed5mahrcio66267e2", // 头部标记 - // "7a89997c2ccd8cb5ed8cb20d843dafdd", // 头部标记 - }, - }).then(function (res) { - var data = null; - try { - data = typeof res.data == "string" ? JSON.parse(res.data) : res.data; - if (data["code"] == 401) { + axios + .get(url, data, { + emulateJSON: true, + withCredentials: true, + headers: { + authorization: process.env.NODE_ENV !== "production" && "pa5o1v493ed5mahrcio66267e2", // 头部标记 + // "7a89997c2ccd8cb5ed8cb20d843dafdd", // 头部标记 + }, + }) + .then(function (res) { + var data = null + try { + data = typeof res.data == "string" ? JSON.parse(res.data) : res.data + if (data["code"] == 401) { + goLogin() + // isNeedLogin.value = true; + } + + if (data["code"] != 200) handleMsg("error", data["message"] || "报错了,请重试!!!") + } catch (error) {} + resolve(data) + }) + .catch(err => { + if (err.response.status == 401) { goLogin() // isNeedLogin.value = true; } + resolve(err.response.data) + }) + }) + } - if (data["code"] != 200) - handleMsg("error", data["message"] || "报错了,请重试!!!"); - } catch (error) { } - resolve(data); - }).catch((err) => { - if (err.response.status == 401) { - goLogin() - // isNeedLogin.value = true; - } - resolve(err.response.data); - }); - }); - }; - - let isNeedLogin = ref(true); // 是否需要有登录 + let isNeedLogin = ref(true) // 是否需要有登录 // 跳转登录 const goLogin = () => { - if (typeof window === "undefined") return; + if (typeof window === "undefined") return if (Object.keys(window["userInfoWin"]).length !== 0) { - if (window["userInfoWin"]["uid"]) isNeedLogin.value = false; + if (window["userInfoWin"]["uid"]) isNeedLogin.value = false else ajax_login() } else ajax_login() } - const route = useRoute(); + const route = useRoute() - let detailsInfoDataVuex = useState("detailsInfoData", () => { }); + let detailsInfoDataVuex = useState("detailsInfoData", () => {}) - const baseURL = "https://ask.gter.net"; + const baseURL = "https://ask.gter.net" - let type = ref("list"); // list details + let type = ref("list") // list details onMounted(() => { // setTimeout(() => { @@ -889,234 +858,227 @@ export default { // } // }, 400); - // 判断一下是否登录 // if (process.env.NODE_ENV !== "production") isNeedLogin.value = false; // else - determineIsLogin(); + determineIsLogin() + getListClass() + window.addEventListener("scroll", handleScroll) + getHistoricalSearchList() - getListClass(); - window.addEventListener("scroll", handleScroll); - getHistoricalSearchList(); + if (isNeedScrollMiddle) scrollLeftInMiddle() - if (isNeedScrollMiddle) scrollLeftInMiddle(); + if (process.client) originUrl.value = window.location.origin - if (process.client) originUrl.value = window.location.origin; + listenPageBack() - listenPageBack(); - - if (detailsInfoDataVuex.value) hanleServerRequestData(); + if (detailsInfoDataVuex.value) hanleServerRequestData() initState.value++ - const params = route.query; + const params = route.query // 是否直接打开提问 - setTimeout(() => { if (params['ispublish']) questionsInit() }, 500); - }); - - + setTimeout(() => { + if (params["ispublish"]) questionsInit() + }, 500) + }) // 处理在服务端已经请求了详情接口 数据 const hanleServerRequestData = () => { - const params = route.query; + const params = route.query - type.value = "details"; + type.value = "details" - let data = detailsInfoDataVuex.value; + let data = detailsInfoDataVuex.value - detailsInfo.value = data["info"] || {}; - detailsIsanswered.value = data["isanswered"] || 0; - detailsIscollection.value = data["iscollection"] || 0; - detailsIsmyself.value = data["ismyself"] || 0; - detailsToken = data["token"] || ""; - detailShare.value = data["share"] || {}; + detailsInfo.value = data["info"] || {} + detailsIsanswered.value = data["isanswered"] || 0 + detailsIscollection.value = data["iscollection"] || 0 + detailsIsmyself.value = data["ismyself"] || 0 + detailsToken = data["token"] || "" + detailShare.value = data["share"] || {} - type.value = "details"; - answerList.value = []; - answerPage.value = 1; - getAnswerList(); - - closeAllTransmitState(); - - replaceState({ uniqid: params["uniqid"] }); - seo.value = data.seo; - closeBottom(); - - }; + type.value = "details" + answerList.value = [] + answerPage.value = 1 + getAnswerList() + closeAllTransmitState() + replaceState({ uniqid: params["uniqid"] }) + seo.value = data.seo + closeBottom() + } // 是否是后退 状态 - let isBackState = false; + let isBackState = false // 监听页面后退效果 重新获取 url 请求 const listenPageBack = () => { window.addEventListener("popstate", function (event) { - const params = route.query; - if (params["keyword"]) keyword.value = params["keyword"]; - if (params["tid"]) typePitch.value = params["tid"]; + const params = route.query + if (params["keyword"]) keyword.value = params["keyword"] + if (params["tid"]) typePitch.value = params["tid"] if (params["uniqid"]) { - isBackState = true; - getDetails(params["uniqid"]); + isBackState = true + getDetails(params["uniqid"]) } else { - type.value = "list"; - openBottom(); - pitchIndex.value = null; - seo.value = {}; + type.value = "list" + openBottom() + pitchIndex.value = null + seo.value = {} } - }); - }; + }) + } // 判断是否登录状态 const determineIsLogin = () => { - let count = 0; + let count = 0 let timer = setInterval(() => { - console.log(Object.keys(window["userInfoWin"]).length); + // console.log(Object.keys(window["userInfoWin"]).length); if (Object.keys(window["userInfoWin"]).length !== 0) { - clearInterval(timer); - if (window["userInfoWin"]["uid"]) isNeedLogin.value = false; + clearInterval(timer) + if (window["userInfoWin"]["uid"]) isNeedLogin.value = false } - count++; - if (count >= 10) clearInterval(timer); - }, 100); - }; + count++ + if (count >= 10) clearInterval(timer) + }, 100) + } - let originUrl = ref(""); + let originUrl = ref("") onUnmounted(() => { - window.removeEventListener("keydown", handleKeydown); - window.removeEventListener("scroll", handleScroll); - }); + window.removeEventListener("keydown", handleKeydown) + window.removeEventListener("scroll", handleScroll) + }) - // 获取当前url 专门 分享的url + // 获取当前url 专门 分享的url const getCurrentUrl = () => { - return `${window.location['origin']}?uniqid=${detailsInfo.value['uniqid'] || ''}`; - }; + return `${window.location["origin"]}?uniqid=${detailsInfo.value["uniqid"] || ""}` + } // 我的 数据 数量 - let myCount = ref({}); // + let myCount = ref({}) // // 获取用户数据 - const getUserData = (key) => { - $ajax("/api/user").then((res) => { - if (res.code != 200) return; - let data = res.data; - myCount.value = data.count; - handleMy(key); - }); - }; + const getUserData = key => { + $ajax("/api/user").then(res => { + if (res.code != 200) return + let data = res.data + myCount.value = data.count + handleMy(key) + }) + } // 是否是搜索模式 - let isSearchMode = ref(false); + let isSearchMode = ref(false) // 获取历史记录方法 const getHistoricalSearchList = () => { - const list = localStorage.getItem("historical-Search"); + const list = localStorage.getItem("historical-Search") - if (list) historicalSearchList.value = JSON.parse(list) || []; - else historicalSearchList.value = []; - }; + if (list) historicalSearchList.value = JSON.parse(list) || [] + else historicalSearchList.value = [] + } // 存入历史记录 随便去重 和 限制长度 方法 const setHistoricalSearchList = () => { - if (!keyword.value) return; - historicalSearchList.value.unshift(keyword.value); - historicalSearchList.value = [...new Set(historicalSearchList.value)]; - historicalSearchList.value = historicalSearchList.value.slice(0, 10); + if (!keyword.value) return + historicalSearchList.value.unshift(keyword.value) + historicalSearchList.value = [...new Set(historicalSearchList.value)] + historicalSearchList.value = historicalSearchList.value.slice(0, 10) - localStorage.setItem("historical-Search", JSON.stringify(historicalSearchList.value)); - }; + localStorage.setItem("historical-Search", JSON.stringify(historicalSearchList.value)) + } // 搜索点击事件 const searchClick = () => { - setHistoricalSearchList(); - page = 1; - list.value = []; - backupsList = []; + setHistoricalSearchList() + page = 1 + list.value = [] + backupsList = [] listHeight.value = 0 - type.value = "list"; - pitchIndex.value = null; - openBottom(); + type.value = "list" + pitchIndex.value = null + openBottom() myModelState.value = false - deleteState(["uniqid"]); + deleteState(["uniqid"]) replaceState({ keyword: keyword.value, - }); - searchBlur(); - getList(); - }; + }) + searchBlur() + getList() + } // 搜索获取焦点 const searchFocus = () => { - if (historicalSearchList.value.length == 0) return; - historicalSearchState.value = true; - }; + if (historicalSearchList.value.length == 0) return + historicalSearchState.value = true + } // 搜索失去焦点 const searchBlur = () => { - setTimeout(() => (historicalSearchState.value = false), 300); - }; + setTimeout(() => (historicalSearchState.value = false), 300) + } // 点击历史记录 item - const handleClickHistoricalItem = (value) => { - keyword.value = value; - searchClick(); - }; + const handleClickHistoricalItem = value => { + keyword.value = value + searchClick() + } // 点击清除搜索 const handleClickClear = () => { - keyword.value = ""; - page = 1; - list.value = []; - backupsList = []; + keyword.value = "" + page = 1 + list.value = [] + backupsList = [] listHeight.value = 0 - type.value = "list"; - openBottom(); - pitchIndex.value = null; + type.value = "list" + openBottom() + pitchIndex.value = null - getList(); + getList() - deleteState(["keyword"]); - }; + deleteState(["keyword"]) + } - let historicalSearchState = ref(false); // 历史记录弹窗状态 - let historicalSearchList = ref([]); // 历史记录数据 + let historicalSearchState = ref(false) // 历史记录弹窗状态 + let historicalSearchList = ref([]) // 历史记录数据 - let tabListFixeState = ref(false); // 顶部 类型的 固定状态 + let tabListFixeState = ref(false) // 顶部 类型的 固定状态 const handleScroll = () => { - const scrollTop = - document.documentElement.scrollTop || document.body.scrollTop; + const scrollTop = document.documentElement.scrollTop || document.body.scrollTop - const scrollHeight = document.documentElement.scrollHeight; - const clientHeight = document.documentElement.clientHeight; + const scrollHeight = document.documentElement.scrollHeight + const clientHeight = document.documentElement.clientHeight // 列表下 滑动到底部 获取新数据 - if (scrollTop + clientHeight >= scrollHeight - 40 && type.value == "list") - getList(); + if (scrollTop + clientHeight >= scrollHeight - 40 && type.value == "list") getList() // 列表下 滚动到顶部 触发类型的固定状态 - if (scrollTop > 115) tabListFixeState.value = true; - else tabListFixeState.value = false; - }; + if (scrollTop > 115) tabListFixeState.value = true + else tabListFixeState.value = false + } - let keyword = ref(""); // 搜索的值 - let keywordText = ref(""); // 搜索的文本 + let keyword = ref("") // 搜索的值 + let keywordText = ref("") // 搜索的文本 - let list = ref([]); // 列表数据 - let backupsList = []; // 备份列表数据 - let page = 1; - let total = ref(0); // 回答总数 - let loading = ref(false); - let inTheEndState = ref(false); // 到底了状态 - let isListEmptyState = ref(); // 列表是否为空的状态 + let list = ref([]) // 列表数据 + let backupsList = [] // 备份列表数据 + let page = 1 + let total = ref(0) // 回答总数 + let loading = ref(false) + let inTheEndState = ref(false) // 到底了状态 + let isListEmptyState = ref() // 列表是否为空的状态 let zeroreply = ref(0) // 只看0条回答状态 // 获取列表数据 const getList = () => { - if (page == 0 || loading.value) return; - loading.value = true; + if (page == 0 || loading.value) return + loading.value = true $ajax("/api/lists", { page, @@ -1124,166 +1086,169 @@ export default { keyword: keyword.value, type: typePitch.value, zeroreply: zeroreply.value, - }).then((res) => { - if (res.code == 401) goLogin(); + }) + .then(res => { + if (res.code == 401) goLogin() - if (res.code != 200) return; + if (res.code != 200) return - let data = res.data; - data.data.forEach(element => { - element['content'] = element['content'].replace(/<[^>]*>/g, ""); - element['content'] = element['content'].replace(/ /g, ''); + let data = res.data + data.data.forEach(element => { + element["content"] = element["content"].replace(/<[^>]*>/g, "") + element["content"] = element["content"].replace(/ /g, "") + }) + + list.value = list.value.concat(data.data || []) + backupsList = backupsList.concat(data.data || []) + + total.value = data.count || 0 + + keywordText.value = keyword.value || "" + + // page++ + if (list.value.length >= data["count"]) page = 0 + else page++ + + if (page == 0 && list.value.length != 0) inTheEndState.value = true + else inTheEndState.value = false + + if (list.value.length == 0) isListEmptyState.value = true + else isListEmptyState.value = false + + if (keyword.value) isSearchMode.value = true + else isSearchMode.value = false + + if (type.value == "details") handleInsertRelatedlist() + + if (list.value.length == 0) type.value = "list" }) + .finally(() => (loading.value = false)) + } - list.value = list.value.concat(data.data || []); - backupsList = backupsList.concat(data.data || []); - - total.value = data.count || 0; - - keywordText.value = keyword.value || ""; - - // page++ - if (list.value.length >= data["count"]) page = 0; - else page++; - - if (page == 0 && list.value.length != 0) inTheEndState.value = true; - else inTheEndState.value = false; - - if (list.value.length == 0) isListEmptyState.value = true; - else isListEmptyState.value = false; - - if (keyword.value) isSearchMode.value = true; - else isSearchMode.value = false; - - if (type.value == "details") handleInsertRelatedlist(); - - if (list.value.length == 0) type.value = "list" - - }).finally(() => (loading.value = false)); - }; - - let typeList = ref([]); - let typePitch = ref(null); + let typeList = ref([]) + let typePitch = ref(null) // 获取分类数据 列表分类 const getListClass = () => { - $ajaxGET("/api/common/typeList").then((res) => { - if (res.code != 200) return; - let data = res.data; - typeList.value = data; + $ajaxGET("/api/common/typeList").then(res => { + if (res.code != 200) return + let data = res.data + typeList.value = data - getPageHeight(); - }); - }; + getPageHeight() + }) + } - let pageHeaderHeight = ref(0); // 头部的高度 - let pageListHeight = ref(0); // 底部列表的高度 + let pageHeaderHeight = ref(0) // 头部的高度 + let pageListHeight = ref(0) // 底部列表的高度 const getPageHeight = () => { - let pageHeader = document.querySelector("#pageHeader"); - pageHeaderHeight.value = pageHeader.clientHeight + 10; - pageListHeight.value = window.innerHeight - pageHeaderHeight.value; - }; + let pageHeader = document.querySelector("#pageHeader") + pageHeaderHeight.value = pageHeader.clientHeight + 10 + pageListHeight.value = window.innerHeight - pageHeaderHeight.value + } - let detailsInfo = ref({}); // 详情信息 - let detailsIsanswered = ref(0); // 详情信息 - let detailsIscollection = ref(0); // 详情信息 - let detailsIsmyself = ref(0); // 详情信息 - let detailsToken = ""; // 详情信息 - let detailShare = ref({}); // 详情信息 - let detailLoading = ref(false); // 详情加载 + let detailsInfo = ref({}) // 详情信息 + let detailsIsanswered = ref(0) // 详情信息 + let detailsIscollection = ref(0) // 详情信息 + let detailsIsmyself = ref(0) // 详情信息 + let detailsToken = "" // 详情信息 + let detailShare = ref({}) // 详情信息 + let detailLoading = ref(false) // 详情加载 // 获取详情 const getDetails = (uniqid, index, isOpenAnswer) => { - if (detailLoading.value) return; - detailLoading.value = true; + if (detailLoading.value) return + detailLoading.value = true // process.env.NODE_ENV !== "production" && (uniqid = "fCSyLDDa0r1q") // 标记1一下 8yr1m1fOH5CS fubm5CnD05qj fCSyLDDa0r1q - detailsInfo.value = {}; - answerList.value = []; - answerPage.value = 0; + detailsInfo.value = {} + answerList.value = [] + answerPage.value = 0 - $ajax("/api/details", { uniqid }).then((res) => { - if (res.code != 200) { - type.value = "list"; - openBottom(); + $ajax("/api/details", { uniqid }) + .then(res => { + if (res.code != 200) { + type.value = "list" + openBottom() - pitchIndex.value = null; - return; - } - let data = res.data; - data["info"]['uniqid'] = uniqid - detailsInfo.value = data["info"] || {}; - detailsIsanswered.value = data["isanswered"] || 0; - detailsIscollection.value = data["iscollection"] || 0; - detailsIsmyself.value = data["ismyself"] || 0; - detailsToken = data["token"] || ""; - detailShare.value = data["share"] || {}; + pitchIndex.value = null + return + } + let data = res.data + data["info"]["uniqid"] = uniqid + detailsInfo.value = data["info"] || {} + detailsIsanswered.value = data["isanswered"] || 0 + detailsIscollection.value = data["iscollection"] || 0 + detailsIsmyself.value = data["ismyself"] || 0 + detailsToken = data["token"] || "" + detailShare.value = data["share"] || {} - type.value = "details"; + type.value = "details" - closeBottom(); + closeBottom() - if (index !== null && index !== undefined) cut(index); - else calculateListIndex(data.info, uniqid); + if (index !== null && index !== undefined) cut(index) + else calculateListIndex(data.info, uniqid) - answerList.value = []; - answerPage.value = 1; - getAnswerList(); + answerList.value = [] + answerPage.value = 1 + getAnswerList() - closeAllTransmitState(); + closeAllTransmitState() - if (isOpenAnswer) openIAnswer(); + if (isOpenAnswer) openIAnswer() - // 非后退状态才可以 修改 url - if (!isBackState) replaceState({ uniqid }); - isBackState = false; + // 非后退状态才可以 修改 url + if (!isBackState) replaceState({ uniqid }) + isBackState = false - seo.value = data.seo; + seo.value = data.seo - // 初始化 我来回答的框 - yourAnswer.value = { - text: "", - anonymous: 0, - }; + // 初始化 我来回答的框 + yourAnswer.value = { + text: "", + anonymous: 0, + } - // 默认 详情 div 滚动到顶部 - nextTick(() => detailsAreaScrollTop()); + // 默认 详情 div 滚动到顶部 + nextTick(() => detailsAreaScrollTop()) - handleInsertRelatedlist(uniqid); - }).finally(() => (detailLoading.value = false)); - }; + handleInsertRelatedlist(uniqid) + }) + .finally(() => (detailLoading.value = false)) + } // 默认 详情 div 滚动到顶部 预防用户在 列表重复点击 const detailsAreaScrollTop = () => { - let detailsArea = document.querySelector(".details-area-box"); + let detailsArea = document.querySelector(".details-area-box") detailsArea.scrollTo({ top: 0, behavior: "smooth", - }); - }; + }) + } const calculateListIndex = (info, uniqid) => { - let targetList = [...list.value]; + let targetList = [...list.value] if (targetList.length == 0 && isSearchMode.value == false && myModelState.value == false) { - setTimeout(() => calculateListIndex(info, uniqid), 200); - return; + setTimeout(() => calculateListIndex(info, uniqid), 200) + return } - let valve = false; + let valve = false list.value.forEach((element, index) => { if (element["uniqid"] == uniqid) { - cut(index); - pitchIndex.value = index; - valve = true; + cut(index) + pitchIndex.value = index + valve = true } - }); + }) if (!valve) { - let content = ""; - if (info["content"].indexOf("<img") == -1) content = info["content"]; - content = content.replace(/<[^>]*>/g, ""); - content = content.replace(/ /g, ''); + let content = "" + if (info["content"].indexOf("<img") == -1) content = info["content"] + content = content.replace(/<[^>]*>/g, "") + content = content.replace(/ /g, "") const obj = { answers: info["answers"], @@ -1292,105 +1257,105 @@ export default { title: info["title"], typename: info["typename"], uniqid, - }; + } - list.value.unshift(obj); - if (!myModelState.value) backupsList.unshift(obj); + list.value.unshift(obj) + if (!myModelState.value) backupsList.unshift(obj) - cut(0); + cut(0) } - }; + } - let answerList = ref([]); // 回答列表数据 - let answerPage = ref(1); // 回答列表页数 - let answerLoading = false; // 回答列表加载 + let answerList = ref([]) // 回答列表数据 + let answerPage = ref(1) // 回答列表页数 + let answerLoading = false // 回答列表加载 // 获取详情的回答数据 const getAnswerList = () => { - if (answerLoading || answerPage.value == 0) return; - answerLoading = true; + if (answerLoading || answerPage.value == 0) return + answerLoading = true $ajax("/api/details/answerList", { token: detailsToken, limit: 20, page: answerPage.value, - }).then((res) => { - if (res.code != 200) return; - let data = res.data; - - data.data.forEach((element) => { - element["commentList"] = []; - }); - - answerList.value = answerList.value.concat(data.data); - - if (answerList.value.length == data["count"]) answerPage.value = 0; - else answerPage.value++; - - detailsInfo.value["answers"] = data["count"]; - if (pitchIndex.value !== null) - list.value[pitchIndex.value]["answers"] = data["count"]; }) - .finally(() => (answerLoading = false)); - }; + .then(res => { + if (res.code != 200) return + let data = res.data + + data.data.forEach(element => { + element["commentList"] = [] + }) + + answerList.value = answerList.value.concat(data.data) + + if (answerList.value.length == data["count"]) answerPage.value = 0 + else answerPage.value++ + + detailsInfo.value["answers"] = data["count"] + if (pitchIndex.value !== null) list.value[pitchIndex.value]["answers"] = data["count"] + }) + .finally(() => (answerLoading = false)) + } // 操作 - 点赞 const operateLike = (token, index) => { if (isNeedLogin.value) { - goLogin(); - return; + goLogin() + return } - $ajax("/api/operate/like", { token }).then((res) => { - if (res.code != 200) return; - let data = res.data; - answerList.value[index]["islike"] = data["status"]; - answerList.value[index]["likenum"] = data["count"]; - handleMsg("success", res["message"] || "操作成功"); - }); - }; + $ajax("/api/operate/like", { token }).then(res => { + if (res.code != 200) return + let data = res.data + answerList.value[index]["islike"] = data["status"] + answerList.value[index]["likenum"] = data["count"] + handleMsg("success", res["message"] || "操作成功") + }) + } - let isNeedNewColletData = false; // 是否需要获取新的收藏数据 ,顶部的我的弹窗需要 + let isNeedNewColletData = false // 是否需要获取新的收藏数据 ,顶部的我的弹窗需要 // 操作 - 收藏 const operateCollect = (token = detailsToken, index) => { if (isNeedLogin.value) { - goLogin(); - return; + goLogin() + return } $ajax("/api/operate/collect", { token, - }).then((res) => { - if (res.code != 200) return; - let data = res.data; - isNeedNewColletData = true; - myCollectionPage = 1; - myCollectionList.value = []; + }).then(res => { + if (res.code != 200) return + let data = res.data + isNeedNewColletData = true + myCollectionPage = 1 + myCollectionList.value = [] if (data["type"] == "askquestioncollection") { - detailsIscollection.value = data["status"]; - detailsInfo.value["collectionnum"] = data["count"]; + detailsIscollection.value = data["status"] + detailsInfo.value["collectionnum"] = data["count"] } else { - answerList.value[index]["iscollection"] = data["status"]; - answerList.value[index]["collectionnum"] = data["count"]; + answerList.value[index]["iscollection"] = data["status"] + answerList.value[index]["collectionnum"] = data["count"] } - handleMsg("success", res["message"] || "操作成功"); + handleMsg("success", res["message"] || "操作成功") - if (data["status"]) myCount.value["collect"]++; - else myCount.value["collect"]--; - }); - }; + if (data["status"]) myCount.value["collect"]++ + else myCount.value["collect"]-- + }) + } - let IAnswerState = ref(false); // 我来回答-弹窗的状态 - let IAnswerEditState = ref(false); // 编辑回答-弹窗的状态 + let IAnswerState = ref(false) // 我来回答-弹窗的状态 + let IAnswerEditState = ref(false) // 编辑回答-弹窗的状态 - let IAnswerInfo = ref({}); // 我来回答-弹窗的信息 + let IAnswerInfo = ref({}) // 我来回答-弹窗的信息 // 开启我来回答 type: my 表示 const openIAnswer = (index, type) => { if (isNeedLogin.value) { - goLogin(); - return; + goLogin() + return } if (index == null) { @@ -1398,10 +1363,10 @@ export default { title: detailsInfo.value["title"], content: detailsInfo.value["content"], anonymous: 0, - }; - IAnswerState.value = true; + } + IAnswerState.value = true - nextTick(() => handleInput()); + nextTick(() => handleInput()) } else { if (type == "my") { IAnswerInfo.value = { @@ -1409,120 +1374,103 @@ export default { ...myAnswerList.value[index], text: myAnswerList.value[index]["content"], content: detailsInfo.value["content"], - }; - myType.value = ""; + } + myType.value = "" } else { IAnswerInfo.value = { title: detailsInfo.value["title"], ...answerList.value[index], text: answerList.value[index]["content"], content: detailsInfo.value["content"], - }; + } } - IAnswerEditState.value = true; + IAnswerEditState.value = true - nextTick(() => handleInput()); + nextTick(() => handleInput()) } - }; + } // 关闭我来回答 const closeIAnswer = () => { - IAnswerState.value = false; - IAnswerEditState.value = false; - isDirectlyListIAnswer = false; - }; + IAnswerState.value = false + IAnswerEditState.value = false + isDirectlyListIAnswer = false + } // 修改我来回答的匿名状态 const amendIAnswer = () => { - IAnswerInfo.value["anonymous"] = - IAnswerInfo.value["anonymous"] == 0 ? 1 : 0; - }; + IAnswerInfo.value["anonymous"] = IAnswerInfo.value["anonymous"] == 0 ? 1 : 0 + } // 提交回答 - const submitAnswer = (type) => { + const submitAnswer = type => { if (isNeedLogin.value) { - goLogin(); - return; + goLogin() + return } - let questionTextarea = null; + let questionTextarea = null - if (type == "you") questionTextarea = document.querySelector(".your-answer-textarea"); - else questionTextarea = document.querySelector(".question-textarea"); + if (type == "you") questionTextarea = document.querySelector(".your-answer-textarea") + else questionTextarea = document.querySelector(".question-textarea") - if (questionTextarea) IAnswerInfo.value["text"] = questionTextarea.innerHTML; + if (questionTextarea) IAnswerInfo.value["text"] = questionTextarea.innerHTML $ajax("/api/publish/answerSubmit", { token: IAnswerInfo.value["token"] || detailsToken, anonymous: IAnswerInfo.value["anonymous"] || 0, content: IAnswerInfo.value["text"], - }).then((res) => { - if (res.code != 200) return; + }).then(res => { + if (res.code != 200) return if (isDirectlyListIAnswer) { - getDetails(IAnswerInfo.value["uniqid"], IAnswerInfo.value["index"]); - IAnswerState.value = false; + getDetails(IAnswerInfo.value["uniqid"], IAnswerInfo.value["index"]) + IAnswerState.value = false } else { - answerList.value = []; - answerPage.value = 1; - getAnswerList(); - closeIAnswer(); + answerList.value = [] + answerPage.value = 1 + getAnswerList() + closeIAnswer() - if (!IAnswerInfo.value["token"]) myCount.value["answer"]++; + if (!IAnswerInfo.value["token"]) myCount.value["answer"]++ - if (type == "you") questionTextarea.innerHTML = ""; + if (type == "you") questionTextarea.innerHTML = "" } - handleMsg("success", res["message"] || "操作成功"); - }); - }; + handleMsg("success", res["message"] || "操作成功") + }) + } // 打开回答的评论 - const openCommentState = (index) => { - if (answerList.value[index]["commentState"]) - answerList.value[index]["commentState"] = false; - else answerList.value[index]["commentState"] = true; + const openCommentState = index => { + if (answerList.value[index]["commentState"]) answerList.value[index]["commentState"] = false + else answerList.value[index]["commentState"] = true - if ( - answerList.value[index]["commentList"].length == 0 && - answerList.value[index]["commentnum"] != 0 - ) - getAnswerCommentList(index); + if (answerList.value[index]["commentList"].length == 0 && answerList.value[index]["commentnum"] != 0) getAnswerCommentList(index) + } - }; - - let answerCommentLimit = 3; + let answerCommentLimit = 3 // 获取回答评论的数据 - const getAnswerCommentList = (index) => { - getAnswerCommentPublic(index, 3).then((res) => { - let data = res.data; - answerList.value[index]["commentList"] = answerList.value[index][ - "commentList" - ].concat(data.data); - answerList.value[index]["commentCount"] = data["count"]; - }); - }; + const getAnswerCommentList = index => { + getAnswerCommentPublic(index, 3).then(res => { + let data = res.data + answerList.value[index]["commentList"] = answerList.value[index]["commentList"].concat(data.data) + answerList.value[index]["commentCount"] = data["count"] + }) + } // 获取全部评论 - const handleAllComment = (index) => { - answerCommentLimit = 1000; - getAnswerCommentPublic(index, 1000).then((res) => { - if (res.code != 200) return; - let data = res.data; - let slice3 = data.data.slice(3); - let merged1 = [ - ...answerList.value[index]["commentList"], - ...slice3.filter( - (item2) => - !answerList.value[index]["commentList"].find( - (item1) => item1.id == item2.id - ) - ), - ]; + const handleAllComment = index => { + answerCommentLimit = 1000 + getAnswerCommentPublic(index, 1000).then(res => { + if (res.code != 200) return + let data = res.data + let slice3 = data.data.slice(3) + let merged1 = [...answerList.value[index]["commentList"], ...slice3.filter(item2 => !answerList.value[index]["commentList"].find(item1 => item1.id == item2.id))] - answerList.value[index]["commentList"] = merged1; - }); - }; + answerList.value[index]["commentList"] = merged1 + }) + } // 获取评论数据的公共接口 const getAnswerCommentPublic = (index, limit) => { @@ -1531,41 +1479,41 @@ export default { token: answerList.value[index]["token"], limit, childlimit: 1, - }).then((res) => { - if (res.code != 200) return; - resolve(res); - }); - }); - }; + }).then(res => { + if (res.code != 200) return + resolve(res) + }) + }) + } // 提交回答-评论 const submitAnswerComments = (index, ind, i) => { if (isNeedLogin.value) { - goLogin(); - return; + goLogin() + return } - const targetAnswerList = [...answerList.value]; + const targetAnswerList = [...answerList.value] - let content = ""; - let parentid = null; - let token = targetAnswerList[index]["token"]; + let content = "" + let parentid = null + let token = targetAnswerList[index]["token"] if (i != null) { - content = targetAnswerList[index]["commentList"][ind]["child"][i]["commentInput"]; - parentid = targetAnswerList[index]["commentList"][ind]["child"][i]["id"]; + content = targetAnswerList[index]["commentList"][ind]["child"][i]["commentInput"] + parentid = targetAnswerList[index]["commentList"][ind]["child"][i]["id"] } else if (ind != null) { - content = targetAnswerList[index]["commentList"][ind]["commentInput"]; - parentid = targetAnswerList[index]["commentList"][ind]["id"]; - } else content = targetAnswerList[index]["commentInput"]; + content = targetAnswerList[index]["commentList"][ind]["commentInput"] + parentid = targetAnswerList[index]["commentList"][ind]["id"] + } else content = targetAnswerList[index]["commentInput"] $ajax("/api/comment/submit", { content, token, parentid, - }).then((res) => { - if (res.code != 200) return; - let data = res.data; + }).then(res => { + if (res.code != 200) return + let data = res.data if (i != null) { let targetData = { @@ -1575,17 +1523,14 @@ export default { islike: 0, likenum: 0, reply: { - nickname: - targetAnswerList[index]["commentList"][ind]["child"][i][ - "nickname" - ], + nickname: targetAnswerList[index]["commentList"][ind]["child"][i]["nickname"], }, ...data, - }; + } - targetAnswerList[index]["commentList"][ind]["child"][i]["commentInput"] = ""; - targetAnswerList[index]["commentList"][ind]["child"].unshift(targetData); - targetAnswerList[index]["commentList"][ind]["childnum"]++; + targetAnswerList[index]["commentList"][ind]["child"][i]["commentInput"] = "" + targetAnswerList[index]["commentList"][ind]["child"].unshift(targetData) + targetAnswerList[index]["commentList"][ind]["childnum"]++ } else if (ind != null) { let targetData = { id: data["commentid"], @@ -1595,10 +1540,10 @@ export default { likenum: 0, reply: [], ...data, - }; - targetAnswerList[index]["commentList"][ind]["child"].unshift(targetData); - targetAnswerList[index]["commentList"][ind]["childnum"]++; - targetAnswerList[index]["commentList"][ind]["commentInput"] = ""; + } + targetAnswerList[index]["commentList"][ind]["child"].unshift(targetData) + targetAnswerList[index]["commentList"][ind]["childnum"]++ + targetAnswerList[index]["commentList"][ind]["commentInput"] = "" } else { let targetData = { id: data["commentid"], @@ -1608,86 +1553,86 @@ export default { likenum: 0, ...data, child: [], - }; - targetAnswerList[index]["commentList"].unshift(targetData); - targetAnswerList[index]["commentCount"]++; - targetAnswerList[index]["commentInput"] = ""; + } + targetAnswerList[index]["commentList"].unshift(targetData) + targetAnswerList[index]["commentCount"]++ + targetAnswerList[index]["commentInput"] = "" } - targetAnswerList[index]["commentnum"] = data["count"]; + targetAnswerList[index]["commentnum"] = data["count"] - closeAnswerCommentsChild(); + closeAnswerCommentsChild() - handleMsg("success", res["message"] || "操作成功"); - }); - }; + handleMsg("success", res["message"] || "操作成功") + }) + } // 回答-评论 点赞 const operateAnswerCommentsLike = (token, index, ind, i) => { if (isNeedLogin.value) { - goLogin(); - return; + goLogin() + return } $ajax("/api/comment/like", { token, - }).then((res) => { - if (res.code != 200) return; + }).then(res => { + if (res.code != 200) return - let data = res.data; - const targetAnswerList = [...answerList.value]; + let data = res.data + const targetAnswerList = [...answerList.value] if (i == null) { - targetAnswerList[index]["commentList"][ind]["islike"] = data["status"]; - targetAnswerList[index]["commentList"][ind]["likenum"] = data["likenum"]; + targetAnswerList[index]["commentList"][ind]["islike"] = data["status"] + targetAnswerList[index]["commentList"][ind]["likenum"] = data["likenum"] } else { - targetAnswerList[index]["commentList"][ind]["child"][i]["islike"] = data["status"]; - targetAnswerList[index]["commentList"][ind]["child"][i]["likenum"] = data["likenum"]; + targetAnswerList[index]["commentList"][ind]["child"][i]["islike"] = data["status"] + targetAnswerList[index]["commentList"][ind]["child"][i]["likenum"] = data["likenum"] } - answerList.value = targetAnswerList; + answerList.value = targetAnswerList - handleMsg("success", res["message"] || "操作成功"); - }); - }; + handleMsg("success", res["message"] || "操作成功") + }) + } // 打开 回答-评论 的子评论 const openAnswerCommentsChild = (index, ind, i) => { if (isNeedLogin.value) { - goLogin(); - return; + goLogin() + return } - closeAnswerCommentsChild(); + closeAnswerCommentsChild() - if (i == null) answerList.value[index].commentList[ind]["childState"] = true; - else answerList.value[index].commentList[ind]["child"][i]["childState"] = true; - }; + if (i == null) answerList.value[index].commentList[ind]["childState"] = true + else answerList.value[index].commentList[ind]["child"][i]["childState"] = true + } // 关闭 回答-评论 的子评论 const closeAnswerCommentsChild = (index, ind, i) => { - const targetAnswerList = [...answerList.value]; + const targetAnswerList = [...answerList.value] - targetAnswerList.forEach((element) => { + targetAnswerList.forEach(element => { if (element["commentList"] && element["commentList"].length != 0) { - element["commentList"].forEach((ele) => { - ele["childState"] = false; + element["commentList"].forEach(ele => { + ele["childState"] = false if (ele["child"] && ele["child"].length != 0) { - ele["child"].forEach((el) => { - el["childState"] = false; - }); + ele["child"].forEach(el => { + el["childState"] = false + }) } - }); + }) } - }); + }) - answerList.value = targetAnswerList; - }; + answerList.value = targetAnswerList + } // 获取剩下的子评论 const alsoCommentsData = (index, ind) => { - const targetAnswerList = [...answerList.value]; - const parentid = targetAnswerList[index]["commentList"][ind]["id"]; - const token = targetAnswerList[index]["token"]; + const targetAnswerList = [...answerList.value] + const parentid = targetAnswerList[index]["commentList"][ind]["id"] + const token = targetAnswerList[index]["token"] $ajax("/api/comment/childrenList", { token, @@ -1695,250 +1640,247 @@ export default { limit: 20, page: 1, childlimit: 1, - }).then((res) => { - if (res.code != 200) return; - let data = res.data; + }).then(res => { + if (res.code != 200) return + let data = res.data - let merged1 = [ - ...targetAnswerList[index]["commentList"][ind]["child"], ...data.data.filter((item2) => !targetAnswerList[index]["commentList"][ind]["child"].find((item1) => item1.id == item2.id)),]; + let merged1 = [...targetAnswerList[index]["commentList"][ind]["child"], ...data.data.filter(item2 => !targetAnswerList[index]["commentList"][ind]["child"].find(item1 => item1.id == item2.id))] - targetAnswerList[index]["commentList"][ind]["child"] = merged1; - answerList.value = targetAnswerList; - }); - }; + targetAnswerList[index]["commentList"][ind]["child"] = merged1 + answerList.value = targetAnswerList + }) + } - let myType = ref(""); // collect answers questions + let myType = ref("") // collect answers questions // 专门处理 我的 弹窗数据 - const handleMy = (key) => { + const handleMy = key => { if (isNeedLogin.value) { - goLogin(); - return; + goLogin() + return } if (Object.keys(myCount.value).length === 0) { - getUserData(key); - return; + getUserData(key) + return } if (key == "collect") { - myCollectionList.value = []; - myCollectionPage = 1; - getMyCollection(); + myCollectionList.value = [] + myCollectionPage = 1 + getMyCollection() } else if (key == "answers") { - myAnswerList.value = []; - myAnswerPage = 1; - getMyAnswer(); + myAnswerList.value = [] + myAnswerPage = 1 + getMyAnswer() } else if (key == "questions") { - myQuestionsList.value = []; - myQuestionsPage = 1; - getMyQuestions(); + myQuestionsList.value = [] + myQuestionsPage = 1 + getMyQuestions() } - }; + } - let myCollectionList = ref([]); // 我的收藏列表 - let myCollectionCount = ref(0); // 我的收藏数量 - let myCollectionPage = 1; // 我的收藏页数 - let myCollectionLading = false; // 我的收藏加载中 + let myCollectionList = ref([]) // 我的收藏列表 + let myCollectionCount = ref(0) // 我的收藏数量 + let myCollectionPage = 1 // 我的收藏页数 + let myCollectionLading = false // 我的收藏加载中 // 获取我的收藏 const getMyCollection = () => { - if (myCollectionPage == 0 || myCollectionLading) return; - myCollectionLading = true; + if (myCollectionPage == 0 || myCollectionLading) return + myCollectionLading = true $ajax("/api/user/collect", { limit: 20, page: myCollectionPage, }) - .then((res) => { - if (res.code != 200) return; - let data = res.data; - myType.value = "collect"; - isNeedNewColletData = false; + .then(res => { + if (res.code != 200) return + let data = res.data + myType.value = "collect" + isNeedNewColletData = false - data.data.forEach((element) => { + data.data.forEach(element => { if (element["type"] == "askanswercollection") { - let content = element["data"]["content"]; - element["data"]["content"] = processHtml(content); + let content = element["data"]["content"] + element["data"]["content"] = processHtml(content) } - }); + }) - myCollectionList.value = myCollectionList.value.concat(data.data); - myCollectionCount.value = data.count; + myCollectionList.value = myCollectionList.value.concat(data.data) + myCollectionCount.value = data.count - if (myCollectionList.value.length != data["count"]) - myCollectionPage++; - else myCollectionPage = 0; + if (myCollectionList.value.length != data["count"]) myCollectionPage++ + else myCollectionPage = 0 }) - .finally(() => (myCollectionLading = false)); - }; + .finally(() => (myCollectionLading = false)) + } - const processHtml = (html) => { - var parser = new DOMParser(); - var doc = parser.parseFromString(html, "text/html"); - var img = doc.querySelector("img"); - if (img) return `<img src="${img.src}">`; - else return doc.body.textContent; - - }; + const processHtml = html => { + var parser = new DOMParser() + var doc = parser.parseFromString(html, "text/html") + var img = doc.querySelector("img") + if (img) return `<img src="${img.src}">` + else return doc.body.textContent + } // 取消收藏 const cancelCollection = (token, index) => { - $ajax("/api/user/deleteCollect", { token }).then((res) => { + $ajax("/api/user/deleteCollect", { token }).then(res => { if (res.code == 200) { - myCollectionList.value.splice(index, 1); - myCollectionCount.value--; - myCount.value["collect"]--; - handleMsg("success", res["message"] || "操作成功"); + myCollectionList.value.splice(index, 1) + myCollectionCount.value-- + myCount.value["collect"]-- + handleMsg("success", res["message"] || "操作成功") } - }); - }; + }) + } // 监听 我的收藏滚动到底部 - const handleCollectionScroll = (e) => { - const el = e.target; - if (el.scrollHeight - el.scrollTop >= el.clientHeight + 10) return; - getMyCollection(); - }; + const handleCollectionScroll = e => { + const el = e.target + if (el.scrollHeight - el.scrollTop >= el.clientHeight + 10) return + getMyCollection() + } - let myAnswerList = ref([]); // 我的回答数据 - let myAnswerCount = ref(0); // 我的回答数量 - let myAnswerPage = 1; - let myAnswerloadimg = false; + let myAnswerList = ref([]) // 我的回答数据 + let myAnswerCount = ref(0) // 我的回答数量 + let myAnswerPage = 1 + let myAnswerloadimg = false // 获取我的回答 const getMyAnswer = () => { - if (myAnswerPage == 0 || myAnswerloadimg) return; - myAnswerloadimg = true; + if (myAnswerPage == 0 || myAnswerloadimg) return + myAnswerloadimg = true $ajax("/api/user/answer", { limit: 20, page: myAnswerPage, - }).then((res) => { - if (res.code != 200) return; - let data = res.data; - data.data.forEach((element) => { - element["popupState"] = false; - }); - - data.data.forEach((element) => { - let content = element["content"]; - element["content"] = processHtml(content); - }); - - myAnswerList.value = myAnswerList.value.concat(data.data); - myAnswerCount.value = data.count; - - if (myAnswerList.value.length != data["count"]) myAnswerPage++; - else myAnswerPage = 0; - - myType.value = "answers"; }) - .finally(() => (myAnswerloadimg = false)); - }; + .then(res => { + if (res.code != 200) return + let data = res.data + data.data.forEach(element => { + element["popupState"] = false + }) + + data.data.forEach(element => { + let content = element["content"] + element["content"] = processHtml(content) + }) + + myAnswerList.value = myAnswerList.value.concat(data.data) + myAnswerCount.value = data.count + + if (myAnswerList.value.length != data["count"]) myAnswerPage++ + else myAnswerPage = 0 + + myType.value = "answers" + }) + .finally(() => (myAnswerloadimg = false)) + } // 我的回答 的滚动到底部事件 - const handleAnswersScroll = (e) => { - const el = e.target; + const handleAnswersScroll = e => { + const el = e.target // 判断滚动到底部 - if (el.scrollHeight - el.scrollTop >= el.clientHeight + 10) return; - getMyAnswer(); - }; + if (el.scrollHeight - el.scrollTop >= el.clientHeight + 10) return + getMyAnswer() + } - let answerIndexOld = null; + let answerIndexOld = null // 切换 我的提问的公开匿名 弹窗状态 - const cutAnswerPopupState = (index) => { - myAnswerList.value[index]["popupState"] = true; + const cutAnswerPopupState = index => { + myAnswerList.value[index]["popupState"] = true if (answerIndexOld == index) { - myAnswerList.value[index]["popupState"] = false; - answerIndexOld = null; + myAnswerList.value[index]["popupState"] = false + answerIndexOld = null } else { - myAnswerList.value[index]["popupState"] = true; - if (answerIndexOld != null) myAnswerList.value[answerIndexOld]["popupState"] = false; - answerIndexOld = index; + myAnswerList.value[index]["popupState"] = true + if (answerIndexOld != null) myAnswerList.value[answerIndexOld]["popupState"] = false + answerIndexOld = index } - }; + } // 更改匿名状态 const changeAnonymous = (token, anonymous, index) => { $ajax("/api/publish/changeAnonymous", { token, anonymous, - }).then((res) => { - if (res.code != 200) return; - let data = res.data; - myAnswerList.value[index]["anonymous"] = anonymous; - cutAnswerPopupState(index); - handleMsg("success", res["message"] || "操作成功"); - }); - }; + }).then(res => { + if (res.code != 200) return + let data = res.data + myAnswerList.value[index]["anonymous"] = anonymous + cutAnswerPopupState(index) + handleMsg("success", res["message"] || "操作成功") + }) + } - let myQuestionsList = ref([]); // 我的提问数据 - let myQuestionsCount = ref(0); // 我的提问数量 - let myQuestionsPage = 0; // 我的提问页数 - let myQuestionsloading = false; // 我的提问页数 + let myQuestionsList = ref([]) // 我的提问数据 + let myQuestionsCount = ref(0) // 我的提问数量 + let myQuestionsPage = 0 // 我的提问页数 + let myQuestionsloading = false // 我的提问页数 // 获取我的提问 const getMyQuestions = () => { - if (myQuestionsPage == 0 || myQuestionsloading) return; - myQuestionsloading = true; + if (myQuestionsPage == 0 || myQuestionsloading) return + myQuestionsloading = true $ajax("/api/user/questions", { limit: 20, page: myQuestionsPage, }) - .then((res) => { - if (res.code != 200) return; - let data = res.data; - myQuestionsList.value = myQuestionsList.value.concat(data.data); - myQuestionsCount.value = data.count; - myType.value = "questions"; + .then(res => { + if (res.code != 200) return + let data = res.data + myQuestionsList.value = myQuestionsList.value.concat(data.data) + myQuestionsCount.value = data.count + myType.value = "questions" - if (myQuestionsList.value.length != data["count"]) myQuestionsPage++; - else myQuestionsPage = 0; + if (myQuestionsList.value.length != data["count"]) myQuestionsPage++ + else myQuestionsPage = 0 }) - .finally(() => (myQuestionsloading = false)); - }; + .finally(() => (myQuestionsloading = false)) + } // 我的提问 的滚动到底部 事件 - const handleQuestionsScroll = (e) => { - const el = e.target; + const handleQuestionsScroll = e => { + const el = e.target // 判断滚动到底部 - if (el.scrollHeight - el.scrollTop >= el.clientHeight + 10) return; - getMyQuestions(); - }; + if (el.scrollHeight - el.scrollTop >= el.clientHeight + 10) return + getMyQuestions() + } - let questionsIndexOld = null; + let questionsIndexOld = null // 切换 我的提问的公开匿名 弹窗状态 - const cutQuestionsPopupState = (index) => { - myQuestionsList.value[index]["popupState"] = true; + const cutQuestionsPopupState = index => { + myQuestionsList.value[index]["popupState"] = true if (questionsIndexOld == index) { - myQuestionsList.value[index]["popupState"] = false; - questionsIndexOld = null; + myQuestionsList.value[index]["popupState"] = false + questionsIndexOld = null } else { - myQuestionsList.value[index]["popupState"] = true; - if (questionsIndexOld != null) - myQuestionsList.value[questionsIndexOld]["popupState"] = false; - questionsIndexOld = index; + myQuestionsList.value[index]["popupState"] = true + if (questionsIndexOld != null) myQuestionsList.value[questionsIndexOld]["popupState"] = false + questionsIndexOld = index } - }; + } // 更改匿名状态 const changeAnonymousQuestions = (token, anonymous, index) => { $ajax("/api/publish/changeAnonymous", { token, anonymous, - }).then((res) => { - if (res.code != 200) return; - myQuestionsList.value[index]["anonymous"] = anonymous; - cutQuestionsPopupState(index); - handleMsg("success", res["message"] || "操作成功"); - }); - }; + }).then(res => { + if (res.code != 200) return + myQuestionsList.value[index]["anonymous"] = anonymous + cutQuestionsPopupState(index) + handleMsg("success", res["message"] || "操作成功") + }) + } - let questionsSetp = ref(0); // 提问的步骤 + let questionsSetp = ref(0) // 提问的步骤 // 切换提问步骤 - const cutQuestionsSetp = (value) => (questionsSetp.value = value); + const cutQuestionsSetp = value => (questionsSetp.value = value) - let questionsTypeList = ref([]); // 提问的类型主题 + let questionsTypeList = ref([]) // 提问的类型主题 let questionsObj = ref({ // 提问的内容 token: "", @@ -1947,49 +1889,49 @@ export default { tags: "", tid: "", anonymous: 0, - }); + }) // 报 提问的初始化 const questionsInit = () => { if (isNeedLogin.value) { - goLogin(); - return; + goLogin() + return } - deleteState(['ispublish']) + deleteState(["ispublish"]) - $ajax("/api/publish/questions").then((res) => { - if (res.code != 200) return; - let data = res.data; - questionsObj.value["token"] = data["token"]; + $ajax("/api/publish/questions").then(res => { + if (res.code != 200) return + let data = res.data + questionsObj.value["token"] = data["token"] - questionsTypeList.value = data["typeList"] || []; - cutQuestionsSetp(1); - }); - }; + questionsTypeList.value = data["typeList"] || [] + cutQuestionsSetp(1) + }) + } // 选择提问主题 - const choosingTheme = (id) => { - questionsObj.value.tid = id; - cutQuestionsSetp(2); - }; + const choosingTheme = id => { + questionsObj.value.tid = id + cutQuestionsSetp(2) + } // 切换匿名状态 const cutAnonymous = () => { - questionsObj.value.anonymous = questionsObj.value.anonymous == 0 ? 1 : 0; - }; + questionsObj.value.anonymous = questionsObj.value.anonymous == 0 ? 1 : 0 + } // 发布问题 const postingIssue = () => { if (isNeedLogin.value) { - goLogin(); - return; + goLogin() + return } - $ajax("/api/publish/questionsSubmit", questionsObj.value).then((res) => { + $ajax("/api/publish/questionsSubmit", questionsObj.value).then(res => { if (res.code == 200) { - myCount.value["questions"]++; - questionsSetp.value = 0; + myCount.value["questions"]++ + questionsSetp.value = 0 questionsObj.value = { token: "", title: "", @@ -1997,394 +1939,376 @@ export default { tags: "", tid: "", anonymous: 0, - }; - handleMsg("success", res["message"] || "操作成功"); - let data = res.data; - getDetails(data["uniqid"]); - return; + } + handleMsg("success", res["message"] || "操作成功") + let data = res.data + getDetails(data["uniqid"]) + return } - handleMsg("error", res["message"] || "刷新重试!!!"); - }); - }; + handleMsg("error", res["message"] || "刷新重试!!!") + }) + } - let pitchIndex = ref(null); // 选中的下标 + let pitchIndex = ref(null) // 选中的下标 // 切换 滚动列表 - const cut = (index) => { - pitchIndex.value = index; + const cut = index => { + pitchIndex.value = index - setTimeout(() => scrollLeftInMiddle(), 350); - }; + setTimeout(() => scrollLeftInMiddle(), 350) + } // 是否需要在 onMounted 滚动左边在中间 - let isNeedScrollMiddle = false; + let isNeedScrollMiddle = false // 滚动左边在中间 const scrollLeftInMiddle = () => { if (typeof document === "undefined") { - isNeedScrollMiddle = true; - return; + isNeedScrollMiddle = true + return } - let list = document.querySelector(".list-box"); - let item = list.querySelector(`.item${pitchIndex.value}`); + let list = document.querySelector(".list-box") + let item = list.querySelector(`.item${pitchIndex.value}`) // 136 分为 两个68,一个是item高度的一半,另一个是列表顶部的 数量 - let top = item.offsetTop - pageListHeight.value / 2 + 136; + let top = item.offsetTop - pageListHeight.value / 2 + 136 list.scrollTo({ top, behavior: "smooth", - }); + }) - isNeedScrollMiddle = false; - }; + isNeedScrollMiddle = false + } const listStyle = () => { - const newtype = type.value; - let width = ""; - let margin = ""; - let height = ""; + const newtype = type.value + let width = "" + let margin = "" + let height = "" if (newtype == "list") { - width = "1200px"; - margin = "0 auto"; + width = "1200px" + margin = "0 auto" } else { - width = "calc((100vw - 1200px) / 2 + 512px)"; - margin = "initial"; + width = "calc((100vw - 1200px) / 2 + 512px)" + margin = "initial" } return { width, margin, height, - }; - }; + } + } - let listHeight = ref(0); - let itemHeightLeft = 0; - let itemHeightRight = 0; + let listHeight = ref(0) + let itemHeightLeft = 0 + let itemHeightRight = 0 const itemStyle = (index, content, typetype) => { if (index == 0) { - itemHeightLeft = 0; - itemHeightRight = 0; + itemHeightLeft = 0 + itemHeightRight = 0 } - const newtype = type.value; + const newtype = type.value // let itemHeight = content == "" ? 107 : 128 - let obj = {}; + let obj = {} if (newtype == "list") { // let top = Math.floor(index / 2) * 128 + "px" // obj["top"] = Math.floor(index / 2) * 128 + "px" // obj["top"] = Math.floor(index / 2) * 128 + "px" if (itemHeightLeft <= itemHeightRight) { - obj["top"] = itemHeightLeft + "px"; - itemHeightLeft += content == "" ? 107 : 137; - obj["left"] = 0; + obj["top"] = itemHeightLeft + "px" + itemHeightLeft += content == "" ? 107 : 137 + obj["left"] = 0 } else { - obj["top"] = itemHeightRight + "px"; - itemHeightRight += content == "" ? 107 : 137; - obj["left"] = 649 + "px"; + obj["top"] = itemHeightRight + "px" + itemHeightRight += content == "" ? 107 : 137 + obj["left"] = 649 + "px" } } else { // obj["top"] = itemHeightLeft + "px"; - obj["position"] = "relative"; + obj["position"] = "relative" // position: static; if (!typetype) { - itemHeightLeft += content == "" ? 107 : 137; - obj["height"] = content == "" ? 107 + "px" : 137 + "px"; + itemHeightLeft += content == "" ? 107 : 137 + obj["height"] = content == "" ? 107 + "px" : 137 + "px" } else { - itemHeightLeft += typetype == "vote" ? 170 : 137; - obj["height"] = typetype == "vote" ? 170 + "px" : 137 + "px"; + itemHeightLeft += typetype == "vote" ? 170 : 137 + obj["height"] = typetype == "vote" ? 170 + "px" : 137 + "px" } // obj["left"] = 0; - obj["width"] = "100%"; - obj["paddingLeft"] = "calc((100vw - 1200px) / 2)"; + obj["width"] = "100%" + obj["paddingLeft"] = "calc((100vw - 1200px) / 2)" } // 通过最后一个 算 列表的高度 - if (index + 1 == list.value.length) listHeight.value = Math.max(itemHeightLeft, itemHeightRight); + if (index + 1 == list.value.length) listHeight.value = Math.max(itemHeightLeft, itemHeightRight) - return obj; - }; + return obj + } const bottomTpsStyle = (index, content) => { - const newtype = type.value; - let obj = {}; + const newtype = type.value + let obj = {} if (newtype == "list") { } else { - obj["width"] = "calc(50vw - 88px)"; - obj["height"] = `calc(100vh - ${list.value.length * 128}px - 268px)`; - obj["paddingLeft"] = "calc((100vw - 1200px) / 2)"; - obj["borderRight"] = "1px solid #ebebeb"; - obj["borderRight"] = "1px solid #ebebeb"; - obj["background"] = "#fff"; + obj["width"] = "calc(50vw - 88px)" + obj["height"] = `calc(100vh - ${list.value.length * 128}px - 268px)` + obj["paddingLeft"] = "calc((100vw - 1200px) / 2)" + obj["borderRight"] = "1px solid #ebebeb" + obj["borderRight"] = "1px solid #ebebeb" + obj["background"] = "#fff" } - return obj; - }; + return obj + } // list-box const listBoxStyle = () => { - const newtype = type.value; - let obj = {}; - if (newtype == "list") obj["overflow"] = "visible"; - else obj["height"] = pageListHeight.value + "px"; + const newtype = type.value + let obj = {} + if (newtype == "list") obj["overflow"] = "visible" + else obj["height"] = pageListHeight.value + "px" - return obj; - }; + return obj + } // 处理时间 const handleDate = (dateTimeStamp = new Date()) => { - dateTimeStamp = dateTimeStamp ? dateTimeStamp : null; - var timestamp = new Date(dateTimeStamp); - timestamp = timestamp.getTime(); - var minute = 1000 * 60; - var hour = minute * 60; - var day = hour * 24; - var now = new Date().getTime(); - var diffValue = now - timestamp; - var result; - if (diffValue < 0) return; + dateTimeStamp = dateTimeStamp ? dateTimeStamp : null + var timestamp = new Date(dateTimeStamp) + timestamp = timestamp.getTime() + var minute = 1000 * 60 + var hour = minute * 60 + var day = hour * 24 + var now = new Date().getTime() + var diffValue = now - timestamp + var result + if (diffValue < 0) return - var dayC = diffValue / day; - var hourC = diffValue / (hour + 1); - var minC = diffValue / minute; + var dayC = diffValue / day + var hourC = diffValue / (hour + 1) + var minC = diffValue / minute if (dayC >= 7) { - let date = new Date(timestamp); - let Y = date.getFullYear() + "-"; - let M = - (date.getMonth() + 1 < 10 - ? "0" + (date.getMonth() + 1) - : date.getMonth() + 1) + "-"; - let D = - (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " "; - let h = - (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + - ":"; - let m = - date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(); - result = "" + Y + M + D + h + m; - } else if (dayC >= 1) result = "" + Math.round(dayC) + "天前"; - else if (hourC >= 1) result = "" + Math.round(hourC) + "小时前"; - else if (minC >= 1) result = "" + Math.round(minC) + "分钟前"; - else result = "刚刚"; + let date = new Date(timestamp) + let Y = date.getFullYear() + "-" + let M = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-" + let D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " " + let h = (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":" + let m = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes() + result = "" + Y + M + D + h + m + } else if (dayC >= 1) result = "" + Math.round(dayC) + "天前" + else if (hourC >= 1) result = "" + Math.round(hourC) + "小时前" + else if (minC >= 1) result = "" + Math.round(minC) + "分钟前" + else result = "刚刚" - return result; - }; + return result + } - let questionsTransmitState = ref(false); // 问题的转发 弹窗状态 - let questionsTransmitMaskState = ref(false); // 问题的转发 弹窗蒙版状态状态 + let questionsTransmitState = ref(false) // 问题的转发 弹窗状态 + let questionsTransmitMaskState = ref(false) // 问题的转发 弹窗蒙版状态状态 // 关闭转发状态 const closeTransmitState = () => { - questionsTransmitState.value = true; - questionsTransmitMaskState.value = true; - countForwardingTimes(detailsToken); - }; + questionsTransmitState.value = true + questionsTransmitMaskState.value = true + countForwardingTimes(detailsToken) + } // 关闭全部转发状态 const closeAllTransmitState = () => { - answerList.value.forEach((element) => { - element["transmitState"] = false; - }); - questionsTransmitState.value = false; - questionsTransmitMaskState.value = false; - }; + answerList.value.forEach(element => { + element["transmitState"] = false + }) + questionsTransmitState.value = false + questionsTransmitMaskState.value = false + } // 开启和关闭回答的转发状态 type open close const handleAnswerTransmitList = (Iindex, type) => { - answerList.value[Iindex]["transmitState"] = true; - questionsTransmitMaskState.value = true; - countForwardingTimes(answerList.value[Iindex]["token"]); - }; + answerList.value[Iindex]["transmitState"] = true + questionsTransmitMaskState.value = true + countForwardingTimes(answerList.value[Iindex]["token"]) + } // 统计转发次数 - const countForwardingTimes = (token) => { - process.env.NODE_ENV === "production" && - $ajaxGET("/api/operate/share?token=" + token); - }; + const countForwardingTimes = token => { + process.env.NODE_ENV === "production" && $ajaxGET("/api/operate/share?token=" + token) + } // 关闭详情模式 const closeDetailMode = () => { - deleteState(["uniqid"]); + deleteState(["uniqid"]) if (myModelState.value) { - closeMyModel(); - return; + closeMyModel() + return } - type.value = "list"; - openBottom(); - pitchIndex.value = null; - seo.value = {}; - list.value = JSON.parse(JSON.stringify(backupsList)); - }; + type.value = "list" + openBottom() + pitchIndex.value = null + seo.value = {} + list.value = JSON.parse(JSON.stringify(backupsList)) + } // 全部的启动到底部 - const handleListScroll = (e) => { - const el = e.target; - if (el.scrollHeight - el.scrollTop >= el.clientHeight + 40 || myModelState.value) return; - getList(); - }; + const handleListScroll = e => { + const el = e.target + if (el.scrollHeight - el.scrollTop >= el.clientHeight + 40 || myModelState.value) return + getList() + } // 处理 回答弹窗的复制图片 type:you 为 您的答案 const handlePaste = (event, type) => { - const items = (event.clipboardData || event.originalEvent.clipboardData).items; + const items = (event.clipboardData || event.originalEvent.clipboardData).items for (const item of items) { if (item.type.indexOf("image") === 0) { // 如果包含图片,阻止默认行为 - event.preventDefault(); - handleMsg("warning", "上传图片中"); - const file = item.getAsFile(); - const reader = new FileReader(); + event.preventDefault() + handleMsg("warning", "上传图片中") + const file = item.getAsFile() + const reader = new FileReader() - reader.onload = (e) => { - const base64 = e.target.result; - uploadImg(base64).then((res) => { - let questionTextarea = null; - if (type == "you") questionTextarea = document.querySelector(".your-answer-textarea"); - else questionTextarea = document.querySelector(".question-textarea"); + reader.onload = e => { + const base64 = e.target.result + uploadImg(base64).then(res => { + let questionTextarea = null + if (type == "you") questionTextarea = document.querySelector(".your-answer-textarea") + else questionTextarea = document.querySelector(".question-textarea") - let imgNode = document.createElement("img"); - imgNode.setAttribute("src", res.url); - imgNode.setAttribute("data-aid", res.aid); - questionTextarea.appendChild(imgNode); + let imgNode = document.createElement("img") + imgNode.setAttribute("src", res.url) + imgNode.setAttribute("data-aid", res.aid) + questionTextarea.appendChild(imgNode) - if (type == "you") handleInputYou(); - else handleInput(); + if (type == "you") handleInputYou() + else handleInput() - handleMsg("success", "上传成功"); - }); - }; - reader.readAsDataURL(file); + handleMsg("success", "上传成功") + }) + } + reader.readAsDataURL(file) } } - }; + } // 上传图片 获取图片url - const uploadImg = (base64) => { + const uploadImg = base64 => { return new Promise((resolve, reject) => { $ajax("/api/common/upload", { data: base64, - }).then((res) => { - if (res.code != 200) return; - let data = res.data; - resolve(data); - }); - }); - }; + }).then(res => { + if (res.code != 200) return + let data = res.data + resolve(data) + }) + }) + } // 回答 的 placeholder 状态 - let questionPlaceholderState = ref(false); - let yourAnswerPlaceholderState = ref(true); // 您的答案的 placeholder 状态 + let questionPlaceholderState = ref(false) + let yourAnswerPlaceholderState = ref(true) // 您的答案的 placeholder 状态 // 回答的输入事件 判断是否显示 placeholder 用 const handleInput = () => { - const questionTextarea = document.querySelector(".question-textarea"); - const html = questionTextarea.innerHTML; - if (html) questionPlaceholderState.value = false; - else questionPlaceholderState.value = true; - }; + const questionTextarea = document.querySelector(".question-textarea") + const html = questionTextarea.innerHTML + if (html) questionPlaceholderState.value = false + else questionPlaceholderState.value = true + } const handleInputYou = () => { - const questionTextarea = document.querySelector(".your-answer-textarea"); - const html = questionTextarea.innerHTML; - if (html) yourAnswerPlaceholderState.value = false; - else yourAnswerPlaceholderState.value = true; - }; + const questionTextarea = document.querySelector(".your-answer-textarea") + const html = questionTextarea.innerHTML + if (html) yourAnswerPlaceholderState.value = false + else yourAnswerPlaceholderState.value = true + } - let msg = ref({}); // 提示文本的对象 state 类型 type success warning error 显示状态 text 内容 + let msg = ref({}) // 提示文本的对象 state 类型 type success warning error 显示状态 text 内容 // 调用 提示框方法 const handleMsg = (type, text) => { - msg.value["state"] = true; - msg.value["type"] = type; - msg.value["text"] = text; - }; + msg.value["state"] = true + msg.value["type"] = type + msg.value["text"] = text + } // 修改提示框类型 const boxClass = () => { - msgShowTimer(); - return type ? `box-item-${msg.value["type"]}` : ""; - }; + msgShowTimer() + return type ? `box-item-${msg.value["type"]}` : "" + } - let msgTimer = null; + let msgTimer = null const msgShowTimer = () => { - clearTimeout(msgTimer); + clearTimeout(msgTimer) msgTimer = setTimeout(() => { - msg.value["state"] = false; - }, 1000); - }; + msg.value["state"] = false + }, 1000) + } // 复制 - let copyText = (text) => { + let copyText = text => { if (navigator.clipboard) { copyText = () => { - navigator.clipboard.writeText(text); - handleMsg("success", "复制成功"); - }; + navigator.clipboard.writeText(text) + handleMsg("success", "复制成功") + } } else { copyText = () => { - var tempInput = document.createElement("input"); - tempInput.value = text; - document.body.appendChild(tempInput); - tempInput.select(); - document.execCommand("copy"); - document.body.removeChild(tempInput); - handleMsg("success", "复制成功"); - }; + var tempInput = document.createElement("input") + tempInput.value = text + document.body.appendChild(tempInput) + tempInput.select() + document.execCommand("copy") + document.body.removeChild(tempInput) + handleMsg("success", "复制成功") + } } - copyText(); - }; + copyText() + } // 修改 url const replaceState = (obj = {}) => { - if (typeof window === "undefined") return; + if (typeof window === "undefined") return // 获取当前URL参数 - let params = new URLSearchParams(window.location.search); + let params = new URLSearchParams(window.location.search) for (const key in obj) { - params.set(key, obj[key]); + params.set(key, obj[key]) } // 替换当前URL,但不刷新页面 - if (window.location.pathname.indexOf("index.html") == -1) - window.history.pushState( - {}, - "", - `${window.location.pathname}index.html?${params}` - ); - else - window.history.pushState( - {}, - "", - `${window.location.pathname}?${params}` - ); + if (window.location.pathname.indexOf("index.html") == -1) window.history.pushState({}, "", `${window.location.pathname}index.html?${params}`) + else window.history.pushState({}, "", `${window.location.pathname}?${params}`) - let location = window.location; - let contentUrl = location.pathname + location.search; - if (window._hmt) window._hmt.push(["_trackPageview", contentUrl]); + let location = window.location + let contentUrl = location.pathname + location.search + if (window._hmt) window._hmt.push(["_trackPageview", contentUrl]) // 用于发送某个URL的PV统计请求 - if (window._czc) window._czc.push(["_trackPageview", contentUrl]); - }; + if (window._czc) window._czc.push(["_trackPageview", contentUrl]) + } // 删除 url 参数的key const deleteState = (keys = []) => { - if (typeof window === "undefined") return; + if (typeof window === "undefined") return - let params = new URLSearchParams(window.location.search); - keys.forEach((key) => { - params.delete(key); - }); - window.history.pushState({}, "", `${window.location.pathname}?${params}`); - }; + let params = new URLSearchParams(window.location.search) + keys.forEach(key => { + params.delete(key) + }) + window.history.pushState({}, "", `${window.location.pathname}?${params}`) + } - let myModelState = ref(false); // 我的模式状态 - let myModelList = ref([]); // 我的模式列表 - let temporaryData = {}; // 临时存放 + let myModelState = ref(false) // 我的模式状态 + let myModelList = ref([]) // 我的模式列表 + let temporaryData = {} // 临时存放 // 我的打开 详情 - const myOpenDetails = (uniqid) => { + const myOpenDetails = uniqid => { if (!uniqid) { - handleMsg("error", "没有找到相关提问"); - return; + handleMsg("error", "没有找到相关提问") + return } - deleteState(["keyword"]); + deleteState(["keyword"]) if (!myModelState.value) { temporaryData = { @@ -2395,222 +2319,212 @@ export default { type: type.value, pitchIndex: pitchIndex.value, listlist: JSON.parse(JSON.stringify(list.value)), - }; + } - isSearchMode.value = false; - inTheEndState.value = false; - keyword.value = ""; + isSearchMode.value = false + inTheEndState.value = false + keyword.value = "" - list.value = JSON.parse(JSON.stringify(myModelList.value)); + list.value = JSON.parse(JSON.stringify(myModelList.value)) - myModelState.value = true; - pitchIndex.value = null; + myModelState.value = true + pitchIndex.value = null } - getDetails(uniqid); + getDetails(uniqid) - myType.value = ""; - }; + myType.value = "" + } // 关闭我的模式 const closeMyModel = () => { - myModelList.value = JSON.parse(JSON.stringify(list.value)); - isSearchMode.value = temporaryData["isSearchMode"]; - keywordText.value = temporaryData["keywordText"]; - keyword.value = temporaryData["keywordText"]; - total.value = temporaryData["total"]; - type.value = temporaryData["type"]; - pitchIndex.value = temporaryData["pitchIndex"]; - inTheEndState.value = temporaryData["inTheEndState"]; - list.value = JSON.parse(JSON.stringify(temporaryData.listlist)); + myModelList.value = JSON.parse(JSON.stringify(list.value)) + isSearchMode.value = temporaryData["isSearchMode"] + keywordText.value = temporaryData["keywordText"] + keyword.value = temporaryData["keywordText"] + total.value = temporaryData["total"] + type.value = temporaryData["type"] + pitchIndex.value = temporaryData["pitchIndex"] + inTheEndState.value = temporaryData["inTheEndState"] + list.value = JSON.parse(JSON.stringify(temporaryData.listlist)) - myModelState.value = false; + myModelState.value = false if (pitchIndex.value !== null && pitchIndex.value !== undefined) { - let uniqid = list.value[pitchIndex.value]["uniqid"]; - getDetails(uniqid); + let uniqid = list.value[pitchIndex.value]["uniqid"] + getDetails(uniqid) } - }; + } // 详情页滚动事件 - const handleDetailsScroll = (e) => { - const el = e.target; + const handleDetailsScroll = e => { + const el = e.target // 判断滚动到底部 - if (el.scrollHeight - el.scrollTop !== el.clientHeight) return; - getAnswerList(); - }; + if (el.scrollHeight - el.scrollTop !== el.clientHeight) return + getAnswerList() + } - let dialogSrc = ref(""); // 大图的src + let dialogSrc = ref("") // 大图的src // 处理点击答案图片 展开大图 - const handleAnswerText = (e) => { + const handleAnswerText = e => { if (e.target.tagName === "IMG") { - var src = e.target.getAttribute("src"); - dialogSrc.value = src; - window.addEventListener("keydown", handleKeydown); + var src = e.target.getAttribute("src") + dialogSrc.value = src + window.addEventListener("keydown", handleKeydown) } - }; + } // 大图的监听 esc 键盘按钮 - const handleKeydown = (event) => { - if (event.key !== "Escape") return; - dialogSrc.value = ""; - window.removeEventListener("keydown", handleKeydown); // 取消监听 - }; + const handleKeydown = event => { + if (event.key !== "Escape") return + dialogSrc.value = "" + window.removeEventListener("keydown", handleKeydown) // 取消监听 + } // 切换顶部的 type - const cutType = (id) => { - typePitch.value = id; - page = 1; - list.value = []; - backupsList = []; + const cutType = id => { + typePitch.value = id + page = 1 + list.value = [] + backupsList = [] listHeight.value = 0 myModelState.value = false - type.value = "list"; - openBottom(); - pitchIndex.value = null; + type.value = "list" + openBottom() + pitchIndex.value = null if (id != null) { replaceState({ tid: id, - }); - deleteState(["uniqid"]); - } else deleteState(["tid", "uniqid"]); + }) + deleteState(["uniqid"]) + } else deleteState(["tid", "uniqid"]) - getList(); + getList() // 创新请求 设置列表的高度 为0 - listHeight.value = 0; - }; + listHeight.value = 0 + } // 打开举报 const handleMenuState = (index, ind, i) => { if (isNeedLogin.value) { - goLogin(); - return; + goLogin() + return } - if (i === undefined) - reportToken = answerList.value[index].commentList[ind]["token"]; - else - reportToken = - answerList.value[index].commentList[ind]["child"][i]["token"]; - alertShow.value = true; - }; + if (i === undefined) reportToken = answerList.value[index].commentList[ind]["token"] + else reportToken = answerList.value[index].commentList[ind]["child"][i]["token"] + alertShow.value = true + } // 举报 token - let reportToken = ""; - const reasonList = ["广告", "辱骂", "重复发送", "不良信息", "其他"]; - let checkList = ref([]); - let alertShow = ref(false); - let alertText = ref(""); - const selectRadio = (value) => { - const index = checkList.value.indexOf(value); - if (index === -1) checkList.value.push(value); - else checkList.value.splice(index, 1); - }; + let reportToken = "" + const reasonList = ["广告", "辱骂", "重复发送", "不良信息", "其他"] + let checkList = ref([]) + let alertShow = ref(false) + let alertText = ref("") + const selectRadio = value => { + const index = checkList.value.indexOf(value) + if (index === -1) checkList.value.push(value) + else checkList.value.splice(index, 1) + } // 举报提交 const alertSubmit = () => { - checkList.value.push(alertText.value); + checkList.value.push(alertText.value) $ajax("/api/operate/report", { message: checkList.value, token: reportToken, - }).then((res) => { - checkList.value = []; - reportToken = ""; - alertShow.value = false; - handleMsg("success", "举报成功"); - }); - }; + }).then(res => { + checkList.value = [] + reportToken = "" + alertShow.value = false + handleMsg("success", "举报成功") + }) + } onMounted(() => { watchEffect(() => { - if ( - questionsSetp.value || - myType.value || - IAnswerEditState.value || - IAnswerState.value || - dialogSrc.value - ) - document.body.style.overflow = "hidden"; - else document.body.style.overflow = "auto"; - }); - }); + if (questionsSetp.value || myType.value || IAnswerEditState.value || IAnswerState.value || dialogSrc.value) document.body.style.overflow = "hidden" + else document.body.style.overflow = "auto" + }) + }) - let recommendList = []; // 推荐相关的数据 - let recommendPage = 1; + let recommendList = [] // 推荐相关的数据 + let recommendPage = 1 // 获取推荐数据 - const getRecommend = (uniqid) => { + const getRecommend = uniqid => { $ajaxGET("/api/details/relatedlist", { page: recommendPage, limit: 20, - }).then((res) => { - if (res.code != 200) return; + }).then(res => { + if (res.code != 200) return let obj = { offer: "Offer", mj: "面经", vote: "投票", thread: "帖子", - }; + } - let data = res.data; + let data = res.data // 替换 类名 - data.forEach((element) => { - element["typename"] = obj[element["type"]]; - element["isrecom"] = true; - }); - recommendList = recommendList.concat(data); - recommendPage++; - handleInsertRelatedlist(uniqid); - }); - }; + data.forEach(element => { + element["typename"] = obj[element["type"]] + element["isrecom"] = true + }) + recommendList = recommendList.concat(data) + recommendPage++ + handleInsertRelatedlist(uniqid) + }) + } // 处理插入推荐数据 - const handleInsertRelatedlist = (uniqid) => { - if (myModelState.value) return; + const handleInsertRelatedlist = uniqid => { + if (myModelState.value) return // 计算需要插入元素的数量 - let insertCount = Math.ceil(backupsList.length / 5); + let insertCount = Math.ceil(backupsList.length / 5) // 检查数组B的长度是否足够 if (recommendList.length < insertCount) { - getRecommend(uniqid); - return; + getRecommend(uniqid) + return } - let target = JSON.parse(JSON.stringify(backupsList)); - let result = []; + let target = JSON.parse(JSON.stringify(backupsList)) + let result = [] - let j = 0; + let j = 0 for (let i = 0; i < target.length; i++) { - result.push(target[i]); + result.push(target[i]) if ((i + 1) % 4 === 0 && j < recommendList.length) { - result.push(recommendList[j]); - j++; + result.push(recommendList[j]) + j++ } } - list.value = JSON.parse(JSON.stringify(result)); + list.value = JSON.parse(JSON.stringify(result)) // 加入 推荐阅读后 重新计算下标 和 滚动 nextTick(() => { if (uniqid) { result.forEach((element, index) => { if (element["uniqid"] == uniqid) { - pitchIndex.value = index; - scrollLeftInMiddle(); + pitchIndex.value = index + scrollLeftInMiddle() } - }); + }) } - }); - }; + }) + } const replaceNumberObj = { 0: "①", 1: "②", 2: "③", - }; + } - let seo = ref({}); + let seo = ref({}) let initState = ref(0) let arrr = [] @@ -2619,40 +2533,40 @@ export default { // 这是一个 等待的方法 如果复制后 会 多次等待 // await new Promise(resolve => setTimeout(resolve, 2000)) - const params = route.query; - if (params["keyword"]) keyword.value = params["keyword"]; - if (params["tid"]) typePitch.value = params["tid"]; + const params = route.query + if (params["keyword"]) keyword.value = params["keyword"] + if (params["tid"]) typePitch.value = params["tid"] if (process.server && params["uniqid"]) { await axios .post(baseURL + "/api/details", { uniqid: params["uniqid"] }) - .then((response) => { - let res = response.data; - let data = res.data; + .then(response => { + let res = response.data + let data = res.data - data["info"]['uniqid'] = params["uniqid"] - detailsInfoDataVuex.value = data; - detailsInfo.value = data["info"] || {}; - detailsIsanswered.value = data["isanswered"] || 0; - detailsIscollection.value = data["iscollection"] || 0; - detailsIsmyself.value = data["ismyself"] || 0; - detailsToken = data["token"] || ""; - detailShare.value = data["share"] || {}; + data["info"]["uniqid"] = params["uniqid"] + detailsInfoDataVuex.value = data + detailsInfo.value = data["info"] || {} + detailsIsanswered.value = data["isanswered"] || 0 + detailsIscollection.value = data["iscollection"] || 0 + detailsIsmyself.value = data["ismyself"] || 0 + detailsToken = data["token"] || "" + detailShare.value = data["share"] || {} - type.value = "details"; + type.value = "details" // calculateListIndex(data.info, params["uniqid"]); - answerList.value = []; - answerPage.value = 1; - getAnswerList(); + answerList.value = [] + answerPage.value = 1 + getAnswerList() - closeAllTransmitState(); + closeAllTransmitState() - replaceState({ uniqid: params["uniqid"] }); - seo.value = data.seo; + replaceState({ uniqid: params["uniqid"] }) + seo.value = data.seo // handleInsertRelatedlist(params["uniqid"]); }) - .catch((error) => console.error(error)); + .catch(error => console.error(error)) // if (process.server) { // await $ajax("/api/details", {uniqid: params["uniqid"]}) @@ -2691,147 +2605,140 @@ export default { limit: 20, keyword: keyword.value, type: typePitch.value, - }).then((res) => { - if (res.code != 200) return; - let data = res.data; + }).then(res => { + if (res.code != 200) return + let data = res.data data.data.forEach(element => { - element['content'] = element['content'].replace(/<[^>]*>/g, ""); - element['content'] = element['content'].replace(/ /g, ''); - + element["content"] = element["content"].replace(/<[^>]*>/g, "") + element["content"] = element["content"].replace(/ /g, "") }) list.value = data.data backupsList = data.data - total.value = data.count || 0; + total.value = data.count || 0 - keywordText.value = keyword.value || ""; + keywordText.value = keyword.value || "" - if (list.value.length != data["count"]) page++; - else page = 0; + if (list.value.length != data["count"]) page++ + else page = 0 - if (page == 0 && list.value.length != 0) inTheEndState.value = true; - else inTheEndState.value = false; + if (page == 0 && list.value.length != 0) inTheEndState.value = true + else inTheEndState.value = false - if (list.value.length == 0) isListEmptyState.value = true; - else isListEmptyState.value = false; - - if (keyword.value) isSearchMode.value = true; - else isSearchMode.value = false; + if (list.value.length == 0) isListEmptyState.value = true + else isListEmptyState.value = false + if (keyword.value) isSearchMode.value = true + else isSearchMode.value = false nextTick(() => { if (list.value.length == 0) type.value = "list" - }) // if (!process.server && params["uniqid"]) handleInsertRelatedlist() - }); + }) - await $ajaxGET("/api/details/relatedlist", { page: 1, limit: 20 }).then((res) => { - if (res.code != 200) return; + await $ajaxGET("/api/details/relatedlist", { page: 1, limit: 20 }).then(res => { + if (res.code != 200) return let obj = { offer: "Offer", mj: "面经", vote: "投票", thread: "帖子", - }; + } - let data = res.data; + let data = res.data // // 替换 类名 - data.forEach((element) => { - element["typename"] = obj[element["type"]]; - element["isrecom"] = true; - }); + data.forEach(element => { + element["typename"] = obj[element["type"]] + element["isrecom"] = true + }) - recommendList = recommendList.concat(data); - recommendPage++; + recommendList = recommendList.concat(data) + recommendPage++ if (params["uniqid"]) { - let target = JSON.parse(JSON.stringify(backupsList)); - let result = []; - let j = 0; + let target = JSON.parse(JSON.stringify(backupsList)) + let result = [] + let j = 0 for (let i = 0; i < target.length; i++) { - result.push(target[i]); + result.push(target[i]) if ((i + 1) % 4 === 0 && j < recommendList.length) { - result.push(recommendList[j]); - j++; + result.push(recommendList[j]) + j++ } } - list.value = JSON.parse(JSON.stringify(result)); + list.value = JSON.parse(JSON.stringify(result)) initState.value++ } - }); - - + }) } catch (error) { - console.error(error); + console.error(error) } - // 这个是监听 初始化的 推荐接口 和 onmount 都运行完成后 滚动 item ,不让冲突 watch(initState, (newValue, oldValue) => { if (newValue === 2) { - const params = route.query; - calculateListIndex(detailsInfo.value, params["uniqid"]); + const params = route.query + calculateListIndex(detailsInfo.value, params["uniqid"]) } }) - const setItemUrl = (uniqid) => { - let url = `./index.html?uniqid=${uniqid}`; - let query = route.query; + const setItemUrl = uniqid => { + let url = `./index.html?uniqid=${uniqid}` + let query = route.query for (const key in query) { - if (key != "uniqid") url += `&${key}=${query[key]}`; + if (key != "uniqid") url += `&${key}=${query[key]}` } - return url; - }; + return url + } // 处理点击 logo const handleLogo = () => { - window.location.href = window.location.origin + window.location.pathname; - }; - + window.location.href = window.location.origin + window.location.pathname + } // 您的答案 let yourAnswer = ref({ text: "", anonymous: 0, - }); + }) // 切换您的答案 匿名状态 const cutYourAnswerAnonymous = () => { - yourAnswer.value["anonymous"] = yourAnswer.value["anonymous"] ? 0 : 1; - }; + yourAnswer.value["anonymous"] = yourAnswer.value["anonymous"] ? 0 : 1 + } // 处理 您的答案的点击提交 const handleYourAnswer = () => { if (isNeedLogin.value) { - goLogin(); - return; + goLogin() + return } - IAnswerInfo.value = { ...yourAnswer.value }; - submitAnswer("you"); + IAnswerInfo.value = { ...yourAnswer.value } + submitAnswer("you") yourAnswer.value = { text: "", anonymous: 0, - }; - }; + } + } - let isDirectlyListIAnswer = false; // 是否是直接打开列表的我来回答 + let isDirectlyListIAnswer = false // 是否是直接打开列表的我来回答 // 专门处理列表状态的 我来回答 - const openListIAnswer = (index) => { + const openListIAnswer = index => { if (isNeedLogin.value) { - goLogin(); - return; + goLogin() + return } - let targetData = list.value[index]; + let targetData = list.value[index] IAnswerInfo.value = { title: targetData["title"], content: targetData["content"], @@ -2839,85 +2746,70 @@ export default { uniqid: targetData["uniqid"], anonymous: 0, index, - }; - isDirectlyListIAnswer = true; - IAnswerState.value = true; - nextTick(() => handleInput()); - }; + } + isDirectlyListIAnswer = true + IAnswerState.value = true + nextTick(() => handleInput()) + } // 头像框的状态 - let avatarState = ref(false); + let avatarState = ref(false) // 开启头像框 const openUserInfo = (index, ind, i) => { if (i != null) { - if (answerList.value[index].commentList[ind]["child"][i]["uin"] > 0) - answerList.value[index].commentList[ind]["child"][i]["avatarState"] = - !answerList.value[index].commentList[ind]["child"][i][ - "avatarState" - ]; + if (answerList.value[index].commentList[ind]["child"][i]["uin"] > 0) answerList.value[index].commentList[ind]["child"][i]["avatarState"] = !answerList.value[index].commentList[ind]["child"][i]["avatarState"] } else if (ind != null) { - if (answerList.value[index].commentList[ind]["uin"] > 0) - answerList.value[index].commentList[ind]["avatarState"] = - !answerList.value[index].commentList[ind]["avatarState"]; + if (answerList.value[index].commentList[ind]["uin"] > 0) answerList.value[index].commentList[ind]["avatarState"] = !answerList.value[index].commentList[ind]["avatarState"] } else if (index != null) { - if (answerList.value[index]["uin"] > 0) - answerList.value[index]["avatarState"] = - !answerList.value[index]["avatarState"]; + if (answerList.value[index]["uin"] > 0) answerList.value[index]["avatarState"] = !answerList.value[index]["avatarState"] } else { - if (detailsInfo.value["uin"] > 0) - avatarState.value = !avatarState.value; + if (detailsInfo.value["uin"] > 0) avatarState.value = !avatarState.value } - }; + } // 点击发送信息 - const sendMessage = (uin) => { - redirectToExternalWebsite( - `https://bbs.gter.net/home.php?mod=space&showmsg=1&uid=${uin}` - ); - }; + const sendMessage = uin => { + redirectToExternalWebsite(`https://bbs.gter.net/home.php?mod=space&showmsg=1&uid=${uin}`) + } // 点击ta的主页 - const TAHomePage = (uin) => { - redirectToExternalWebsite( - `https://bbs.gter.net/home.php?mod=space&uid=${uin}` - ); - }; + const TAHomePage = uin => { + redirectToExternalWebsite(`https://bbs.gter.net/home.php?mod=space&uid=${uin}`) + } // 跳转 url - const redirectToExternalWebsite = (url) => { - const link = document.createElement("a"); - link.href = url; - link.target = "_blank"; - link.click(); - }; + const redirectToExternalWebsite = url => { + const link = document.createElement("a") + link.href = url + link.target = "_blank" + link.click() + } // 详情模式下关闭底部 const closeBottom = () => { - if (process.server) return; + if (process.server) return - const footer = document.querySelector("body .index-footer"); - if (footer) footer.style.display = "none"; - else setTimeout(() => closeBottom(), 1000); - }; + const footer = document.querySelector("body .index-footer") + if (footer) footer.style.display = "none" + else setTimeout(() => closeBottom(), 1000) + } const openBottom = () => { - const footer = document.querySelector("body .index-footer"); - if (footer) footer.style.display = "block"; - else setTimeout(() => openBottom(), 1000); - }; + const footer = document.querySelector("body .index-footer") + if (footer) footer.style.display = "block" + else setTimeout(() => openBottom(), 1000) + } // 处理点击 只看 const handleLookOnly = () => { - zeroreply.value = (zeroreply.value == 0 ? 1 : 0) - page = 1; + zeroreply.value = zeroreply.value == 0 ? 1 : 0 + page = 1 list.value = [] - backupsList = []; + backupsList = [] listHeight.value = 0 - getList(); + getList() } - - return { handleLookOnly, zeroreply, @@ -3048,9 +2940,9 @@ export default { handleAnswerText, getCurrentUrl, loading, - }; + } }, -}; +} </script> <style>