commonVue.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. columnImage: '', //栏目图片
  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('id') ? this.getQuery('id') : ''
  84. this.requestParams.title = this.getQuery('title') ? this.getQuery('title') : ''
  85. this.requestParams.articleid = this.getQuery('articleid') ? this.getQuery('articleid') : ''
  86. },
  87. mounted: function () {
  88. this.getColumnData()
  89. },
  90. methods: {
  91. //获取栏目
  92. getColumnData() {
  93. var _this = this
  94. this.columnTypes = []
  95. $.ajax({
  96. type: 'get',
  97. dataType: 'json',
  98. url: window.FQDN2 + 'siteCategory/siteCategoryList',
  99. }).done(function (res) {
  100. _this.loading = false;
  101. _this.columnList = res.data;
  102. _this.currentPath = window.location.pathname;
  103. for (let i = 0; i < res.data.length; i++) {
  104. //栏目处理
  105. if (res.data[i].sname == window.location.pathname) {
  106. //进入当前栏目页
  107. getSeoCommon()
  108. _this.columnTypes = res.data[i].children
  109. _this.colL= _this.columnTypes.childten;
  110. if (res.data[i].children.length > 0) {
  111. _this.requestParams.categoryid = (_this.getQuery('isUrlId') == 1) ? _this.getQuery('id') : _this.columnTypes[0].id;
  112. } else {
  113. var objData = _this.columnList.filter(obj => obj.sname == window.location.pathname);
  114. _this.requestParams.categoryid=objData[0].id
  115. }
  116. _this.getArticalData(_this.requestParams)
  117. _this.columnImage = res.data[i].imagePath;
  118. } else {
  119. // 进入详情页
  120. if (res.data[i].sname == '/product/index.html' && window.location.pathname == '/product/read.html') {
  121. getDetailCommon()
  122. getSeoCommon()
  123. }
  124. if (res.data[i].sname == '/solution/index.html' && window.location.pathname == '/solution/read.html') {
  125. getDetailCommon()
  126. getSeoCommon()
  127. }
  128. if (res.data[i].sname == '/news/index.html' && window.location.pathname == '/news/read.html') {
  129. getDetailCommon()
  130. getSeoCommon()
  131. }
  132. function getDetailCommon(){
  133. //获取内容详情
  134. _this.getArticalData(_this.requestParams)
  135. //获取详情相关数据
  136. setTimeout(() => {
  137. _this.requestParams.title = ''
  138. _this.requestParams.articleid = 0
  139. _this.getArticalData(_this.requestParams, 1)
  140. }, 100)
  141. _this.currentPath = res.data[i].sname //产品详情时栏目高亮
  142. _this.columnImage = res.data[i].imagePath; //栏目图片获取
  143. }
  144. }
  145. function getSeoCommon(){
  146. $('title').text(res.data[i].categoryName);
  147. $('meta[name="description"]').attr('content', res.data[i].metadescription);
  148. $('meta[name="keywords"]').attr('content',res.data[i].metakeywords);
  149. }
  150. //首页旧
  151. if (res.data[i].sname == '/index.html' && (window.location.pathname == '/index.html'||window.location.pathname == '/')) {
  152. jQuery.ajax({
  153. type: 'POST',
  154. dataType: 'json',
  155. url: window.FQDN + 'Index/index',
  156. }).done(function (res) {
  157. // _this.loading = false;
  158. _this.homeList = res
  159. _this.status = true
  160. }).fail(function (err) {});
  161. }
  162. // 获取反馈弹框类型数据
  163. if (res.data[i].sname == '/solution/index.html') {
  164. _this.dialogDataArray = (res.data[i].children)
  165. _this.ruleForm.platName = _this.dialogDataArray[0].categoryName;
  166. }
  167. }
  168. })
  169. },
  170. //获取内容
  171. getArticalData(requestParams, type) {
  172. var _this=this
  173. if( window.location.pathname == '/news/index.html'){
  174. _this.requestParams.order = ''
  175. }
  176. $.ajax({
  177. type: 'GET',
  178. dataType: 'json',
  179. url: window.FQDN2 + 'siteArticle/siteArticleList',
  180. data: requestParams
  181. }).done(function (res) {
  182. var aa
  183. var bb
  184. if(type==1){
  185. bb=res.data.records
  186. }else{
  187. aa= res.data.records;
  188. // aa.sort(_this.compare("sortindex"))
  189. _this.articalArray = aa;
  190. }
  191. if (bb) {
  192. console.log(bb)
  193. console.log(_this.articalArray[0])
  194. _this.articalArrayRelated = bb.filter(obj => obj.title != _this.articalArray[0].title);
  195. // _this.articalArrayRelated = bb
  196. console.log(_this.articalArrayRelated)
  197. }
  198. // _this.loading = false;
  199. _this.totalPageSzie = res.data.total
  200. _this.totalPageNum = Math.ceil(res.data.total / res.data.size);
  201. }).fail(function (err) {});
  202. },
  203. //类型点击
  204. facilityClick(e, item) {
  205. this.requestParams.categoryid = item.id
  206. this.requestParams.pageNum = 1
  207. this.getArticalData(this.requestParams)
  208. },
  209. // 分页
  210. oneInnerBox: function (param) {
  211. window.location = "./read.html?id=" + param.categoryid + "&title=" + param.title + "&articleid=" + param.id + "&isUrlId=1";
  212. },
  213. enterPage: function (res) {
  214. if (this.goPage >= 1 && this.goPage <= this.totalPageNum) {
  215. this.requestParams.pageNum = this.goPage
  216. this.getArticalData(this.requestParams)
  217. } else {
  218. this.goPage = 1
  219. alert('输入页数有误!')
  220. }
  221. },
  222. currentChange: function (res) {
  223. this.requestParams.pageNum = res
  224. this.getArticalData(this.requestParams)
  225. },
  226. //申请试用
  227. goApply:function(){
  228. this.centerDialogVisible=true
  229. },
  230. //弹框显示隐藏(子组件向父组件传值)
  231. handleChildEvent:function(value) {
  232. this.centerDialogVisible = value; // 处理从子组件接收到的数据
  233. },
  234. // 排序
  235. compare(property) {
  236. return function (a, b) {
  237. var value1 = a[property];
  238. var value2 = b[property];
  239. return value1 - value2;
  240. }
  241. },
  242. // 获取路由参数
  243. getQuery(name) {
  244. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  245. var r = window.location.search.substr(1).match(reg);
  246. if (r != null) return decodeURI(r[2]);
  247. return null;
  248. },
  249. //获得年月日时分秒 //传入日期//例:2020-10-27T14:36:23
  250. timeFormatSeconds(time) {
  251. var d = time ? new Date(time) : new Date();
  252. var year = d.getFullYear();
  253. var month = d.getMonth() + 1;
  254. var day = d.getDate();
  255. var hours = d.getHours();
  256. var min = d.getMinutes();
  257. var seconds = d.getSeconds();
  258. if (month < 10) month = '0' + month;
  259. if (day < 10) day = '0' + day;
  260. if (hours < 0) hours = '0' + hours;
  261. if (min < 10) min = '0' + min;
  262. if (seconds < 10) seconds = '0' + seconds;
  263. return (year + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + seconds);
  264. }
  265. }
  266. });