commonVue.js 8.0 KB

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