commonVue.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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.columnList = res.data;
  106. let expires = Date.now() + 1000 * 60 * 30; //半小时过期时间
  107. localStorage.setItem('storeColumnList', JSON.stringify({
  108. data: _this.columnList,
  109. expires
  110. }));
  111. _this.loading = false
  112. _this.currentPath = window.location.pathname;
  113. _this.handleColumnData()
  114. })
  115. } else {
  116. this.loading = false;
  117. this.handleColumnData()
  118. }
  119. setTimeout(function(){
  120. _this.contentBoolean=true
  121. },1500)
  122. setTimeout(function(){
  123. _this.footerBoolean=true
  124. },2000)
  125. },
  126. handleColumnData() {
  127. this.currentPath = window.location.pathname;
  128. this.columnList = JSON.parse(localStorage.getItem('storeColumnList')).data;
  129. // 读取并检查是否过期
  130. if (JSON.parse(localStorage.getItem('storeColumnList')).expires < Date.now()) {
  131. localStorage.removeItem('storeColumnList');
  132. } else {
  133. }
  134. var _this = this;
  135. for (let i = 0; i < _this.columnList.length; i++) {
  136. //栏目处理
  137. //进入首页
  138. if (_this.columnList[i].sname == '/' && (window.location.pathname == '/'||window.location.pathname == ''||window.location.pathname == '/index.html')) {
  139. getSeoCommon()
  140. this.requestParams.categoryid = this.columnList[0].id
  141. _this.modelType = _this.columnList[0].modelType;
  142. _this.columnImage = _this.columnList[0].imagePath;
  143. setTimeout(() => {
  144. if (_this.modelType == 2) {
  145. document.getElementById("videoPlay").src = _this.columnImage; //url为你需要播放的视频地址
  146. document.getElementById("videoPlay").setAttribute('poster', '/assets/img/banner/poster.jpg');
  147. }
  148. }, 100)
  149. _this.getArticalData(_this.requestParams)
  150. }
  151. //进入其他栏目页
  152. if ((_this.columnList[i].sname == window.location.pathname)||(_this.columnList[i].sname == window.location.pathname.replace('index.html', ''))) {
  153. getSeoCommon()
  154. _this.columnTypes = _this.columnList[i].children
  155. _this.colL = _this.columnTypes.childten;
  156. if (_this.columnList[i].children.length > 0) {
  157. _this.requestParams.categoryid = (_this.getQuery('isUrlId') == 1) ? _this.getQuery('categoryid') : _this.columnTypes[0].id;
  158. } else {
  159. var objData = _this.columnList.filter(obj => obj.sname == window.location.pathname.replace('index.html', ''));
  160. _this.requestParams.categoryid = objData[0].id
  161. }
  162. _this.getArticalData(_this.requestParams)
  163. _this.modelType = _this.columnList[i].modelType;
  164. _this.columnImage = _this.columnList[i].imagePath;
  165. setTimeout(() => {
  166. if (_this.modelType == 2) {
  167. document.getElementById("videoPlay").src = _this.columnImage; //url为你需要播放的视频地址
  168. document.getElementById("videoPlay").setAttribute('poster', '/assets/img/banner/poster.jpg');
  169. }
  170. }, 100)
  171. } else {
  172. // 进入详情页
  173. if (_this.columnList[i].sname == '/product/' && window.location.pathname == '/product/read.html') {
  174. getDetailCommon()
  175. getSeoCommon()
  176. }
  177. if (_this.columnList[i].sname == '/solution/' && window.location.pathname == '/solution/read.html') {
  178. getDetailCommon()
  179. getSeoCommon()
  180. }
  181. if (_this.columnList[i].sname == '/news/' && window.location.pathname == '/news/read.html') {
  182. getDetailCommon()
  183. getSeoCommon()
  184. }
  185. function getDetailCommon() {
  186. //获取内容详情
  187. _this.getArticalData(_this.requestParams)
  188. //获取详情相关数据
  189. setTimeout(() => {
  190. _this.requestParams.id = ''
  191. _this.requestParams.articleid = ''
  192. _this.getArticalData(_this.requestParams, 1)
  193. }, 100)
  194. _this.currentPath = _this.columnList[i].sname //产品详情时栏目高亮
  195. _this.modelType = _this.columnList[i].modelType; //栏目图片获取
  196. _this.columnImage = _this.columnList[i].imagePath; //栏目图片获取
  197. setTimeout(() => {
  198. if (_this.modelType == 2) {
  199. document.getElementById("videoPlay").src = _this.columnImage; //url为你需要播放的视频地址
  200. document.getElementById("videoPlay").setAttribute('poster', '/assets/img/banner/poster.jpg');
  201. }
  202. }, 100)
  203. }
  204. }
  205. function getSeoCommon() {
  206. $('title').text(_this.columnList[i].categoryName);
  207. $('meta[name="description"]').attr('content', _this.columnList[i].metadescription);
  208. $('meta[name="keywords"]').attr('content', _this.columnList[i].metakeywords);
  209. }
  210. // 获取反馈弹框类型数据
  211. if (_this.columnList[i].sname == '/solution/') {
  212. _this.dialogDataArray = (_this.columnList[i].children)
  213. _this.ruleForm.platName = _this.dialogDataArray[0].categoryName;
  214. }
  215. }
  216. },
  217. //获取内容
  218. getArticalData(requestParams, type) {
  219. var _this = this
  220. if (window.location.pathname == '/news/') {
  221. _this.requestParams.order = ''
  222. }
  223. $.ajax({
  224. type: 'GET',
  225. dataType: 'json',
  226. url: window.FQDN2 + 'siteArticle/siteArticleList',
  227. data: requestParams
  228. }).done(function (res) {
  229. var aa
  230. var bb
  231. if (type == 1) {
  232. bb = res.data.records
  233. } else {
  234. aa = res.data.records;
  235. _this.articalArray = aa;
  236. }
  237. if (bb) {
  238. _this.articalArrayRelated = bb.filter(obj => obj.title != _this.articalArray[0].title);
  239. // _this.articalArrayRelated = bb
  240. }
  241. // _this.loading = false;
  242. _this.totalPageSzie = res.data.total
  243. _this.totalPageNum = Math.ceil(res.data.total / res.data.size);
  244. }).fail(function (err) {});
  245. },
  246. //类型点击
  247. facilityClick(e, item) {
  248. this.requestParams.categoryid = item.id
  249. this.requestParams.pageNum = 1
  250. this.getArticalData(this.requestParams)
  251. },
  252. // 分页
  253. oneInnerBox: function (param) {
  254. window.location = "./read.html?categoryid=" + param.categoryid + "&id=" + param.id + "&isUrlId=1";
  255. },
  256. enterPage: function (res) {
  257. if (this.goPage >= 1 && this.goPage <= this.totalPageNum) {
  258. this.requestParams.pageNum = this.goPage
  259. this.getArticalData(this.requestParams)
  260. } else {
  261. this.goPage = 1
  262. alert('输入页数有误!')
  263. }
  264. },
  265. currentChange: function (res) {
  266. this.requestParams.pageNum = res
  267. this.getArticalData(this.requestParams)
  268. },
  269. //申请试用
  270. goApply: function () {
  271. this.centerDialogVisible = true
  272. },
  273. //弹框显示隐藏(子组件向父组件传值)
  274. handleChildEvent: function (value) {
  275. this.centerDialogVisible = value; // 处理从子组件接收到的数据
  276. },
  277. // 排序
  278. compare(property) {
  279. return function (a, b) {
  280. var value1 = a[property];
  281. var value2 = b[property];
  282. return value1 - value2;
  283. }
  284. },
  285. // 获取路由参数
  286. getQuery(name) {
  287. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  288. var r = window.location.search.substr(1).match(reg);
  289. if (r != null) return decodeURI(r[2]);
  290. return null;
  291. },
  292. //获得年月日时分秒 //传入日期//例:2020-10-27T14:36:23
  293. timeFormatSeconds(time) {
  294. var d = time ? new Date(time) : new Date();
  295. var year = d.getFullYear();
  296. var month = d.getMonth() + 1;
  297. var day = d.getDate();
  298. var hours = d.getHours();
  299. var min = d.getMinutes();
  300. var seconds = d.getSeconds();
  301. if (month < 10) month = '0' + month;
  302. if (day < 10) day = '0' + day;
  303. if (hours < 0) hours = '0' + hours;
  304. if (min < 10) min = '0' + min;
  305. if (seconds < 10) seconds = '0' + seconds;
  306. return (year + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + seconds);
  307. }
  308. }
  309. }
  310. Vue.createApp(App).use(ElementPlus).mount("#app");