commonVue.js 8.7 KB

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