commonVue.js 13 KB

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