123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462 |
- 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'
- const App = {
- components: {
- footerCom,
- feedFix,
- dialogCom,
- loadingCom,
- headerCom
- },
- data() {
- return {
- title: 'Hello Vue',
- count: 0,
- articalArray: [], //详情数组
- //公共
- id: null,
- columnList: [],
- requestParams: { //内容接口请求参数
- categoryid: 0, //栏目id
- pageNum: 1,
- pageSize: 9,
- order: 'sortindex',
- articleid: 0, //访问量统计
- id: 0, //内容详情id
- },
- dup:'',
- currentPath: '',
- articalArray: [], //详情数组
- articalArrayRelated: [], //相关推荐
- columnTypes: [], //栏目类型
- colL: 0,
- modelType: 1,
- columnImage: '', //栏目图片
- footerBoolean: false, //底部延时加载(解决页面闪烁)
- contentBoolean: false, //中间延时加载(优化banner图片加载慢的问题)
- // 公共弹框
- 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.dup=this.getQuery('dup')
- this.requestParams.categoryid = this.getQuery('categoryid') ? this.getQuery('categoryid') : ''
- this.requestParams.id = this.getQuery('id') ? this.getQuery('id') : ''
- this.requestParams.articleid = this.getQuery('id') ? this.getQuery('id') : ''
- },
- mounted: function () {
- this.getColumnData()
- },
- methods: {
- //获取栏目数据
- getColumnData() {
- var _this = this;
- if (!localStorage.getItem('storeColumnList') || (window.location.pathname == '/'&&!this.dup) || window.location.pathname == '/index.html') {
- $.ajax({
- type: 'get',
- dataType: 'json',
- url: window.FQDN2 + 'siteCategory/siteCategoryList',
- }).done(function (res) {
- _this.lazyFunc()
- _this.columnList = res.data;
- let expires = Date.now() + 1000 * 60 * 30; //半小时过期时间
- localStorage.setItem('storeColumnList', JSON.stringify({
- data: _this.columnList,
- expires
- }));
- _this.loading = false
- _this.handleColumnData()
- })
- } else {
- this.loading = false;
- this.handleColumnData()
- }
- setTimeout(function () {
- _this.contentBoolean = true
- }, 900)
- setTimeout(function () {
- _this.footerBoolean = true
- }, 1000)
- },
- handleColumnData() {
-
- if(window.location.pathname=='/'&&!this.dup){//if 首页模板
- this.currentPath='/template1/'
- } else if(window.location.pathname=='/'&&this.dup){ //if 首页复用模板
- this.currentPath='/template1/?dup='+this.dup
- }else if (window.location.href.indexOf("dup") > 0) { // if 非首页模板
- this.currentPath = `${window.location.pathname}?dup=` + this.getQuery('dup')
- } else { //非首页复用模板
- this.currentPath = window.location.pathname;
- }
- this.columnList = JSON.parse(localStorage.getItem('storeColumnList')).data;
- // 读取并检查是否过期
- if (JSON.parse(localStorage.getItem('storeColumnList')).expires < Date.now()) {
- localStorage.removeItem('storeColumnList');
- } else {}
- var _this = this;
- for (let i = 0; i < _this.columnList.length; i++) {
- // 获取反馈弹框类型数据
- if ( _this.columnList[i].categoryStyle == '2'&& _this.columnList[i].sname == '') {
- _this.dialogDataArray = (_this.columnList[i].children)
- _this.ruleForm.platName = _this.dialogDataArray[0].categoryName;
- }
- //栏目处理
- //进入首页
- if (_this.columnList[i].categoryStyle == '1' && (window.location.pathname == '/' || window.location.pathname == '' || window.location.pathname == '/index.html')) {
- if ( '/?dup=' + _this.columnList[i].sname == `${window.location.pathname}?dup=` + this.getQuery('dup')) {
- console.log('首页复用模板')
- getSeoCommon()
- var objData = _this.columnList.filter(obj =>obj.categoryStyle==1? '/?dup=' + obj.sname == `${window.location.pathname}?dup=` + _this.getQuery('dup'):'');
- _this.requestParams.categoryid = objData[0].id
- _this.getArticalData(_this.requestParams)
- _this.columnImage = _this.columnList[i].imagePath;
- setTimeout(() => {
- if (_this.modelType == 2) {
- document.getElementById("videoPlay").src = _this.columnImage; //url为你需要播放的视频地址
- document.getElementById("videoPlay").setAttribute('poster', '/assets/img/banner/poster.jpg');
- }
- }, 100)
- _this.getArticalData(_this.requestParams)
- }
- if(window.location.href.indexOf("dup") == -1&& !_this.columnList[i].sname ){
- console.log('首页模板')
- getSeoCommon()
- this.requestParams.categoryid = this.columnList[0].id
- _this.modelType = _this.columnList[0].modelType;
- _this.columnImage = _this.columnList[0].imagePath;
- setTimeout(() => {
- if (_this.modelType == 2) {
- document.getElementById("videoPlay").src = _this.columnImage; //url为你需要播放的视频地址
- document.getElementById("videoPlay").setAttribute('poster', '/assets/img/banner/poster.jpg');
- }
- }, 100)
- _this.getArticalData(_this.requestParams)
- }
-
-
-
-
- }
- //进入其他栏目页
- if (('/template' + _this.columnList[i].categoryStyle + '/' == window.location.pathname) || (_this.columnList[i].categoryStyle == window.location.pathname.replace('index.html', ''))) {
- if (window.location.href.indexOf("dup") && ('/template' + _this.columnList[i].categoryStyle + '/?dup=' + _this.columnList[i].sname == `${window.location.pathname}?dup=` + this.getQuery('dup'))) {
- if (_this.columnList[i].children.length > 0) {
- _this.columnTypes = _this.columnList[i].children
- _this.requestParams.categoryid = (_this.getQuery('isUrlId') == 1) ? _this.getQuery('categoryid') : _this.columnTypes[0].id;
- _this.getArticalData(_this.requestParams)
- _this.columnImage = _this.columnList[i].imagePath;
- } else {
- var objData = _this.columnList.filter(obj => '/template' + obj.categoryStyle + '/?dup=' + obj.sname == `${window.location.pathname}?dup=` + _this.getQuery('dup'));
- _this.requestParams.categoryid = objData[0].id
- _this.getArticalData(_this.requestParams)
- _this.columnImage = _this.columnList[i].imagePath;
- }
- getSeoCommon()
- }
- if (window.location.href.indexOf("dup") == -1 && !_this.columnList[i].sname && ('/template' + _this.columnList[i].categoryStyle + '/' == window.location.pathname)) {
- if (_this.columnList[i].children.length > 0) {
- _this.columnTypes = _this.columnList[i].children
- _this.requestParams.categoryid = (_this.getQuery('isUrlId') == 1) ? _this.getQuery('categoryid') : _this.columnTypes[0].id;
- _this.getArticalData(_this.requestParams)
- _this.columnImage = _this.columnList[i].imagePath;
- } else {
- var objData = _this.columnList.filter(obj => '/template' + obj.categoryStyle + '/' == window.location.pathname.replace('index.html', ''));
- _this.requestParams.categoryid = objData[0].id
- _this.getArticalData(_this.requestParams)
- _this.columnImage = _this.columnList[i].imagePath;
- }
- getSeoCommon()
-
- }
- _this.modelType = _this.columnList[i].modelType;
- setTimeout(() => {
- if (_this.modelType == 2) {
- document.getElementById("videoPlay").src = _this.columnImage; //url为你需要播放的视频地址
- document.getElementById("videoPlay").setAttribute('poster', '/assets/img/banner/poster.jpg');
- }
- }, 100)
- } else {
- // 进入详情页
- if ('/template' + _this.columnList[i].categoryStyle + '/read.html' == window.location.pathname) {
- getDetailCommon()
- }
- function getDetailCommon() {
- //获取内容详情
- _this.getArticalData(_this.requestParams)
- //获取详情相关数据
- setTimeout(() => {
- _this.requestParams.id = ''
- _this.requestParams.articleid = ''
- _this.getArticalData(_this.requestParams, 1)
- }, 100)
- //产品详情时栏目高亮
- if(window.location.href.indexOf("dup") && ('/template' + _this.columnList[i].categoryStyle+ '/read.html' + '?dup=' + _this.columnList[i].sname == `${window.location.pathname}?dup=` + _this.getQuery('dup'))){
- _this.currentPath = `/template${ _this.columnList[i].categoryStyle}/?dup=` + _this.getQuery('dup')
- getSeoCommon()
- }
-
- if (window.location.href.indexOf("dup") == -1 && !_this.columnList[i].sname && ('/template' + _this.columnList[i].categoryStyle + '/read.html' == window.location.pathname)) {
-
- _this.currentPath = `/template${ _this.columnList[i].categoryStyle}/`
- getSeoCommon()
- }
- _this.modelType = _this.columnList[i].modelType; //栏目图片获取
- _this.columnImage = _this.columnList[i].imagePath; //栏目图片获取
- setTimeout(() => {
- if (_this.modelType == 2) {
- document.getElementById("videoPlay").src = _this.columnImage; //url为你需要播放的视频地址
- document.getElementById("videoPlay").setAttribute('poster', '/assets/img/banner/poster.jpg');
- }
- }, 100)
- }
- }
- 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);
- }
- }
- },
- //获取内容
- getArticalData(requestParams, type) {
- var _this = this
- if (window.location.pathname == '/template4/') {
- _this.requestParams.order = ''
- }
- $.ajax({
- type: 'GET',
- dataType: 'json',
- url: window.FQDN2 + 'siteArticle/siteArticleList',
- data: requestParams
- }).done(function (res) {
- _this.lazyFunc()
- var aa
- var bb
- if (type == 1) {
- bb = res.data.records
- } else {
- aa = res.data.records;
- _this.articalArray = aa;
- }
- if (bb) {
- _this.articalArrayRelated = bb.filter(obj => obj.title != _this.articalArray[0].title);
- // _this.articalArrayRelated = bb
- }
- // _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) {
-
- var aa=this.getQuery('dup')
- if(this.getQuery('dup')){
- window.location = "./read.html?dup="+aa+"&categoryid=" + param.categoryid + "&id=" + param.id + "&isUrlId=1";
- }else{
- window.location = "./read.html?categoryid=" + param.categoryid + "&id=" + 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
- },
- lazyFunc: function () {
- setTimeout(function () {
- // 1 获取全部图片的DOM节点
- // 注意:querySelectorAll 值为伪数组利用扩展运算符转为真数组
- const images = $('.lazyContainer img')
- // 2 监听页面滚动事件
- window.addEventListener('scroll', lazyLoad)
- // 3 定义页面滚动的处理函数
- function lazyLoad() {
- for (let i = 0; i < images.length; i++) {
- // isVisible是否该图片位于可视区域 返回true 或false
- if (isVisible(images[i])) {
- // 将元素的自定义属性 data-src 赋值给元素的 src 属性
- // dataset.src 此为元素的自定义属性 data-src
- if(images[i].dataset.src){
- images[i].src = images[i].dataset.src // 等价于:img.setAttribute('src', img.getAttribute('data-src'))
- }
- // 防止重复被遍历 加载完之后 删除元素不再加载
- images.splice(i, 1)
- i--
- }
- }
-
- }
- lazyLoad()
- // 4 可视区域判断函数
- function isVisible(img) {
- // 判断是否在可视区域
- const imgRect = img.getBoundingClientRect() // getBoundingClientRect 获取图片的动态信息
- return imgRect.bottom > 0 && imgRect.top < window.innerHeight && imgRect.right > 0 && imgRect.left < window.innerWidth
- }
- }, 100)
- },
- //弹框显示隐藏(子组件向父组件传值)
- 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);
- }
- }
- }
- Vue.createApp(App).use(ElementPlus).mount("#app");
|