commonVue.js 15 KB

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