You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
zhishifufei_php/public/pc/mixins/base2.js

167 lines
6.0 KiB

define([
'mixins/router',
'api/home',
'api/auth',
'api/public',
'api/special'
], function (routerMixin, homeApi, authApi, publicApi, specialApi) {
return {
mixins: [routerMixin],
data: function () {
return {
userInfo: {
avatar: ''
},
publicData: {},
agreeContent: {},
loginVisible: false,
agreeVisible: false,
isLogin: false,
router: router
};
},
watch: {
'publicData.kefu_token': function () {
if (window.canCustomerServer) {
window.canCustomerServer.destroy();
window.canCustomerServer = null;
}
var option = {
openUrl: this.publicData.service_url,
token: this.publicData.kefu_token,
isShowTip: false,
domId: 'customerServerTip',
};
if (this.userInfo.phone) {
option.sendUserData = {
nickName: this.userInfo.nickname,
phone: this.userInfo.phone,
avatar: this.userInfo.avatar
}
}
window.canCustomerServer = new initCustomerServer(option);
window.canCustomerServer.init();
}
},
created: function () {
var vm = this;
this.public_data();
this.get_host_search();
this.get_home_navigation();
this.agree_content();
this.get_grade_cate();
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
if (request.readyState === request.DONE) {
if (request.status === 200) {
var text = request.responseText;
if (text) {
var markStart = text.indexOf('<script>');
if (markStart !== -1) {
text = text.slice(markStart + 8);
var markEnd = text.indexOf('</script>');
if (markEnd !== -1) {
text = text.slice(0, markEnd);
}
}
var scriptEl = document.createElement('script');
scriptEl.innerHTML = text;
document.body.appendChild(scriptEl);
}
}
}
};
request.open('GET', '../public_api/get_website_statistics');
request.send();
// 登陆状态
homeApi.user_login().then(function () {
vm.isLogin = true;
vm.user_info();
}).catch(function (err) {
if (window.location.href.includes('/web/my/index')) {
vm.$message.error(err.msg);
vm.loginVisible = true;
}
});
},
methods: {
// 公共数据
public_data: function () {
var vm = this;
publicApi.public_data().then(function (res) {
for (var key in res.data) {
if (Object.hasOwnProperty.call(res.data, key)) {
vm.$set(vm.publicData, key, res.data[key]);
}
}
});
},
// 热搜
get_host_search: function () {
var vm = this;
publicApi.get_host_search().then(function (res) {
vm.$set(vm.publicData, 'host_search', res.data);
}).catch(function (err) {
vm.$message.error(err.msg);
});
},
// 用户协议
agree_content: function () {
var vm = this;
publicApi.agree().then(function (res) {
vm.agreeContent = res.data;
}).catch(function (err) {
vm.$message.error(err.msg);
});
},
// 大分类
get_grade_cate: function () {
var vm = this;
specialApi.get_grade_cate().then(function (res) {
vm.$set(vm.publicData, 'grade_cate', res.data);
}).catch(function (err) {
vm.$message.error(err.msg);
});
},
loginOpen: function () {
this.loginVisible = true;
},
// 关闭登录弹窗
loginClose: function (type) {
this.loginVisible = false;
if (type) {
if (this.isReload) {
window.location.reload();
} else {
this.isLogin = true;
this.user_info();
}
}
},
agreeOpen: function () {
this.agreeVisible = true;
},
agreeClose: function () {
this.agreeVisible = false;
},
// 用户信息
user_info: function () {
var vm = this;
authApi.user_info().then(function (res) {
vm.userInfo = res.data;
}).catch(function (err) {
vm.$message.error(err.msg);
});
},
// 顶部导航
get_home_navigation: function () {
var vm = this;
publicApi.get_home_navigation().then(function (res) {
vm.$set(vm.publicData, 'navList', res.data);
}).catch(function (err) {
vm.$message.error(err.msg);
});
}
}
};
});