no message

This commit is contained in:
A1300399510
2023-11-29 12:28:01 +08:00
parent 59acdf68dd
commit c27e4a5420
643 changed files with 75279 additions and 243 deletions

9
js/axios.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -1,3 +1,8 @@
// 提交问题
// 切换头部分类
// 转发的链接和title
// 图片上传有一些错误
Object.assign(window, Vue)
const forumApp = Vue.createApp({
setup() {
@@ -6,31 +11,53 @@ const forumApp = Vue.createApp({
let type = ref('list') // list details
onMounted(() => {
getUrlParams()
getUserData()
getList()
getListClass()
window.addEventListener('scroll', handleScroll);
getHistoricalSearchList()
})
onUnmounted(() => {
window.removeEventListener('scroll', handleScroll);
});
let initParams = {}
// 获取url的参数
const getUrlParams = () => {
const params = {};
const regex = /[?&]([^=#]+)=([^&#]*)/g;
let match;
while ((match = regex.exec(window.location.href))) {
params[match[1]] = decodeURIComponent(match[2]);
}
initParams = params
if (params['uniqid']) getDetails(params['uniqid'])
}
// 获取当前url
const getCurrentUrl = () => {
return window.location.href;
}
// 我的 数据 数量
let myCount = ref({}) //
// 获取用户数据
const getUserData = () => {
$ajax("/api/user").then(res => {
console.log("res", res);
if (res.code != 200) return
let data = res.data
console.log(data, "data");
myCount.value = data.count
})
}
@@ -62,7 +89,8 @@ const forumApp = Vue.createApp({
list.value = []
type.value = 'list'
pitchIndex.value = null
replaceState({ keyword: keyword.value })
searchBlur()
getList()
}
@@ -75,7 +103,7 @@ const forumApp = Vue.createApp({
// 搜索失去焦点
const searchBlur = () => {
setTimeout(() => historicalSearchState.value = false, 100)
setTimeout(() => historicalSearchState.value = false, 300)
}
// 点击历史记录 item
@@ -93,6 +121,8 @@ const forumApp = Vue.createApp({
pitchIndex.value = null
getList()
replaceState()
}
let historicalSearchState = ref(false) // 历史记录弹窗状态
@@ -114,6 +144,7 @@ const forumApp = Vue.createApp({
}
let keyword = ref('') // 搜索的值
let keywordText = ref('') // 搜索的文本
let list = ref([]) // 列表数据
let page = 1
@@ -125,13 +156,12 @@ const forumApp = Vue.createApp({
if (page == 0 || loading) return
loading = true
$ajax("/api/lists",
{
page,
limit: 20,
keyword: keyword.value,
// type: 'all',
}
$ajax("/api/lists", {
page,
limit: 20,
keyword: keyword.value,
type: typePitch.value,
}
).then(res => {
if (res.code != 200) return
@@ -140,8 +170,9 @@ const forumApp = Vue.createApp({
list.value = list.value.concat(data.data || [])
total.value = data.count || 0
if (list.value.length != data['count']) page++
else page = 0
keywordText.value = keyword.value || ''
page++
if (keyword.value) isSearchMode.value = true
else isSearchMode.value = false
@@ -151,35 +182,16 @@ const forumApp = Vue.createApp({
}
let typeList = ref([])
let typePitch = ref('')
let typePitch = ref(null)
// 获取分类数据 列表分类
const getListClass = () => {
$ajax("/api/common/typeList").then(res => {
if (res.code != 200) return
let data = res.data
console.log(data, "data");
data = [{
id: "all",
name: "All",
}, {
id: "all2",
name: "All",
}, {
id: "all3",
name: "All",
}, {
id: "all4",
name: "All",
}, {
id: "all5",
name: "All",
}, {
id: "all6",
name: "All",
}]
typeList.value = data
typePitch.value = data[0].id
console.log("data", data);
getPageHeight()
})
@@ -203,14 +215,12 @@ const forumApp = Vue.createApp({
let detailShare = ref({}) // 详情信息
// 获取详情
const getDetails = (uniqid, index) => {
uniqid = "fubm5CnD05qj" // 标记一下
const getDetails = (uniqid, index, isOpenAnswer) => {
// uniqid = "fubm5CnD05qj" // 标记一下
$ajax("/api/details", { uniqid }).then(res => {
if (res.code != 200) return
let data = res.data
console.log("data", data);
detailsInfo.value = data['info'] || {}
detailsIsanswered.value = data['isanswered'] || 0
detailsIscollection.value = data['iscollection'] || 0
@@ -220,25 +230,68 @@ const forumApp = Vue.createApp({
type.value = 'details'
cut(index)
if (index !== null && index !== undefined) cut(index)
else {
let targetList = [...list.value]
let valve = false
targetList.forEach((element, index) => {
if (element['uniqid'] == uniqid) {
cut(index)
valve = true
}
})
if (!valve) {
list.value.unshift({
answers: data.info['answers'],
content: data.info['content'],
publicationdate: data.info['publicationdate'],
title: data.info['title'],
uniqid,
})
cut(0)
}
}
answerList.value = []
answerPage.value = 1
getAnswerList()
closeAllTransmitState()
if (isOpenAnswer) openIAnswer()
replaceState({ uniqid })
})
}
let answerList = ref([]) // 回答列表数据
let answerPage = ref(1) // 回答列表页数
let answerLoading = false // 回答列表加载
// 获取详情的回答数据
const getAnswerList = () => {
$ajax("/api/details/answerList", { token: detailsToken }).then(res => {
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'] = []
})
// commentList
answerList.value = data.data
})
answerList.value = answerList.value.concat(data.data)
if (answerList.value.length == data['count']) answerPage.value = 0
else answerPage.value++
}).finally(() => answerLoading = false)
}
// 操作 - 点赞
@@ -248,6 +301,7 @@ const forumApp = Vue.createApp({
let data = res.data
answerList.value[index]['islike'] = data['status']
answerList.value[index]['likenum'] = data['count']
handleMsg('success', res['message'] || '操作成功')
})
}
@@ -266,6 +320,12 @@ const forumApp = Vue.createApp({
answerList.value[index]['iscollection'] = data['status']
answerList.value[index]['collectionnum'] = data['count']
}
handleMsg('success', res['message'] || '操作成功')
if (data['status']) myCount.value['collect']++
else myCount.value['collect']--
})
}
@@ -314,6 +374,10 @@ const forumApp = Vue.createApp({
}
IAnswerEditState.value = true
nextTick(() => {
handleInput()
})
}
}
@@ -341,12 +405,13 @@ const forumApp = Vue.createApp({
anonymous: IAnswerInfo.value['anonymous'] || 0,
content: IAnswerInfo.value['text'],
}).then(res => {
console.log(res);
if (res.code == 200) {
getAnswerList()
closeIAnswer()
isNeedNewAnswersData = true
handleMsg('success', res['message'] || '操作成功')
if (!IAnswerInfo.value['token']) myCount.value['answer']++
} else {
}
@@ -385,6 +450,7 @@ const forumApp = Vue.createApp({
if (res.code != 200) return
let data = res.data
answerList.value[index]['commentList'] = answerList.value[index]['commentList'].concat(data.data.slice(3))
handleMsg('success', res['message'] || '操作成功')
})
}
@@ -394,6 +460,7 @@ const forumApp = Vue.createApp({
$ajax("/api/comment/lists", {
token: answerList.value[index]['token'],
limit: answerCommentLimit,
childlimit: 1,
}).then(res => {
if (res.code != 200) return
resolve(res)
@@ -424,7 +491,6 @@ const forumApp = Vue.createApp({
token,
parentid,
}).then(res => {
console.log("res", res);
if (res.code != 200) return
let data = res.data
@@ -469,6 +535,7 @@ const forumApp = Vue.createApp({
closeAnswerCommentsChild()
console.log("targetAnswerList", targetAnswerList);
handleMsg('success', res['message'] || '操作成功')
})
}
@@ -477,23 +544,22 @@ const forumApp = Vue.createApp({
$ajax("/api/comment/like", {
token,
}).then(res => {
console.log("res", res);
if (res.code != 200) return
let data = res.data
console.log("data", data);
const targetAnswerList = [...answerList.value]
if (i == null) {
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']
}
answerList.value = targetAnswerList
handleMsg('success', res['message'] || '操作成功')
})
}
@@ -542,6 +608,7 @@ const forumApp = Vue.createApp({
parentid,
limit: 20,
page: 1,
childlimit: 1,
}).then(res => {
console.log("res", res);
if (res.code != 200) return
@@ -568,10 +635,12 @@ const forumApp = Vue.createApp({
getMyAnswer()
return
} else if (key == 'questions') {
myQuestionsList.value = []
myQuestionsPage = 1
getMyQuestions()
return
}
myType.value = key
// myType.value = key
}
let myCollectionList = ref([]) // 我的收藏列表
@@ -591,9 +660,9 @@ const forumApp = Vue.createApp({
myCollectionList.value = myCollectionList.value.concat(data.data)
myCollectionCount.value = data.count
if (myCollectionList.value.length != data['count']) myCollectionPage++
else myCollectionPage = 0
})
}
@@ -603,6 +672,8 @@ const forumApp = Vue.createApp({
if (res.code == 200) {
myCollectionList.value.splice(index, 1)
myCollectionCount.value--
myCount.value['collect']--
handleMsg('success', res['message'] || '操作成功')
}
})
}
@@ -639,13 +710,13 @@ const forumApp = Vue.createApp({
if (myAnswerList.value.length != data['count']) myAnswerPage++
else myAnswerPage = 0
console.log("myAnswerList", myAnswerList.value);
myType.value = 'answers'
isNeedNewAnswersData = false
})
}
// 我的回答 的滚动到底部事件
const handleAnswersScroll = e => {
const el = e.target;
// 判断滚动到底部
@@ -675,22 +746,67 @@ const forumApp = Vue.createApp({
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 // 我的提问页数
// 获取我的提问
const getMyQuestions = () => {
$ajax("/api/user/questions").then(res => {
if (myQuestionsPage == 0) return
$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'
if (myQuestionsList.value.length != data['count']) myQuestionsPage++
else myQuestionsPage = 0
})
}
// 我的提问 的滚动到底部 事件
const handleQuestionsScroll = e => {
const el = e.target;
// 判断滚动到底部
if (el.scrollHeight - el.scrollTop !== el.clientHeight) return
getMyQuestions()
}
let questionsIndexOld = null
// 切换 我的提问的公开匿名 弹窗状态
const cutQuestionsPopupState = index => {
myQuestionsList.value[index]['popupState'] = true
if (questionsIndexOld == index) {
myQuestionsList.value[index]['popupState'] = false
questionsIndexOld = null
} else {
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
let data = res.data
myQuestionsList.value[index]['anonymous'] = anonymous
cutQuestionsPopupState(index)
handleMsg('success', res['message'] || '操作成功')
})
}
let questionsSetp = ref(0) // 提问的步骤
// 切换提问步骤
@@ -716,6 +832,7 @@ const forumApp = Vue.createApp({
questionsObj.value['token'] = data['token']
questionsTypeList.value = data['typeList'] || []
console.log("data['typeList']", data['typeList']);
cutQuestionsSetp(1)
})
}
@@ -733,15 +850,23 @@ const forumApp = Vue.createApp({
// 发布问题
const postingIssue = () => {
// 还没有分类
console.log("发布问题", questionsObj.value);
$ajax("/api/publish/questionsSubmit", questionsObj.value).then(res => {
console.log("res", res);
myCount.value['questions']++
if (res.code == 200) {
handleMsg('success', res['message'] || '操作成功')
}
handleMsg('error', res['message'] || '刷新重试!!!')
})
}
let pitchIndex = ref(null) // 选中的下标
// 切换 滚动列表
const cut = index => {
// if (pitchIndex.value == null) type.value = type.value == 'list' ? 'details' : 'list'
@@ -754,12 +879,10 @@ const forumApp = Vue.createApp({
// 滚动左边在中间
const scrollLeftInMiddle = () => {
// console.log(pitchIndex.value, "pitchIndex");
let list = document.querySelector(".list-box")
// console.log("list", list);
console.log(107 * pitchIndex.value, pageListHeight.value / 2);
list.scrollTo({
top: 128 * pitchIndex.value + 64 - 385,
// top: 128 * pitchIndex.value - pageListHeight.value / 2 - 385,
top: 128 * pitchIndex.value + 68 - pageListHeight.value / 2,
behavior: 'smooth'
})
}
@@ -783,7 +906,6 @@ const forumApp = Vue.createApp({
const itemStyle = (index, content) => {
const newtype = type.value
// pitchIndex
// let itemHeight = content == "" ? 106 : 128
let obj = {}
if (newtype == 'list') {
@@ -816,6 +938,7 @@ const forumApp = Vue.createApp({
return obj
}
const $ajax = (url, data) => {
url = url.indexOf('//') > -1 ? url : baseURL + url;
return new Promise(function (resolve, reject) {
@@ -824,15 +947,20 @@ const forumApp = Vue.createApp({
withCredentials: true,
headers: {
// authorization: "9l3vfdx6h5xhu2hbw4fv5ygbog1dhtly"
authorization: "194cdc367ed40c938f2eaaf1c6dfa5ff"
// authorization: "194cdc367ed40c938f2eaaf1c6dfa5ff"
authorization: "63c9bef150557f9c90e93f98d2e2497e"
}
}).then(function (res) {
var data = null
try {
data = typeof res.data == 'string' ? JSON.parse(res.data) : res.data;
if (data['code'] != 200) handleMsg('error', data['message'] || '报错了,请重试!!!')
} catch (error) { }
resolve(data)
});
}).catch(err => {
if (err.response.status == 401) window.location.href = 'https://passport.gter.net';
})
});
}
@@ -868,34 +996,50 @@ const forumApp = Vue.createApp({
return result;
}
// 问题的转发 弹窗状态
let questionsTransmitState = ref(false)
let questionsTransmitState = ref(false) // 问题的转发 弹窗状态
let questionsTransmitMaskState = ref(false) // 问题的转发 弹窗蒙版状态状态
// 关闭转发状态
const closeTransmitState = () => {
questionsTransmitState.value = true
questionsTransmitMaskState.value = true
countForwardingTimes(detailsToken)
}
// 关闭全部转发状态
const closeAllTransmitState = () => {
answerList.value.forEach(element => {
element['transmitState'] = false
})
questionsTransmitState.value = !questionsTransmitState.value
questionsTransmitState.value = false
questionsTransmitMaskState.value = false
}
// 开启和关闭回答的转发状态 type open close
const handleAnswerTransmitList = (Iindex, type) => {
// handleAnswerTransmitList
questionsTransmitState.value = false
answerList.value[Iindex]['transmitState'] = true
questionsTransmitMaskState.value = true
countForwardingTimes(answerList.value[Iindex]['token'])
}
answerList.value.forEach((element, index) => {
if (index != Iindex) element['transmitState'] = false
// 统计转发次数
const countForwardingTimes = (token) => {
console.log("token", token);
// return
$ajax("/api/operate/share", { token }).then(res => {
console.log("res", res);
})
answerList.value[Iindex]['transmitState'] = !answerList.value[Iindex]['transmitState']
}
// 关闭详情模式
const closeDetailMode = () => {
type.value = 'list'
pitchIndex.value = null
replaceState()
}
// 全部的启动到底部
const handleListScroll = (e) => {
const el = e.target;
// 判断滚动到底部
@@ -908,37 +1052,173 @@ const forumApp = Vue.createApp({
const handlePaste = (event) => {
const items = (event.clipboardData || event.originalEvent.clipboardData).items;
for (const item of items) {
console.log(item);
if (item.type.indexOf('image') === 0) {
const file = item.getAsFile();
const reader = new FileReader();
reader.onload = (e) => {
const img = new Image();
img.src = e.target.result;
const questionTextarea = document.querySelector(".question-textarea")
questionTextarea.appendChild(img);
handleInput()
// IAnswerInfo.value['text'] = questionTextarea.innerHTML
const base64 = e.target.result
// console.log("base64", base64);
uploadImg(base64).then(res => {
const questionTextarea = document.querySelector(".question-textarea")
const imgElements = questionTextarea.querySelectorAll("img");
// console.log("imgElements1111", imgElements);
if (imgElements.length == 0) {
questionTextarea.innerHTML += `<img 1 src="${res.url}" data-aid="${res.aid}" />`
handleInput()
} else {
imgElements.forEach(img => {
// console.log("src", img.getAttribute("src"));
// if (img.getAttribute("src") == base64) {
if (img.getAttribute("data-aid") == null && img.getAttribute('data-custom') == null) {
img.setAttribute("src", res.url);
img.setAttribute("data-aid", res.aid);
}
});
}
})
};
reader.readAsDataURL(file);
}
}
}
// 上传图片 获取图片url
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)
})
})
}
// 回答 的 placeholder 状态
let questionPlaceholderState = ref(false)
// 回答的输入事件 判断是否显示 placeholder 用
const handleInput = (event) => {
// IAnswerInfo.value['text'] = event.target.innerHTML;
const questionTextarea = document.querySelector(".question-textarea")
const html = questionTextarea.innerHTML
if (html) questionPlaceholderState.value = false
else questionPlaceholderState.value = true
console.log("questionPlaceholderState", questionPlaceholderState);
}
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
}
// 修改提示框类型
const boxClass = () => {
msgShowTimer()
return type ? `box-item-${msg.value['type']}` : ''
}
let msgTimer = null
const msgShowTimer = () => {
clearTimeout(msgTimer)
msgTimer = setTimeout(() => {
msg.value['state'] = false
}, 1000)
}
// 复制
let copyText = text => {
if (navigator.clipboard) {
copyText = () => {
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', '复制成功')
}
}
copyText()
}
// 修改 url
const replaceState = (obj = {}) => {
// 获取当前URL参数
let params = new URLSearchParams(window.location.search);
// 循环删除所有参数
for (let key of params.keys()) {
params.delete(key);
}
// 修改URL参数
// params.set('paramName', 'paramValue');
for (const key in obj) {
params.set(key, obj[key]);
}
// 替换当前URL但不刷新页面
window.history.replaceState({}, '', `${window.location.pathname}?${params}`);
}
// 我的打开 详情
const myOpenDetails = (value) => {
getDetails(value['uniqid'])
myType.value = ""
}
// 详情页滚动事件
const handleDetailsScroll = e => {
// console.log("e", e);
const el = e.target;
// 判断滚动到底部
if (el.scrollHeight - el.scrollTop !== el.clientHeight) return
// console.log("底部");
getAnswerList()
}
let dialogSrc = ref("") // 大图的src
// 处理点击答案图片 展开大图
const handleAnswerText = e => {
if (e.target.tagName === 'IMG') {
var src = e.target.getAttribute('src');
dialogSrc.value = src
}
}
// 切换顶部的 type
const cutType = (id) => {
typePitch.value = id
page = 1
list.value = []
type.value = 'list'
getList()
}
return {
cutType,
dialogSrc,
answerPage,
handleDetailsScroll,
replaceState,
copyText,
boxClass,
questionPlaceholderState,
handleInput,
handlePaste,
@@ -951,6 +1231,7 @@ const forumApp = Vue.createApp({
cut,
list,
keyword,
keywordText,
getList,
total,
typeList,
@@ -989,20 +1270,25 @@ const forumApp = Vue.createApp({
handleDate,
handleCollectionScroll,
handleAnswersScroll,
handleQuestionsScroll,
cancelCollection,
getMyCollection,
questionsSetp,
questionsObj,
cutAnonymous,
cutQuestionsSetp,
cutQuestionsPopupState,
questionsTypeList,
postingIssue,
choosingTheme,
handleMy,
changeAnonymous,
changeAnonymousQuestions,
pageHeaderHeight,
pageListHeight,
questionsTransmitState,
questionsTransmitMaskState,
closeAllTransmitState,
closeTransmitState,
handleAnswerTransmitList,
closeDetailMode,
@@ -1017,9 +1303,15 @@ const forumApp = Vue.createApp({
handleClickClear,
isSearchMode,
questionsInit,
myCount,
msg,
myOpenDetails,
handleAnswerText,
getCurrentUrl
};
}
})
forumApp.mount("#answer-app"); //初始化

12014
js/vue.js Normal file

File diff suppressed because it is too large Load Diff

15929
js/vue@3.2.36.js Normal file

File diff suppressed because it is too large Load Diff