commonVue.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. import footerCom from '/assets/js/component/footerCom.js'
  2. import feedFix from '/assets/js/component/feedFix.js'
  3. import dialogCom from '/assets/js/component/dialogCom.js'
  4. import loadingCom from '/assets/js/component/loadingCom.js'
  5. import headerCom from '/assets/js/component/headerCom.js'
  6. const App = {
  7. components: {
  8. footerCom,
  9. feedFix,
  10. dialogCom,
  11. loadingCom,
  12. headerCom
  13. },
  14. data() {
  15. return {
  16. title: 'Hello Vue',
  17. count: 0,
  18. articalArray: [], //详情数组
  19. //公共
  20. id: null,
  21. columnList: [],
  22. requestParams: { //内容接口请求参数
  23. categoryid: 0, //栏目id
  24. pageNum: 1,
  25. pageSize: 9,
  26. order: 'sortindex',
  27. articleid: 0, //访问量统计
  28. id: 0, //内容详情id
  29. },
  30. dup:'',
  31. currentPath: '',
  32. articalArray: [], //详情数组
  33. articalArrayRelated: [], //相关推荐
  34. columnTypes: [], //栏目类型
  35. colL: 0,
  36. modelType: 1,
  37. columnImage: '', //栏目图片
  38. footerBoolean: false, //底部延时加载(解决页面闪烁)
  39. contentBoolean: false, //中间延时加载(优化banner图片加载慢的问题)
  40. // 公共弹框
  41. centerDialogVisible: false,
  42. dialogDataArray: [],
  43. ruleForm: {
  44. platName: '智慧安防',
  45. consultName: '',
  46. consultPhone: '',
  47. mail: '',
  48. company: '',
  49. consultContent: "",
  50. },
  51. rules: {
  52. platName: [{
  53. required: true,
  54. message: '请选择类型',
  55. trigger: 'change'
  56. }, ],
  57. consultName: [{
  58. required: true,
  59. message: '请输入姓名',
  60. trigger: 'blur'
  61. }, ],
  62. consultPhone: [{
  63. required: true,
  64. message: '请输入正确的电话号码',
  65. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  66. trigger: 'change'
  67. }],
  68. mail: [{
  69. required: false,
  70. type: "email",
  71. message: "请输入正确的邮箱地址",
  72. trigger: 'blur'
  73. }],
  74. },
  75. //首页
  76. homeList: [],
  77. status: false,
  78. // 新闻
  79. goPage: 1,
  80. totalPageNum: 1,
  81. totalPageSzie: 1,
  82. loading: true,
  83. categoryid: 0,
  84. }
  85. },
  86. computed: {
  87. },
  88. created: function () {
  89. this.dup=this.getQuery('dup')
  90. this.requestParams.categoryid = this.getQuery('categoryid') ? this.getQuery('categoryid') : ''
  91. this.requestParams.id = this.getQuery('id') ? this.getQuery('id') : ''
  92. this.requestParams.articleid = this.getQuery('id') ? this.getQuery('id') : ''
  93. },
  94. mounted: function () {
  95. this.getColumnData()
  96. },
  97. methods: {
  98. //获取栏目数据
  99. getColumnData() {
  100. var _this = this;
  101. if (!localStorage.getItem('storeColumnList') || (window.location.pathname == '/'&&!this.dup) || window.location.pathname == '/index.html') {
  102. $.ajax({
  103. type: 'get',
  104. dataType: 'json',
  105. url: window.FQDN2 + 'siteCategory/siteCategoryList',
  106. }).done(function (res) {
  107. _this.lazyFunc()
  108. _this.columnList = res.data;
  109. let expires = Date.now() + 1000 * 60 * 30; //半小时过期时间
  110. localStorage.setItem('storeColumnList', JSON.stringify({
  111. data: _this.columnList,
  112. expires
  113. }));
  114. _this.loading = false
  115. _this.handleColumnData()
  116. })
  117. } else {
  118. this.loading = false;
  119. this.handleColumnData()
  120. }
  121. setTimeout(function () {
  122. _this.contentBoolean = true
  123. }, 900)
  124. setTimeout(function () {
  125. _this.footerBoolean = true
  126. }, 1000)
  127. },
  128. handleColumnData() {
  129. if(window.location.pathname=='/'&&!this.dup){//if 首页模板
  130. this.currentPath='/template1/'
  131. } else if(window.location.pathname=='/'&&this.dup){ //if 首页复用模板
  132. this.currentPath='/template1/?dup='+this.dup
  133. }else if (window.location.href.indexOf("dup") > 0) { // if 非首页模板
  134. this.currentPath = `${window.location.pathname}?dup=` + this.getQuery('dup')
  135. } else { //非首页复用模板
  136. this.currentPath = window.location.pathname;
  137. }
  138. this.columnList = JSON.parse(localStorage.getItem('storeColumnList')).data;
  139. // 读取并检查是否过期
  140. if (JSON.parse(localStorage.getItem('storeColumnList')).expires < Date.now()) {
  141. localStorage.removeItem('storeColumnList');
  142. } else {}
  143. var _this = this;
  144. for (let i = 0; i < _this.columnList.length; i++) {
  145. // 获取反馈弹框类型数据
  146. if ( _this.columnList[i].categoryStyle == '2'&& _this.columnList[i].sname == '') {
  147. _this.dialogDataArray = (_this.columnList[i].children)
  148. _this.ruleForm.platName = _this.dialogDataArray[0].categoryName;
  149. }
  150. //栏目处理
  151. //进入首页
  152. if (_this.columnList[i].categoryStyle == '1' && (window.location.pathname == '/' || window.location.pathname == '' || window.location.pathname == '/index.html')) {
  153. if ( '/?dup=' + _this.columnList[i].sname == `${window.location.pathname}?dup=` + this.getQuery('dup')) {
  154. console.log('首页复用模板')
  155. getSeoCommon()
  156. var objData = _this.columnList.filter(obj =>obj.categoryStyle==1? '/?dup=' + obj.sname == `${window.location.pathname}?dup=` + _this.getQuery('dup'):'');
  157. _this.requestParams.categoryid = objData[0].id
  158. _this.getArticalData(_this.requestParams)
  159. _this.columnImage = _this.columnList[i].imagePath;
  160. _this.modelType = _this.columnList[i].modelType;
  161. setTimeout(() => {
  162. if (_this.modelType == 2) {
  163. document.getElementById("videoPlay").src = _this.columnImage; //url为你需要播放的视频地址
  164. document.getElementById("videoPlay").setAttribute('poster', '/assets/img/banner/poster.jpg');
  165. }
  166. }, 100)
  167. }
  168. if(window.location.href.indexOf("dup") == -1&& !_this.columnList[i].sname ){
  169. console.log('首页模板')
  170. getSeoCommon()
  171. this.requestParams.categoryid = this.columnList[0].id
  172. _this.columnImage = _this.columnList[0].imagePath;
  173. _this.getArticalData(_this.requestParams)
  174. _this.modelType = _this.columnList[i].modelType;
  175. setTimeout(() => {
  176. if (_this.modelType == 2) {
  177. document.getElementById("videoPlay").src = _this.columnImage; //url为你需要播放的视频地址
  178. document.getElementById("videoPlay").setAttribute('poster', '/assets/img/banner/poster.jpg');
  179. }
  180. }, 100)
  181. }
  182. }
  183. //进入其他栏目页
  184. if (('/template' + _this.columnList[i].categoryStyle + '/' == window.location.pathname) || (_this.columnList[i].categoryStyle == window.location.pathname.replace('index.html', ''))) {
  185. if (window.location.href.indexOf("dup") && ('/template' + _this.columnList[i].categoryStyle + '/?dup=' + _this.columnList[i].sname == `${window.location.pathname}?dup=` + this.getQuery('dup'))) {
  186. if (_this.columnList[i].children.length > 0) {
  187. _this.columnTypes = _this.columnList[i].children
  188. _this.requestParams.categoryid = (_this.getQuery('isUrlId') == 1) ? _this.getQuery('categoryid') : _this.columnTypes[0].id;
  189. _this.getArticalData(_this.requestParams)
  190. _this.columnImage = _this.columnList[i].imagePath;
  191. } else {
  192. var objData = _this.columnList.filter(obj => '/template' + obj.categoryStyle + '/?dup=' + obj.sname == `${window.location.pathname}?dup=` + _this.getQuery('dup'));
  193. _this.requestParams.categoryid = objData[0].id
  194. _this.getArticalData(_this.requestParams)
  195. _this.columnImage = _this.columnList[i].imagePath;
  196. }
  197. getSeoCommon()
  198. _this.modelType = _this.columnList[i].modelType;
  199. setTimeout(() => {
  200. if (_this.modelType == 2) {
  201. document.getElementById("videoPlay").src = _this.columnImage; //url为你需要播放的视频地址
  202. document.getElementById("videoPlay").setAttribute('poster', '/assets/img/banner/poster.jpg');
  203. }
  204. }, 100)
  205. }
  206. if (window.location.href.indexOf("dup") == -1 && !_this.columnList[i].sname && ('/template' + _this.columnList[i].categoryStyle + '/' == window.location.pathname)) {
  207. if (_this.columnList[i].children.length > 0) {
  208. _this.columnTypes = _this.columnList[i].children
  209. _this.requestParams.categoryid = (_this.getQuery('isUrlId') == 1) ? _this.getQuery('categoryid') : _this.columnTypes[0].id;
  210. _this.getArticalData(_this.requestParams)
  211. _this.columnImage = _this.columnList[i].imagePath;
  212. } else {
  213. var objData = _this.columnList.filter(obj => '/template' + obj.categoryStyle + '/' == window.location.pathname.replace('index.html', ''));
  214. _this.requestParams.categoryid = objData[0].id
  215. _this.getArticalData(_this.requestParams)
  216. _this.columnImage = _this.columnList[i].imagePath;
  217. }
  218. getSeoCommon()
  219. _this.modelType = _this.columnList[i].modelType;
  220. setTimeout(() => {
  221. if (_this.modelType == 2) {
  222. document.getElementById("videoPlay").src = _this.columnImage; //url为你需要播放的视频地址
  223. document.getElementById("videoPlay").setAttribute('poster', '/assets/img/banner/poster.jpg');
  224. }
  225. }, 100)
  226. }
  227. } else {
  228. // 进入详情页
  229. if ('/template' + _this.columnList[i].categoryStyle + '/read.html' == window.location.pathname) {
  230. getDetailCommon()
  231. }
  232. function getDetailCommon() {
  233. //获取内容详情
  234. _this.getArticalData(_this.requestParams)
  235. //获取详情相关数据
  236. setTimeout(() => {
  237. _this.requestParams.id = ''
  238. _this.requestParams.articleid = ''
  239. _this.getArticalData(_this.requestParams, 1)
  240. }, 100)
  241. //产品详情时栏目高亮
  242. 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'))){
  243. _this.currentPath = `/template${ _this.columnList[i].categoryStyle}/?dup=` + _this.getQuery('dup')
  244. getSeoCommon()
  245. _this.modelType = _this.columnList[i].modelType; //栏目图片获取
  246. _this.columnImage = _this.columnList[i].imagePath; //栏目图片获取
  247. setTimeout(() => {
  248. if (_this.modelType == 2) {
  249. document.getElementById("videoPlay").src = _this.columnImage; //url为你需要播放的视频地址
  250. document.getElementById("videoPlay").setAttribute('poster', '/assets/img/banner/poster.jpg');
  251. }
  252. }, 100)
  253. }
  254. if (window.location.href.indexOf("dup") == -1 && !_this.columnList[i].sname && ('/template' + _this.columnList[i].categoryStyle + '/read.html' == window.location.pathname)) {
  255. _this.currentPath = `/template${ _this.columnList[i].categoryStyle}/`
  256. getSeoCommon()
  257. _this.modelType = _this.columnList[i].modelType; //栏目图片获取
  258. _this.columnImage = _this.columnList[i].imagePath; //栏目图片获取
  259. setTimeout(() => {
  260. if (_this.modelType == 2) {
  261. document.getElementById("videoPlay").src = _this.columnImage; //url为你需要播放的视频地址
  262. document.getElementById("videoPlay").setAttribute('poster', '/assets/img/banner/poster.jpg');
  263. }
  264. }, 100)
  265. }
  266. }
  267. }
  268. function getSeoCommon() {
  269. $('title').text(_this.columnList[i].categoryName);
  270. $('meta[name="description"]').attr('content', _this.columnList[i].metadescription);
  271. $('meta[name="keywords"]').attr('content', _this.columnList[i].metakeywords);
  272. }
  273. }
  274. },
  275. //获取内容
  276. getArticalData(requestParams, type) {
  277. var _this = this
  278. if (window.location.pathname == '/template4/') {
  279. _this.requestParams.order = ''
  280. }
  281. $.ajax({
  282. type: 'GET',
  283. dataType: 'json',
  284. url: window.FQDN2 + 'siteArticle/siteArticleList',
  285. data: requestParams
  286. }).done(function (res) {
  287. _this.lazyFunc()
  288. var aa
  289. var bb
  290. if (type == 1) {
  291. bb = res.data.records
  292. } else {
  293. aa = res.data.records;
  294. _this.articalArray = aa;
  295. }
  296. if (bb) {
  297. _this.articalArrayRelated = bb.filter(obj => obj.title != _this.articalArray[0].title);
  298. // _this.articalArrayRelated = bb
  299. }
  300. // _this.loading = false;
  301. _this.totalPageSzie = res.data.total
  302. _this.totalPageNum = Math.ceil(res.data.total / res.data.size);
  303. }).fail(function (err) {});
  304. },
  305. //类型点击
  306. facilityClick(e, item) {
  307. this.requestParams.categoryid = item.id
  308. this.requestParams.pageNum = 1
  309. this.getArticalData(this.requestParams)
  310. },
  311. // 分页
  312. oneInnerBox: function (param) {
  313. var aa=this.getQuery('dup')
  314. if(this.getQuery('dup')){
  315. window.location = "./read.html?dup="+aa+"&categoryid=" + param.categoryid + "&id=" + param.id + "&isUrlId=1";
  316. }else{
  317. window.location = "./read.html?categoryid=" + param.categoryid + "&id=" + param.id + "&isUrlId=1";
  318. }
  319. },
  320. enterPage: function (res) {
  321. if (this.goPage >= 1 && this.goPage <= this.totalPageNum) {
  322. this.requestParams.pageNum = this.goPage
  323. this.getArticalData(this.requestParams)
  324. } else {
  325. this.goPage = 1
  326. alert('输入页数有误!')
  327. }
  328. },
  329. currentChange: function (res) {
  330. this.requestParams.pageNum = res
  331. this.getArticalData(this.requestParams)
  332. },
  333. //申请试用
  334. goApply: function () {
  335. this.centerDialogVisible = true
  336. },
  337. lazyFunc: function () {
  338. setTimeout(function () {
  339. // 1 获取全部图片的DOM节点
  340. // 注意:querySelectorAll 值为伪数组利用扩展运算符转为真数组
  341. const images = $('.lazyContainer img')
  342. // 2 监听页面滚动事件
  343. window.addEventListener('scroll', lazyLoad)
  344. // 3 定义页面滚动的处理函数
  345. function lazyLoad() {
  346. for (let i = 0; i < images.length; i++) {
  347. // isVisible是否该图片位于可视区域 返回true 或false
  348. if (isVisible(images[i])) {
  349. // 将元素的自定义属性 data-src 赋值给元素的 src 属性
  350. // dataset.src 此为元素的自定义属性 data-src
  351. if(images[i].dataset.src){
  352. images[i].src = images[i].dataset.src // 等价于:img.setAttribute('src', img.getAttribute('data-src'))
  353. }
  354. // 防止重复被遍历 加载完之后 删除元素不再加载
  355. images.splice(i, 1)
  356. i--
  357. }
  358. }
  359. }
  360. lazyLoad()
  361. // 4 可视区域判断函数
  362. function isVisible(img) {
  363. // 判断是否在可视区域
  364. const imgRect = img.getBoundingClientRect() // getBoundingClientRect 获取图片的动态信息
  365. return imgRect.bottom > 0 && imgRect.top < window.innerHeight && imgRect.right > 0 && imgRect.left < window.innerWidth
  366. }
  367. }, 100)
  368. },
  369. //弹框显示隐藏(子组件向父组件传值)
  370. handleChildEvent: function (value) {
  371. this.centerDialogVisible = value; // 处理从子组件接收到的数据
  372. },
  373. // 排序
  374. compare(property) {
  375. return function (a, b) {
  376. var value1 = a[property];
  377. var value2 = b[property];
  378. return value1 - value2;
  379. }
  380. },
  381. // 获取路由参数
  382. getQuery(name) {
  383. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  384. var r = window.location.search.substr(1).match(reg);
  385. if (r != null) return decodeURI(r[2]);
  386. return null;
  387. },
  388. //获得年月日时分秒 //传入日期//例:2020-10-27T14:36:23
  389. timeFormatSeconds(time) {
  390. var d = time ? new Date(time) : new Date();
  391. var year = d.getFullYear();
  392. var month = d.getMonth() + 1;
  393. var day = d.getDate();
  394. var hours = d.getHours();
  395. var min = d.getMinutes();
  396. var seconds = d.getSeconds();
  397. if (month < 10) month = '0' + month;
  398. if (day < 10) day = '0' + day;
  399. if (hours < 0) hours = '0' + hours;
  400. if (min < 10) min = '0' + min;
  401. if (seconds < 10) seconds = '0' + seconds;
  402. return (year + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + seconds);
  403. }
  404. }
  405. }
  406. Vue.createApp(App).use(ElementPlus).mount("#app");