提交 b6fcc3d5 编写于 作者: yma16's avatar yma16

fix:聊天室配置

上级 86b35688
...@@ -16,11 +16,11 @@ module.exports = { ...@@ -16,11 +16,11 @@ module.exports = {
changeOrigin: true, //是否允许跨越 changeOrigin: true, //是否允许跨越
chunkOrigins: true, chunkOrigins: true,
pathRewrite: { pathRewrite: {
"^/api": "", //重写, "^/api": "api", //重写,
}, },
}, },
"/ws_api/": { "/ws_api/": {
target: "http://yongma16.xyz/", target: "ws://yongma16.xyz/ws/webchat/",
ws: true, //接受websocket请求 ws: true, //接受websocket请求
changeOrigin: true, //是否允许跨越 changeOrigin: true, //是否允许跨越
chunkOrigins: true, chunkOrigins: true,
......
...@@ -152,12 +152,14 @@ export default { ...@@ -152,12 +152,14 @@ export default {
"https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg", "https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg",
], ],
headerData: ["从现在开始,种一棵树", "从现在开始,种一棵树"], headerData: ["从现在开始,种一棵树", "从现在开始,种一棵树"],
readCount: 0 readCount: 0,
}; };
}, },
computed: { computed: {
currentUserName: function () { currentUserName: function () {
return store.state.user.userInfo.name; return store.state.user.userInfo && store.state.user.userInfo.name
? store.state.user.userInfo.name
: "游客";
}, },
}, },
mounted() { mounted() {
......
...@@ -58,6 +58,7 @@ export default { ...@@ -58,6 +58,7 @@ export default {
watch: { watch: {
articleId: function (newData) { articleId: function (newData) {
this.childArticleId = newData; this.childArticleId = newData;
return newData
}, },
}, },
mounted() { mounted() {
......
...@@ -210,40 +210,40 @@ ...@@ -210,40 +210,40 @@
</template> </template>
<script> <script>
import VueMarkdown from "vue-markdown"; import VueMarkdown from 'vue-markdown'
import ArticleComment from "@/comment/ArticleComment"; import ArticleComment from '@/comment/ArticleComment'
import EchartWeather from "@/weather/EchartWeather"; import EchartWeather from '@/weather/EchartWeather'
import axios from "axios"; import axios from 'axios'
export default { export default {
components: { components: {
VueMarkdown, //显示markdown的组件 VueMarkdown, // 显示markdown的组件
ArticleComment, //子组件评论 ArticleComment, // 子组件评论
EchartWeather, //天气 EchartWeather // 天气
}, },
name: "Article", name: 'Article',
data() { data () {
return { return {
// baseurl: '/api/', // baseurl: '/api/',
baseurl: "/api/", baseurl: '/api/',
// baseurl: "http://yongma16.xyz/", // baseurl: "http://yongma16.xyz/",
msg: "内容", msg: '内容',
commmentSlogan: "评论区", commmentSlogan: '评论区',
day_challenge: "训练营", day_challenge: '训练营',
challenge_data: [ challenge_data: [
"css挑战", 'css挑战',
"websocket聊天", 'websocket聊天',
"echarts地图配置", 'echarts地图配置',
"vue3测试平台", 'vue3测试平台',
"更新中", '更新中'
], ],
md_data: [], md_data: [],
md_title: [], md_title: [],
the_title: "", the_title: '',
sear_page: 0, sear_page: 0,
index_page: 0, index_page: 0,
data: ["threejs加载模型"], data: ['threejs加载模型'],
slogan: "记忆碎片", slogan: '记忆碎片',
tabPosition: "left", tabPosition: 'left',
weather_title: [], weather_title: [],
weather_high: [], weather_high: [],
weather_low: [], weather_low: [],
...@@ -251,231 +251,237 @@ export default { ...@@ -251,231 +251,237 @@ export default {
article_loc: 0, article_loc: 0,
challenge_loc: -1, challenge_loc: -1,
topshow: false, topshow: false,
userImg: "", userImg: '',
username: "匿名", username: '匿名',
articleCommit: "评论区", articleCommit: '评论区',
// 分页实现 page1 page2 指向数组 // 分页实现 page1 page2 指向数组
pageAnalys: {}, pageAnalys: {},
currentPage: 1, currentPage: 1,
splitLength: 6, //划分条数 splitLength: 6, // 划分条数
total: 0, total: 0,
pageSize: 4, pageSize: 4,
pageArray: [6, 8, 10], pageArray: [6, 8, 10],
postcomment: { postcomment: {
articleId: undefined, articleId: undefined,
articleCommit: null, articleCommit: null
}, },
articleId: [], //文章的id articleId: [] // 文章的id
}; }
}, },
watch: { watch: {
topshow: function (newvalue, oldvalue) { topshow: function (newvalue, oldvalue) {
if (newvalue === true) { if (newvalue === true) {
document.getElementById("topiconid").style.display = "none"; document.getElementById('topiconid').style.display = 'none'
} else { } else {
document.getElementById("topiconid").style.display = "block"; document.getElementById('topiconid').style.display = 'block'
} }
}, }
}, },
beforeDestroy() { beforeDestroy () {
window.removeEventListener("onload", this.topvisible()); window.removeEventListener('onload', this.topvisible())
}, },
mounted() { mounted () {
this.initPageSpliteFun(); this.initPageSpliteFun()
window.addEventListener("onload", this.topvisible()); window.addEventListener('onload', this.topvisible())
}, },
methods: { methods: {
initPageSpliteFun() { initPageSpliteFun () {
this.splitLength = this.pageArray[0]; this.splitLength = this.pageArray[0]
}, },
handleSizeChange(val) { handleSizeChange (val) {
// 转到第一页md_title // 转到第一页md_title
let that = this; let that = this
that.pageAnalysFun(that.pageAnalys.allTitle, val); //触发修改 that.pageAnalysFun(that.pageAnalys.allTitle, val) // 触发修改
}, },
handleCurrentChange(val) { handleCurrentChange (val) {
let that = this; let that = this
//触发md_title的修改 // 触发md_title的修改
that.currentPage = val; that.currentPage = val
that.pageAnalysFun(that.pageAnalys.allTitle); //触发修改 that.pageAnalysFun(that.pageAnalys.allTitle) // 触发修改
}, },
pageAnalysFun(allTitleArray, selectListLength) { pageAnalysFun (allTitleArray, selectListLength) {
let that = this; let that = this
that.total = allTitleArray.length; //总数 that.total = allTitleArray.length // 总数
let splitLength = that.splitLength; let splitLength = that.splitLength
if (!selectListLength) { if (!selectListLength) {
that.splitLength = that.splitLength; that.splitLength = that.splitLength
} else { } else {
this.currentPage = 1; this.currentPage = 1
that.splitLength = selectListLength; //划分长度 that.splitLength = selectListLength // 划分长度
} }
splitLength = that.splitLength; splitLength = that.splitLength
let splitNum = Math.ceil(that.total / splitLength); //向上取整 let splitNum = Math.ceil(that.total / splitLength) // 向上取整
that.pageAnalys.childNum = splitNum; //子数组个数 that.pageAnalys.childNum = splitNum // 子数组个数
that.pageAnalys.allTitle = allTitleArray; //所有标题 that.pageAnalys.allTitle = allTitleArray // 所有标题
that.pageAnalys.titleArray = new Array(); //子数组个数 that.pageAnalys.titleArray = new Array() // 子数组个数
var locSplit = 0; let locSplit = 0
var locLength = splitLength; //每一页的条数 let locLength = splitLength // 每一页的条数
while (splitNum--) { while (splitNum--) {
// 循环获取子数组 // 循环获取子数组
if (splitNum >= 1) { if (splitNum >= 1) {
let childArray = []; let childArray = []
for ( for (
let temp = locSplit; let temp = locSplit;
temp < locLength && temp < that.total; temp < locLength && temp < that.total;
++temp, ++locSplit ++temp, ++locSplit
) { ) {
childArray.push(that.pageAnalys.allTitle[temp]); childArray.push(that.pageAnalys.allTitle[temp])
} }
that.pageAnalys.titleArray.push(childArray); that.pageAnalys.titleArray.push(childArray)
locLength += splitLength; //分割数组长度后移 locLength += splitLength // 分割数组长度后移
} else { } else {
// 最后一个数组 // 最后一个数组
let childArray = []; let childArray = []
for (let temp = locSplit; temp < that.total; ++temp) { for (let temp = locSplit; temp < that.total; ++temp) {
childArray.push(that.pageAnalys.allTitle[temp]); childArray.push(that.pageAnalys.allTitle[temp])
} }
that.pageAnalys.titleArray.push(childArray); that.pageAnalys.titleArray.push(childArray)
break; break
} }
} }
try { try {
that.md_title = that.pageAnalys.titleArray[this.currentPage - 1]; that.md_title = that.pageAnalys.titleArray[this.currentPage - 1]
} catch (e) { } catch (e) {
throw Error(e); throw Error(e)
} }
}, },
increment: function () { increment: function () {
this.$store.commit("increment"); this.$store.commit('increment')
}, },
topvisible: function () { topvisible: function () {
let dom = document.getElementById("hometitle"); let dom = document.getElementById('hometitle')
this.topshow = this.elementIsVisibleInViewport(dom); this.topshow = this.elementIsVisibleInViewport(dom)
setTimeout(this.topvisible); setTimeout(this.topvisible)
}, },
elementIsVisibleInViewport: function (el, partiallyVisible = false) { elementIsVisibleInViewport: function (el, partiallyVisible = false) {
const { top, left, bottom, right } = el.getBoundingClientRect(); try {
const { top, left, bottom, right } = el.getBoundingClientRect()
return partiallyVisible return partiallyVisible
? ((top > 0 && top < innerHeight) || ? ((top > 0 && top < innerHeight) ||
(bottom > 0 && bottom < innerHeight)) && (bottom > 0 && bottom < innerHeight)) &&
((left > 0 && left < innerWidth) || ((left > 0 && left < innerWidth) ||
(right > 0 && right < innerWidth)) (right > 0 && right < innerWidth))
: top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth; : top >= 0 &&
left >= 0 &&
bottom <= innerHeight &&
right <= innerWidth
} catch (r) {
throw Error(r)
}
}, },
li_errorClass: function () {}, li_errorClass: function () {},
cssPage: function (index) { cssPage: function (index) {
this.challenge_loc = index; this.challenge_loc = index
let name = this.challenge_data[index]; let name = this.challenge_data[index]
switch (name) { switch (name) {
case "css挑战": case 'css挑战':
this.$router this.$router
.push({ .push({
path: "/css", path: '/css'
}) })
.catch((error) => { .catch((error) => {
throw Error(error); throw Error(error)
}); })
break; break
case "echarts地图配置": case 'echarts地图配置':
this.$router this.$router
.push({ .push({
path: "/home", path: '/home'
}) })
.catch((error) => { .catch((error) => {
throw Error(error); throw Error(error)
}); })
break; break
case "websocket聊天": case 'websocket聊天':
this.$router this.$router
.push({ .push({
path: "/onlinewebsocket", path: '/onlinewebsocket'
}) })
.catch((error) => { .catch((error) => {
throw Error(error); throw Error(error)
}); })
break; break
case "vue3测试平台": case 'vue3测试平台':
window.open("http://yongma16.xyz/emoji_api/"); window.open('http://yongma16.xyz/emoji_api/')
break; break
default: default:
break; break
} }
}, },
open_message: function () { open_message: function () {
this.$notify({ this.$notify({
title: "欢迎合作", title: '欢迎合作',
message: "邮箱:1432448610@qq.com", message: '邮箱:1432448610@qq.com',
position: "bottom-right", position: 'bottom-right'
}); })
}, },
toTop: function () { toTop: function () {
location.href = "#home"; // 定位 location.href = '#home' // 定位
document.getElementById("mainappid").scrollTop = 0; document.getElementById('mainappid').scrollTop = 0
}, // 返回天气相当于返回顶部 }, // 返回天气相当于返回顶部
getCommentsFromArticle(id) { getCommentsFromArticle (id) {
this.$refs.commentRef.getComments(id); //触发子组件的方法 this.$refs.commentRef.getComments(id) // 触发子组件的方法
}, },
getArticles: function (page) { getArticles: function (page) {
let that = this; // this指向转化 let that = this // this指向转化
that.article_loc = page; that.article_loc = page
// 查找文章id 从1开始 // 查找文章id 从1开始
that.postcomment.articleId = that.postcomment.articleId =
that.articleId[ that.articleId[
parseInt(page + (that.currentPage - 1) * that.splitLength) parseInt(page + (that.currentPage - 1) * that.splitLength)
]; ]
// 提交数据 page从0开始 // 提交数据 page从0开始
axios axios
.post(that.baseurl + "article/index/", { .post(that.baseurl + 'article/index/', {
value: page + (that.currentPage - 1) * that.splitLength, value: page + (that.currentPage - 1) * that.splitLength
// 传入索引 // 传入索引
}) })
.then((res) => { .then((res) => {
if (res.data.code === 1) { if (res.data.code === 1) {
let respdata = res.data; let respdata = res.data
let content = respdata.article; let content = respdata.article
that.md_data = []; // 清空 that.md_data = [] // 清空
content.map((o) => { content.map((o) => {
that.md_data.push(o); // 传入一个文章 that.md_data.push(o) // 传入一个文章
}); })
that.the_title = respdata.the_title; that.the_title = respdata.the_title
} else if (res.data.code === 0) { } else if (res.data.code === 0) {
// alter("失败!") // alter("失败!")
that.$message.error("失败"); that.$message.error('失败')
} }
}) })
.catch((error) => { .catch((error) => {
throw Error(error); throw Error(error)
}); })
that.getCommentsFromArticle(that.postcomment.articleId); that.getCommentsFromArticle(that.postcomment.articleId)
}, }
}, },
created: function () { created: function () {
// 初始化 // 初始化
let that = this; let that = this
axios axios
.get(that.baseurl + "article/index/") .get(that.baseurl + 'article/index/')
.then((res) => { .then((res) => {
let resdata = res.data; let resdata = res.data
let content = resdata.article; // 传递过来的文章 进行处理 let content = resdata.article // 传递过来的文章 进行处理
let title = resdata.title; let title = resdata.title
that.articleId = resdata.articleObjectId; that.articleId = resdata.articleObjectId
that.postcomment.articleId = resdata.articleId; that.postcomment.articleId = resdata.articleId
this.$refs.commentRef.getComments(that.postcomment.articleId); //触发子组件的方法 this.$refs.commentRef.getComments(that.postcomment.articleId) // 触发子组件的方法
content.map((o) => { content.map((o) => {
that.md_data.push(o); that.md_data.push(o)
}); })
let titleAllArray = title.map((o) => { let titleAllArray = title.map((o) => {
return o; return o
}); })
that.the_title = resdata.the_title; that.the_title = resdata.the_title
this.pageAnalysFun(titleAllArray); //分页 this.pageAnalysFun(titleAllArray) // 分页
}) })
.catch((r) => { .catch((r) => {
throw Error(r); throw Error(r)
}); // get log }) // get log
}, }
}; }
</script> </script>
<style scoped> <style scoped>
......
...@@ -141,10 +141,9 @@ export default { ...@@ -141,10 +141,9 @@ export default {
room_name: ["DjangoVue"], room_name: ["DjangoVue"],
room_select: "", room_select: "",
// baseUrl: "http://localhost:8006/webchat/index/", // baseUrl: "http://localhost:8006/webchat/index/",
baseurl: "/ws_api/", baseUrl: "http://yongma16.xyz/api/",
// baseUrl: "http://yongma16.xyz/", // websocketUrl: "/ws_api/",
websocketUrl: "/api/", websocketUrl: "ws://yongma16.xyz/ws-api/",
// websocketUrl: "yongma16.xyz/ws/webchat/",
websocket: null, websocket: null,
// room 存房间名字,content保存聊天信息的数组 // room 存房间名字,content保存聊天信息的数组
chat_info: new Array(), chat_info: new Array(),
...@@ -322,8 +321,8 @@ export default { ...@@ -322,8 +321,8 @@ export default {
try { try {
//判断房间是否存在 //判断房间是否存在
let roomFlag = false; let roomFlag = false;
this.chat_info.map((o, index) => { this.chat_info.map((item, index) => {
if (o.room == roomName) { if (item.room == roomName) {
// 房间存在 // 房间存在
console.log("房间存在", roomName); console.log("房间存在", roomName);
roomFlag = true; roomFlag = true;
...@@ -344,7 +343,7 @@ export default { ...@@ -344,7 +343,7 @@ export default {
console.log("创建房间出错", e); console.log("创建房间出错", e);
} }
this.chatRoomIndex = chatRoomIndex; this.chatRoomIndex = chatRoomIndex;
const wsUrl = this.websocketUrl + "webchat/room/"; const wsUrl = this.websocketUrl;
this.websocket = new WebSocket(wsUrl + room + "/"); // 连接 this.websocket = new WebSocket(wsUrl + room + "/"); // 连接
console.log(this.websocket, "聊天室"); console.log(this.websocket, "聊天室");
this.websocket.onmessage = this.websocketMessage; // 函数指向 this.websocket.onmessage = this.websocketMessage; // 函数指向
......
...@@ -5,7 +5,7 @@ export default { ...@@ -5,7 +5,7 @@ export default {
state: { state: {
// 用户账号密码 // 用户账号密码
userInfo: { userInfo: {
name: null, name: "游客",
password: null, password: null,
}, },
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册