fix:修改接口地址

merge-requests/78/merge
张征 3 years ago
parent 9da1383799
commit c11e89124c

@ -17,7 +17,7 @@
</div> </div>
</template> </template>
<script> <script>
import { ApiGetRecommendedGoodsList } from "@/plugins/api/goods"; import { ApiGetGoodsList } from "@/plugins/api/goods";
import UiGoodsItem from "@/components/UiGoodsItem.vue"; import UiGoodsItem from "@/components/UiGoodsItem.vue";
export default { export default {
components: { UiGoodsItem }, components: { UiGoodsItem },
@ -32,7 +32,13 @@ export default {
methods: { methods: {
async getRecommendedGoodsList() { async getRecommendedGoodsList() {
let vm = this; let vm = this;
let res = await ApiGetRecommendedGoodsList(); let res = await ApiGetGoodsList({
length: 20,
pageIndex: 1,
name: "",
categoryId: "",
order: "",
});
vm.recommendedData = res.result; vm.recommendedData = res.result;
}, },
}, },

@ -167,6 +167,7 @@ export default {
this.dialogVisible = false; this.dialogVisible = false;
this.$store.commit("setToken", result.token); this.$store.commit("setToken", result.token);
this.$store.dispatch("getUserInfo"); this.$store.dispatch("getUserInfo");
this.$startWebSockets()
} }
} }
}); });

@ -45,7 +45,8 @@ export default {
'@plugins/axiosTk.js', '@plugins/axiosTk.js',
'@plugins/vue-inject.js', '@plugins/vue-inject.js',
'@/plugins/v-distpicker', '@/plugins/v-distpicker',
'@/plugins/router' '@/plugins/router',
'@/plugins/im'
], ],
// Auto import components: https://go.nuxtjs.dev/config-components // Auto import components: https://go.nuxtjs.dev/config-components

@ -11,7 +11,7 @@
<main class="main"> <main class="main">
<h3 class="title">消息通知</h3> <h3 class="title">消息通知</h3>
<section class="section"> <section class="section">
<div class="section__item flex" v-for="item in msgList" :key="item.id"> <!-- <div class="section__item flex" v-for="item in 3" :key="item.id">
<img <img
class="section__item-img" class="section__item-img"
src="https://img1.baidu.com/it/u=3384796346,381674655&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500" src="https://img1.baidu.com/it/u=3384796346,381674655&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500"
@ -31,7 +31,7 @@
}} }}
</div> </div>
</div> </div>
</div> </div> -->
</section> </section>
</main> </main>
</div> </div>
@ -40,58 +40,15 @@
import { mapState } from "vuex"; import { mapState } from "vuex";
export default { export default {
data() { data() {
return { return {};
Socket: null,
msgList: [],
};
}, },
computed: { computed: {
...mapState(["token"]), ...mapState(["token"], ["socketMsgData"]),
}, },
mounted() { mounted(){
let url = `ws://192.168.10.93:8090/ws?client=${this.token}&type=1`; console.log(`socketMsgData`,this.socketMsgData)
// let url = `wss://k8s-horse-gateway.mashibing.cn/ws?client=${this.token}&type=1`;
this.socket(url);
},
methods: {
socket(url) {
let vm = this;
vm.Socket = new WebSocket(url);
vm.Socket.onopen = () => {
let traceId = Math.random();
vm.Socket.send(
`{"traceId":${traceId},traceType:1,"content":{"size": 100}}`
);
};
vm.Socket.onclose = () => {
vm.Socket = null;
};
vm.Socket.onerror = () => {
if (vm.Socket.readyState !== 3) {
if (vm.reconnection > 3) {
// vm.$message.error("!");
return;
}
}
};
vm.Socket.onmessage = (e) => {
if (e.data == `pong`) {
return;
}
let msg = JSON.parse(e.data);
console.log("websocket收到消息", msg);
if (msg.traceType == 1) {
let traceId = Math.random();
let sys = msg.content.sessionVOS.find((item) => item.type != 3);
let str = `{"traceId":${traceId},traceType:2,"content":{"sessionId":${sys.id}}}`;
vm.Socket.send(str);
}
if (msg.traceType == 2) {
vm.msgList = msg.content;
}
};
},
}, },
methods: {},
}; };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

@ -38,11 +38,11 @@
<div v-else :class="listData && listData.length ? 'page' : ''"> <div v-else :class="listData && listData.length ? 'page' : ''">
<main class="main" v-if="listData && listData.length"> <main class="main" v-if="listData && listData.length">
<nav class="main__nav"> <nav class="main__nav">
<p class="main__nav-crumbs"> <!-- <p class="main__nav-crumbs">
全部商品 全部商品
<i class="el-icon-arrow-right"></i> <i class="el-icon-arrow-right"></i>
<!-- <span v-if="levelType == 2">{{}}</span> --> <span v-if="levelType == 2">{{}}</span>
</p> </p> -->
<div class="main__nav-sort flex flex-middle" v-if="levelType == 1"> <div class="main__nav-sort flex flex-middle" v-if="levelType == 1">
<span class="main__nav-sort-txt">分类 :</span> <span class="main__nav-sort-txt">分类 :</span>
<span <span
@ -156,10 +156,8 @@ export default {
let res = await ApiGetCategoryTwoAndGoods({ categoryId: this.levelId }); let res = await ApiGetCategoryTwoAndGoods({ categoryId: this.levelId });
this.categoryOneList = res.result; this.categoryOneList = res.result;
this.getGoodsListData(); this.getGoodsListData();
console.log(res);
}, },
onNavClick(i) { onNavClick(i) {
console.log(i);
let vm = this; let vm = this;
vm.sortType = i; vm.sortType = i;
vm.navActive = i; vm.navActive = i;
@ -196,13 +194,15 @@ export default {
if (vm.levelType == 1) { if (vm.levelType == 1) {
vm.params.categoryId = vm.categoryOneList[vm.levelActive].id; vm.params.categoryId = vm.categoryOneList[vm.levelActive].id;
} }
if(vm.params.name){
vm.params.categoryId = ''
}
let res = await ApiGetGoodsList(vm.params); let res = await ApiGetGoodsList(vm.params);
vm.pageloading = false; vm.pageloading = false;
if (res.error) { if (res.error) {
vm.$message.error(res.error.message); vm.$message.error(res.error.message);
return false; return false;
} }
console.log(`goodListRes`, res.result);
vm.total = res.result.total; vm.total = res.result.total;
vm.listData = res.result.records; vm.listData = res.result.records;
}, },

@ -72,6 +72,7 @@ export default {
}, },
mounted() { mounted() {
this.getTabBarVisible(); this.getTabBarVisible();
this.$startWebSockets()
}, },
methods: { methods: {
getTabBarVisible() { getTabBarVisible() {

@ -0,0 +1,62 @@
import Vue from "vue";
import { TOKEN_KEY } from "@/constants";
function guid() {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
var r = (Math.random() * 16) | 0,
v = c == "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
Vue.prototype.$startWebSockets = function () {
console.log();
let token = this.$cookies.get(TOKEN_KEY);
if (token) {
let url = `wss://k8s-horse-gateway.mashibing.cn/ws?client=${token}&type=1`;
Vue.prototype.Socket = new WebSocket(url);
Vue.prototype.Socket.onopen = () => {
let traceId = guid();
Vue.prototype.Socket.send(
`{"traceId":${traceId},traceType:1,"content":{"size": 100}}`
);
};
Vue.prototype.Socket.onclose = () => {
Vue.prototype.Socket = null;
};
// Vue.prototype.Socket.onerror = () => {
// if (Vue.prototype.Socket.readyState !== 3) {
// }
// };
Vue.prototype.Socket.onmessage = (e) => {
if (e.data == `pong`) {
return;
}
let msg = JSON.parse(e.data);
console.log("websocket收到消息", msg);
// 获取会话
if (msg.traceType == 1) {
let traceId = guid();
let sys = msg.content.sessionVOS.find((item) => item.type != 3);
let str = `{"traceId":${traceId},traceType:2,"content":{"sessionId":${sys.id}}}`;
Vue.prototype.Socket.send(str);
this.$store.commit("setUnreadCount", msg.content.totalUnreadCount);
}
// 获取消息列表
if (msg.traceType == 2) {
this.$store.commit("setSocketMsgData", msg.content);
}
// 接收消息
if (msg.traceType == 3) {
let traceId = guid();
Vue.prototype.Socket.send(
`{"traceId":${traceId},traceType:1,"content":{"size": 100}}`
);
}
};
}
};

@ -18,6 +18,8 @@ const state = () => ({
seckillTabVisible: false, // 公共头是否展示秒杀tab seckillTabVisible: false, // 公共头是否展示秒杀tab
cartProducts: [], // 购物车列表 cartProducts: [], // 购物车列表
categroyData: [], // 公共页头分类数据 categroyData: [], // 公共页头分类数据
unreadCount:0, //未读消息数量
socketMsgData: [], //消息数据对象
}); });
const mutations = { const mutations = {
setUserInfo(state, info) { setUserInfo(state, info) {
@ -47,6 +49,12 @@ const mutations = {
setCategroyData(state, val) { setCategroyData(state, val) {
state.categroyData = val; state.categroyData = val;
}, },
setUnreadCount(state, val){
state.unreadCount = val;
},
setSocketMsgData(state, val){
state.socketMsgData = val;
}
}; };
const actions = { const actions = {
async nuxtServerInit({ state, commit, dispatch }) { async nuxtServerInit({ state, commit, dispatch }) {

Loading…
Cancel
Save