commonVue.js 14 KB

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