commonVue.js 8.0 KB

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