import footerCom from '/assets/js/component/footerCom.js' import feedFix from '/assets/js/component/feedFix.js' import dialogCom from '/assets/js/component/dialogCom.js' import loadingCom from '/assets/js/component/loadingCom.js' import headerCom from '/assets/js/component/headerCom.js' var AboutKeyWrds=''; var app = new Vue({ el: '#app', components: { footerCom, feedFix, dialogCom, loadingCom, headerCom }, data: { //公共 id: null, columnList: [ ], requestParams: { //内容接口请求参数 categoryid: 0, pageNum: 1, pageSize: 9, title: '', order:'sortindex', articleid:0, }, currentPath: '', articalArray: [], //详情数组 articalArrayRelated: [], //相关推荐 columnTypes: [], //栏目类型 colL:0, columnImage: '', //栏目图片 // 公共弹框 centerDialogVisible: false, dialogDataArray: [], ruleForm: { platName: '智慧安防', consultName: '', consultPhone: '', mail: '', company: '', consultContent: "", }, rules: { platName: [{ required: true, message: '请选择类型', trigger: 'change' }, ], consultName: [{ required: true, message: '请输入姓名', trigger: 'blur' }, ], consultPhone: [{ required: true, message: '请输入正确的电话号码', pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, trigger: 'change' }], mail: [{ required: false, type: "email", message: "请输入正确的邮箱地址", trigger: 'blur' }], }, //首页 homeList: [], status: false, // 新闻 goPage: 1, totalPageNum: 1, totalPageSzie: 1, loading: true, categoryid: 0, }, computed: { }, created: function () { this.requestParams.categoryid = this.getQuery('id') ? this.getQuery('id') : '' this.requestParams.title = this.getQuery('title') ? this.getQuery('title') : '' this.requestParams.articleid = this.getQuery('articleid') ? this.getQuery('articleid') : '' }, mounted: function () { this.getColumnData() }, methods: { //获取栏目数据 getColumnData() { var _this = this; if(!localStorage.getItem('storeColumnList')||window.location.pathname == '/index.html'||window.location.pathname == '/'){ $.ajax({ type: 'get', dataType: 'json', url: window.FQDN2 + 'siteCategory/siteCategoryList', }).done(function (res) { _this.columnList = res.data; let expires = Date.now() + 1000 * 60* 30 ; //半小时过期时间 localStorage.setItem('storeColumnList', JSON.stringify({data: _this.columnList, expires})); _this.loading=false _this.currentPath = window.location.pathname; _this.handleColumnData() }) }else{ console.log(JSON.parse(localStorage.getItem('storeColumnList'))) this.loading = false; this.handleColumnData() } }, handleColumnData(){ this.currentPath = window.location.pathname; this.columnList=JSON.parse(localStorage.getItem('storeColumnList')).data; console.log( JSON.parse(localStorage.getItem('storeColumnList'))) console.log( Date.now()) // 读取并检查是否过期 if ( JSON.parse(localStorage.getItem('storeColumnList')).expires < Date.now()) { localStorage.removeItem('storeColumnList'); } else { console.log( this.columnList); } var _this=this; for (let i = 0; i < _this.columnList.length; i++) { //栏目处理 if (_this.columnList[i].sname == window.location.pathname) { //进入当前栏目页 getSeoCommon() _this.columnTypes = _this.columnList[i].children _this.colL= _this.columnTypes.childten; if (_this.columnList[i].children.length > 0) { _this.requestParams.categoryid = (_this.getQuery('isUrlId') == 1) ? _this.getQuery('id') : _this.columnTypes[0].id; } else { var objData = _this.columnList.filter(obj => obj.sname == window.location.pathname); _this.requestParams.categoryid=objData[0].id } _this.getArticalData(_this.requestParams) _this.columnImage = _this.columnList[i].imagePath; } else { // 进入详情页 if (_this.columnList[i].sname == '/product/index.html' && window.location.pathname == '/product/read.html') { getDetailCommon() getSeoCommon() } if (_this.columnList[i].sname == '/solution/index.html' && window.location.pathname == '/solution/read.html') { getDetailCommon() getSeoCommon() } if (_this.columnList[i].sname == '/news/index.html' && window.location.pathname == '/news/read.html') { getDetailCommon() getSeoCommon() } function getDetailCommon(){ //获取内容详情 _this.getArticalData(_this.requestParams) //获取详情相关数据 setTimeout(() => { _this.requestParams.title = '' _this.requestParams.articleid = 0 _this.getArticalData(_this.requestParams, 1) }, 100) _this.currentPath = _this.columnList[i].sname //产品详情时栏目高亮 _this.columnImage = _this.columnList[i].imagePath; //栏目图片获取 } } function getSeoCommon(){ $('title').text(_this.columnList[i].categoryName); $('meta[name="description"]').attr('content', _this.columnList[i].metadescription); $('meta[name="keywords"]').attr('content',_this.columnList[i].metakeywords); } //首页旧 if (_this.columnList[i].sname == '/index.html' && (window.location.pathname == '/index.html'||window.location.pathname == '/')) { jQuery.ajax({ type: 'POST', dataType: 'json', url: window.FQDN + 'Index/index', }).done(function (res) { // _this.loading = false; _this.homeList = res _this.status = true }).fail(function (err) {}); } // 获取反馈弹框类型数据 if (_this.columnList[i].sname == '/solution/index.html') { _this.dialogDataArray = (_this.columnList[i].children) _this.ruleForm.platName = _this.dialogDataArray[0].categoryName; } } }, //获取内容 getArticalData(requestParams, type) { var _this=this if( window.location.pathname == '/news/index.html'){ _this.requestParams.order = '' } $.ajax({ type: 'GET', dataType: 'json', url: window.FQDN2 + 'siteArticle/siteArticleList', data: requestParams }).done(function (res) { var aa var bb if(type==1){ bb=res.data.records }else{ aa= res.data.records; // aa.sort(_this.compare("sortindex")) _this.articalArray = aa; } if (bb) { console.log(bb) console.log(_this.articalArray[0]) _this.articalArrayRelated = bb.filter(obj => obj.title != _this.articalArray[0].title); // _this.articalArrayRelated = bb console.log(_this.articalArrayRelated) } // _this.loading = false; _this.totalPageSzie = res.data.total _this.totalPageNum = Math.ceil(res.data.total / res.data.size); }).fail(function (err) {}); }, //类型点击 facilityClick(e, item) { this.requestParams.categoryid = item.id this.requestParams.pageNum = 1 this.getArticalData(this.requestParams) }, // 分页 oneInnerBox: function (param) { window.location = "./read.html?id=" + param.categoryid + "&title=" + param.title + "&articleid=" + param.id + "&isUrlId=1"; }, enterPage: function (res) { if (this.goPage >= 1 && this.goPage <= this.totalPageNum) { this.requestParams.pageNum = this.goPage this.getArticalData(this.requestParams) } else { this.goPage = 1 alert('输入页数有误!') } }, currentChange: function (res) { this.requestParams.pageNum = res this.getArticalData(this.requestParams) }, //申请试用 goApply:function(){ this.centerDialogVisible=true }, //弹框显示隐藏(子组件向父组件传值) handleChildEvent:function(value) { this.centerDialogVisible = value; // 处理从子组件接收到的数据 }, // 排序 compare(property) { return function (a, b) { var value1 = a[property]; var value2 = b[property]; return value1 - value2; } }, // 获取路由参数 getQuery(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return decodeURI(r[2]); return null; }, //获得年月日时分秒 //传入日期//例:2020-10-27T14:36:23 timeFormatSeconds(time) { var d = time ? new Date(time) : new Date(); var year = d.getFullYear(); var month = d.getMonth() + 1; var day = d.getDate(); var hours = d.getHours(); var min = d.getMinutes(); var seconds = d.getSeconds(); if (month < 10) month = '0' + month; if (day < 10) day = '0' + day; if (hours < 0) hours = '0' + hours; if (min < 10) min = '0' + min; if (seconds < 10) seconds = '0' + seconds; return (year + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + seconds); } } });