commonVue.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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. var AboutKeyWrds = '';
  7. var app = new Vue({
  8. el: '#app',
  9. components: {
  10. footerCom,
  11. feedFix,
  12. dialogCom,
  13. loadingCom,
  14. headerCom
  15. },
  16. data: {
  17. //公共
  18. id: null,
  19. columnList: [],
  20. requestParams: { //内容接口请求参数
  21. categoryid: 0,
  22. pageNum: 1,
  23. pageSize: 9,
  24. title: '',
  25. order: 'sortindex',
  26. articleid: 0,
  27. },
  28. currentPath: '',
  29. articalArray: [], //详情数组
  30. articalArrayRelated: [], //相关推荐
  31. columnTypes: [], //栏目类型
  32. colL: 0,
  33. modelType: 1,
  34. columnImage: '', //栏目图片
  35. footerBoolean:false, //底部延时加载(解决页面闪烁)
  36. // 公共弹框
  37. centerDialogVisible: false,
  38. dialogDataArray: [],
  39. ruleForm: {
  40. platName: '智慧安防',
  41. consultName: '',
  42. consultPhone: '',
  43. mail: '',
  44. company: '',
  45. consultContent: "",
  46. },
  47. rules: {
  48. platName: [{
  49. required: true,
  50. message: '请选择类型',
  51. trigger: 'change'
  52. }, ],
  53. consultName: [{
  54. required: true,
  55. message: '请输入姓名',
  56. trigger: 'blur'
  57. }, ],
  58. consultPhone: [{
  59. required: true,
  60. message: '请输入正确的电话号码',
  61. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  62. trigger: 'change'
  63. }],
  64. mail: [{
  65. required: false,
  66. type: "email",
  67. message: "请输入正确的邮箱地址",
  68. trigger: 'blur'
  69. }],
  70. },
  71. //首页
  72. homeList: [],
  73. status: false,
  74. // 新闻
  75. goPage: 1,
  76. totalPageNum: 1,
  77. totalPageSzie: 1,
  78. loading: true,
  79. categoryid: 0,
  80. },
  81. computed: {
  82. },
  83. created: function () {
  84. this.requestParams.categoryid = this.getQuery('id') ? this.getQuery('id') : ''
  85. this.requestParams.title = this.getQuery('title') ? this.getQuery('title') : ''
  86. this.requestParams.articleid = this.getQuery('articleid') ? this.getQuery('articleid') : ''
  87. },
  88. mounted: function () {
  89. this.getColumnData()
  90. },
  91. methods: {
  92. //获取栏目数据
  93. getColumnData() {
  94. var _this = this;
  95. if (!localStorage.getItem('storeColumnList') || window.location.pathname == '/index.html' || window.location.pathname == '/') {
  96. $.ajax({
  97. type: 'get',
  98. dataType: 'json',
  99. url: window.FQDN2 + 'siteCategory/siteCategoryList',
  100. }).done(function (res) {
  101. _this.columnList = res.data;
  102. let expires = Date.now() + 1000 * 60 * 30; //半小时过期时间
  103. localStorage.setItem('storeColumnList', JSON.stringify({
  104. data: _this.columnList,
  105. expires
  106. }));
  107. _this.loading = false
  108. _this.currentPath = window.location.pathname;
  109. _this.handleColumnData()
  110. })
  111. } else {
  112. console.log(JSON.parse(localStorage.getItem('storeColumnList')))
  113. this.loading = false;
  114. this.handleColumnData()
  115. }
  116. setTimeout(function(){
  117. _this.footerBoolean=true
  118. },1000)
  119. },
  120. handleColumnData() {
  121. this.currentPath = window.location.pathname;
  122. this.columnList = JSON.parse(localStorage.getItem('storeColumnList')).data;
  123. console.log(JSON.parse(localStorage.getItem('storeColumnList')))
  124. console.log(Date.now())
  125. // 读取并检查是否过期
  126. if (JSON.parse(localStorage.getItem('storeColumnList')).expires < Date.now()) {
  127. localStorage.removeItem('storeColumnList');
  128. } else {
  129. console.log(this.columnList);
  130. }
  131. var _this = this;
  132. for (let i = 0; i < _this.columnList.length; i++) {
  133. //栏目处理
  134. //进入首页
  135. if (_this.columnList[i].sname == '/index.html' && (window.location.pathname == '/'||window.location.pathname == '')) {
  136. getSeoCommon()
  137. this.requestParams.categoryid = this.columnList[0].id
  138. _this.modelType = _this.columnList[0].modelType;
  139. _this.columnImage = _this.columnList[0].imagePath;
  140. setTimeout(() => {
  141. if (_this.modelType == 2) {
  142. document.getElementById("videoPlay").src = _this.columnImage; //url为你需要播放的视频地址
  143. document.getElementById("videoPlay").setAttribute('poster', '/assets/img/banner/111.png');
  144. }
  145. }, 100)
  146. _this.getArticalData(_this.requestParams)
  147. }
  148. //进入其他栏目页
  149. if ((_this.columnList[i].sname == window.location.pathname)) {
  150. getSeoCommon()
  151. _this.columnTypes = _this.columnList[i].children
  152. _this.colL = _this.columnTypes.childten;
  153. if (_this.columnList[i].children.length > 0) {
  154. _this.requestParams.categoryid = (_this.getQuery('isUrlId') == 1) ? _this.getQuery('id') : _this.columnTypes[0].id;
  155. } else {
  156. var objData = _this.columnList.filter(obj => obj.sname == window.location.pathname);
  157. _this.requestParams.categoryid = objData[0].id
  158. }
  159. _this.getArticalData(_this.requestParams)
  160. _this.modelType = _this.columnList[i].modelType;
  161. _this.columnImage = _this.columnList[i].imagePath;
  162. setTimeout(() => {
  163. if (_this.modelType == 2) {
  164. document.getElementById("videoPlay").src = _this.columnImage; //url为你需要播放的视频地址
  165. document.getElementById("videoPlay").setAttribute('poster', '/assets/img/banner/111.png');
  166. }
  167. }, 100)
  168. } else {
  169. // 进入详情页
  170. if (_this.columnList[i].sname == '/product/index.html' && window.location.pathname == '/product/read.html') {
  171. getDetailCommon()
  172. getSeoCommon()
  173. }
  174. if (_this.columnList[i].sname == '/solution/index.html' && window.location.pathname == '/solution/read.html') {
  175. getDetailCommon()
  176. getSeoCommon()
  177. }
  178. if (_this.columnList[i].sname == '/news/index.html' && window.location.pathname == '/news/read.html') {
  179. getDetailCommon()
  180. getSeoCommon()
  181. }
  182. function getDetailCommon() {
  183. //获取内容详情
  184. _this.getArticalData(_this.requestParams)
  185. //获取详情相关数据
  186. setTimeout(() => {
  187. _this.requestParams.title = ''
  188. _this.requestParams.articleid = 0
  189. _this.getArticalData(_this.requestParams, 1)
  190. }, 100)
  191. _this.currentPath = _this.columnList[i].sname //产品详情时栏目高亮
  192. _this.modelType = _this.columnList[i].modelType; //栏目图片获取
  193. _this.columnImage = _this.columnList[i].imagePath; //栏目图片获取
  194. setTimeout(() => {
  195. if (_this.modelType == 2) {
  196. document.getElementById("videoPlay").src = _this.columnImage; //url为你需要播放的视频地址
  197. document.getElementById("videoPlay").setAttribute('poster', '/assets/img/banner/111.png');
  198. }
  199. }, 100)
  200. }
  201. }
  202. function getSeoCommon() {
  203. $('title').text(_this.columnList[i].categoryName);
  204. $('meta[name="description"]').attr('content', _this.columnList[i].metadescription);
  205. $('meta[name="keywords"]').attr('content', _this.columnList[i].metakeywords);
  206. }
  207. // 获取反馈弹框类型数据
  208. if (_this.columnList[i].sname == '/solution/index.html') {
  209. _this.dialogDataArray = (_this.columnList[i].children)
  210. _this.ruleForm.platName = _this.dialogDataArray[0].categoryName;
  211. }
  212. }
  213. },
  214. //获取内容
  215. getArticalData(requestParams, type) {
  216. var _this = this
  217. if (window.location.pathname == '/news/index.html') {
  218. _this.requestParams.order = ''
  219. }
  220. $.ajax({
  221. type: 'GET',
  222. dataType: 'json',
  223. url: window.FQDN2 + 'siteArticle/siteArticleList',
  224. data: requestParams
  225. }).done(function (res) {
  226. var aa
  227. var bb
  228. if (type == 1) {
  229. bb = res.data.records
  230. } else {
  231. aa = res.data.records;
  232. // aa.sort(_this.compare("sortindex"))
  233. _this.articalArray = aa;
  234. }
  235. if (bb) {
  236. console.log(bb)
  237. console.log(_this.articalArray[0])
  238. _this.articalArrayRelated = bb.filter(obj => obj.title != _this.articalArray[0].title);
  239. _this.articalArrayRelated = bb
  240. console.log(_this.articalArrayRelated)
  241. }
  242. // _this.loading = false;
  243. _this.totalPageSzie = res.data.total
  244. _this.totalPageNum = Math.ceil(res.data.total / res.data.size);
  245. }).fail(function (err) {});
  246. },
  247. //类型点击
  248. facilityClick(e, item) {
  249. this.requestParams.categoryid = item.id
  250. this.requestParams.pageNum = 1
  251. this.getArticalData(this.requestParams)
  252. },
  253. // 分页
  254. oneInnerBox: function (param) {
  255. window.location = "./read.html?id=" + param.categoryid + "&title=" + param.title + "&articleid=" + param.id + "&isUrlId=1";
  256. },
  257. enterPage: function (res) {
  258. if (this.goPage >= 1 && this.goPage <= this.totalPageNum) {
  259. this.requestParams.pageNum = this.goPage
  260. this.getArticalData(this.requestParams)
  261. } else {
  262. this.goPage = 1
  263. alert('输入页数有误!')
  264. }
  265. },
  266. currentChange: function (res) {
  267. this.requestParams.pageNum = res
  268. this.getArticalData(this.requestParams)
  269. },
  270. //申请试用
  271. goApply: function () {
  272. this.centerDialogVisible = true
  273. },
  274. //弹框显示隐藏(子组件向父组件传值)
  275. handleChildEvent: function (value) {
  276. this.centerDialogVisible = value; // 处理从子组件接收到的数据
  277. },
  278. // 排序
  279. compare(property) {
  280. return function (a, b) {
  281. var value1 = a[property];
  282. var value2 = b[property];
  283. return value1 - value2;
  284. }
  285. },
  286. // 获取路由参数
  287. getQuery(name) {
  288. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  289. var r = window.location.search.substr(1).match(reg);
  290. if (r != null) return decodeURI(r[2]);
  291. return null;
  292. },
  293. //获得年月日时分秒 //传入日期//例:2020-10-27T14:36:23
  294. timeFormatSeconds(time) {
  295. var d = time ? new Date(time) : new Date();
  296. var year = d.getFullYear();
  297. var month = d.getMonth() + 1;
  298. var day = d.getDate();
  299. var hours = d.getHours();
  300. var min = d.getMinutes();
  301. var seconds = d.getSeconds();
  302. if (month < 10) month = '0' + month;
  303. if (day < 10) day = '0' + day;
  304. if (hours < 0) hours = '0' + hours;
  305. if (min < 10) min = '0' + min;
  306. if (seconds < 10) seconds = '0' + seconds;
  307. return (year + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + seconds);
  308. }
  309. }
  310. });