commonVue.js 8.4 KB

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