commonVue.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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 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. ],
  20. requestParams: { //内容接口请求参数
  21. categoryid: 0,
  22. pageNum: 1,
  23. pageSize: 9,
  24. title: '',
  25. order:'sortindex',
  26. articleid:0,
  27. },
  28. currentPath: '',
  29. articalArray: [], //详情数组
  30. articalArrayRelated: [], //相关推荐
  31. columnTypes: [], //栏目类型
  32. colL:0,
  33. columnImage: '', //栏目图片
  34. // 公共弹框
  35. centerDialogVisible: false,
  36. dialogDataArray: [],
  37. ruleForm: {
  38. platName: '智慧安防',
  39. consultName: '',
  40. consultPhone: '',
  41. mail: '',
  42. company: '',
  43. consultContent: "",
  44. },
  45. rules: {
  46. platName: [{
  47. required: true,
  48. message: '请选择类型',
  49. trigger: 'change'
  50. }, ],
  51. consultName: [{
  52. required: true,
  53. message: '请输入姓名',
  54. trigger: 'blur'
  55. }, ],
  56. consultPhone: [{
  57. required: true,
  58. message: '请输入正确的电话号码',
  59. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  60. trigger: 'change'
  61. }],
  62. mail: [{
  63. required: false,
  64. type: "email",
  65. message: "请输入正确的邮箱地址",
  66. trigger: 'blur'
  67. }],
  68. },
  69. //首页
  70. homeList: [],
  71. status: false,
  72. // 新闻
  73. goPage: 1,
  74. totalPageNum: 1,
  75. totalPageSzie: 1,
  76. loading: true,
  77. categoryid: 0,
  78. },
  79. computed: {
  80. },
  81. created: function () {
  82. this.requestParams.categoryid = this.getQuery('id') ? this.getQuery('id') : ''
  83. this.requestParams.title = this.getQuery('title') ? this.getQuery('title') : ''
  84. this.requestParams.articleid = this.getQuery('articleid') ? this.getQuery('articleid') : ''
  85. },
  86. mounted: function () {
  87. this.getColumnData()
  88. },
  89. methods: {
  90. //获取栏目
  91. getColumnData() {
  92. var _this = this
  93. this.columnTypes = []
  94. $.ajax({
  95. type: 'get',
  96. dataType: 'json',
  97. url: window.FQDN2 + 'siteCategory/siteCategoryList',
  98. }).done(function (res) {
  99. _this.loading = false;
  100. _this.columnList = res.data;
  101. _this.currentPath = window.location.pathname;
  102. for (let i = 0; i < res.data.length; i++) {
  103. //栏目处理
  104. if (res.data[i].sname == window.location.pathname) {
  105. //进入当前栏目页
  106. _this.columnTypes = res.data[i].children
  107. _this.colL= _this.columnTypes.childten;
  108. if (res.data[i].children.length > 0) {
  109. _this.requestParams.categoryid = (_this.getQuery('isUrlId') == 1) ? _this.getQuery('id') : _this.columnTypes[0].id;
  110. } else {
  111. _this.requestParams.categoryid = _this.getQuery('id')
  112. }
  113. _this.getArticalData(_this.requestParams)
  114. _this.columnImage = res.data[i].imagePath;
  115. } else {
  116. // 进入详情页
  117. if (res.data[i].sname == '/product/index.html' && window.location.pathname == '/product/read.html') {
  118. getDetailCommon()
  119. }
  120. if (res.data[i].sname == '/solution/index.html' && window.location.pathname == '/solution/read.html') {
  121. getDetailCommon()
  122. }
  123. if (res.data[i].sname == '/news/index.html' && window.location.pathname == '/news/read.html') {
  124. getDetailCommon()
  125. }
  126. function getDetailCommon(){
  127. //获取内容详情
  128. _this.getArticalData(_this.requestParams)
  129. //获取详情相关数据
  130. setTimeout(() => {
  131. _this.requestParams.title = ''
  132. _this.requestParams.articleid = 0
  133. _this.getArticalData(_this.requestParams, 1)
  134. }, 100)
  135. _this.currentPath = res.data[i].sname //产品详情时栏目高亮
  136. _this.columnImage = res.data[i].imagePath; //栏目图片获取
  137. }
  138. }
  139. //首页旧
  140. if (res.data[i].sname == '/index.html' && (window.location.pathname == '/index.html'||window.location.pathname == '/')) {
  141. jQuery.ajax({
  142. type: 'POST',
  143. dataType: 'json',
  144. url: window.FQDN + 'Index/index',
  145. }).done(function (res) {
  146. // _this.loading = false;
  147. _this.homeList = res
  148. _this.status = true
  149. }).fail(function (err) {});
  150. }
  151. // 获取反馈弹框类型数据
  152. if (res.data[i].sname == '/solution/index.html') {
  153. _this.dialogDataArray = (res.data[i].children)
  154. _this.ruleForm.platName = _this.dialogDataArray[0].categoryName;
  155. }
  156. }
  157. })
  158. },
  159. //获取内容
  160. getArticalData(requestParams, type) {
  161. var _this=this
  162. if( window.location.pathname == '/news/index.html'){
  163. _this.requestParams.order = ''
  164. }
  165. $.ajax({
  166. type: 'GET',
  167. dataType: 'json',
  168. url: window.FQDN2 + 'siteArticle/siteArticleList',
  169. data: requestParams
  170. }).done(function (res) {
  171. var aa
  172. var bb
  173. if(type==1){
  174. bb=res.data.records
  175. }else{
  176. aa= res.data.records;
  177. // aa.sort(_this.compare("sortindex"))
  178. _this.articalArray = aa;
  179. }
  180. if (bb) {
  181. console.log(bb)
  182. console.log(_this.articalArray[0])
  183. _this.articalArrayRelated = bb.filter(obj => obj.title != _this.articalArray[0].title);
  184. // _this.articalArrayRelated = bb
  185. console.log(_this.articalArrayRelated)
  186. }
  187. // _this.loading = false;
  188. _this.totalPageSzie = res.data.total
  189. _this.totalPageNum = Math.ceil(res.data.total / res.data.size);
  190. }).fail(function (err) {});
  191. },
  192. //类型点击
  193. facilityClick(e, item) {
  194. this.requestParams.categoryid = item.id
  195. this.requestParams.pageNum = 1
  196. this.getArticalData(this.requestParams)
  197. },
  198. // 分页
  199. oneInnerBox: function (param) {
  200. window.location = "./read.html?id=" + param.categoryid + "&title=" + param.title + "&articleid=" + param.id + "&isUrlId=1";
  201. },
  202. enterPage: function (res) {
  203. if (this.goPage >= 1 && this.goPage <= this.totalPageNum) {
  204. this.requestParams.pageNum = this.goPage
  205. this.getArticalData(this.requestParams)
  206. } else {
  207. this.goPage = 1
  208. alert('输入页数有误!')
  209. }
  210. },
  211. currentChange: function (res) {
  212. this.requestParams.pageNum = res
  213. this.getArticalData(this.requestParams)
  214. },
  215. //申请试用
  216. goApply:function(){
  217. this.centerDialogVisible=true
  218. },
  219. //弹框显示隐藏(子组件向父组件传值)
  220. handleChildEvent:function(value) {
  221. this.centerDialogVisible = value; // 处理从子组件接收到的数据
  222. },
  223. // 排序
  224. compare(property) {
  225. return function (a, b) {
  226. var value1 = a[property];
  227. var value2 = b[property];
  228. return value1 - value2;
  229. }
  230. },
  231. // 获取路由参数
  232. getQuery(name) {
  233. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  234. var r = window.location.search.substr(1).match(reg);
  235. if (r != null) return decodeURI(r[2]);
  236. return null;
  237. },
  238. //获得年月日时分秒 //传入日期//例:2020-10-27T14:36:23
  239. timeFormatSeconds(time) {
  240. var d = time ? new Date(time) : new Date();
  241. var year = d.getFullYear();
  242. var month = d.getMonth() + 1;
  243. var day = d.getDate();
  244. var hours = d.getHours();
  245. var min = d.getMinutes();
  246. var seconds = d.getSeconds();
  247. if (month < 10) month = '0' + month;
  248. if (day < 10) day = '0' + day;
  249. if (hours < 0) hours = '0' + hours;
  250. if (min < 10) min = '0' + min;
  251. if (seconds < 10) seconds = '0' + seconds;
  252. return (year + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + seconds);
  253. }
  254. }
  255. });