commonVue copy.js 10 KB

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