commonVue.js 11 KB

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