commonVue.js 8.7 KB

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