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