commonVue.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. // 定义一个名为 button-counter 的新组件
  2. Vue.component('button-counter', {
  3. props: ['title'],
  4. data() {
  5. return {
  6. count: 0
  7. }
  8. },
  9. methods: {
  10. addCount() {
  11. this.count++
  12. }
  13. },
  14. template: '<button @click="addCount">{{ title }} : You clicked me {{ count }} times.</button>'
  15. })
  16. var app = new Vue({
  17. el: '#app',
  18. data: {
  19. //公共
  20. id: null,
  21. columnList: [],
  22. currentPath: '',
  23. articalArray: [], //详情数组
  24. columnTypes: [], //栏目类型
  25. // 公共弹框
  26. centerDialogVisible: false,
  27. dialogDataArray:[],
  28. ruleForm: {
  29. platName: '智慧安防',
  30. consultName: '',
  31. consultPhone: '',
  32. mail: '',
  33. company: '',
  34. consultContent: "",
  35. },
  36. rules: {
  37. platName: [{
  38. required: true,
  39. message: '请选择类型',
  40. trigger: 'change'
  41. },
  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. news: [],
  66. goPage: 1,
  67. one_page_size: 9,
  68. currentPageNum: 1,
  69. totalPageNum: 1,
  70. totalPageSzie: 4,
  71. loading: true,
  72. //解决方案旧
  73. array: [],
  74. //新闻详情旧
  75. articleInfo: {},
  76. previousInfo: {},
  77. nextInfo: {},
  78. relativeArr: [],
  79. ariticle_id: 0,
  80. },
  81. computed: {
  82. // 新闻详情旧
  83. isNews: function () {
  84. return (this.articleInfo.type == 1);
  85. },
  86. hasPrevious: function () {
  87. return Object.keys(this.previousInfo).length > 0;
  88. },
  89. hasNext: function () {
  90. return Object.keys(this.nextInfo).length > 0;
  91. }
  92. },
  93. created: function () {
  94. this.ariticle_id = this.getQuery('id')
  95. this.title = this.getQuery('title') ? this.getQuery('title') : ''
  96. },
  97. mounted: function () {
  98. _this = this
  99. this.getColumnData()
  100. },
  101. methods: {
  102. //获取栏目
  103. getColumnData() {
  104. this.columnTypes = []
  105. $.ajax({
  106. type: 'get',
  107. dataType: 'json',
  108. url: window.FQDN2 + 'siteCategory/siteCategoryList',
  109. }).done(function (res) {
  110. _this.columnList = res.data;
  111. _this.currentPath = window.location.pathname
  112. for (let i = 0; i < res.data.length; i++) {
  113. // console.log(res.data[i].sname)
  114. // console.log(window.location.pathname)
  115. if (res.data[i].categoryName == '首页' && window.location.pathname == '/index.html') {
  116. //首页旧
  117. jQuery.ajax({
  118. type: 'POST',
  119. dataType: 'json',
  120. url: window.FQDN + 'Index/index',
  121. }).done(function (res) {
  122. _this.homeList = res
  123. _this.status = true
  124. }).fail(function (err) {});
  125. }
  126. if (res.data[i].categoryName == '产品服务' && window.location.pathname == '/product/read.html') {
  127. _this.currentPath = '/product/index.html' //产品详情时栏目高亮
  128. }
  129. if (res.data[i].categoryName == '解决方案') {
  130. _this.dialogDataArray=(res.data[i].children)
  131. _this.ruleForm.platName= _this.dialogDataArray[0].categoryName
  132. }
  133. if (res.data[i].categoryName == '新闻动态' && window.location.pathname == '/news/read.html') {
  134. _this.currentPath = '/news/index.html' //新闻详情时栏目高亮
  135. //新闻详情旧
  136. jQuery.ajax({
  137. type: 'POST',
  138. dataType: 'json',
  139. url: window.FQDN + 'agw/journalism_details',
  140. data: {
  141. id: 154
  142. }
  143. }).done(function (res) {
  144. if (!res.msg) {
  145. return;
  146. }
  147. _this.loading = false;
  148. _this.articleInfo = res;
  149. _this.relativeArr = res.related;
  150. console.log(_this.relativeArr)
  151. if (res.previous != null) {
  152. _this.previousInfo = res.previous;
  153. }
  154. if (res.next != null) {
  155. _this.nextInfo = res.next;
  156. }
  157. }).fail(function (err) {});
  158. }
  159. if (res.data[i].categoryName == '关于永天' && window.location.pathname.indexOf('about') > -1) {
  160. _this.columnTypes = res.data[i].children
  161. _this.getArticalData(_this.getQuery('id'))
  162. //关于永天旧
  163. $.ajax({
  164. type: 'POST',
  165. dataType: 'json',
  166. url: window.FQDN + 'Aboutus/index',
  167. }).done(function (arr) {
  168. // console.log(arr)
  169. _this.array = arr;
  170. }).fail(function (err) {});
  171. }
  172. if (res.data[i].children.length > 0) {
  173. if (res.data[i].categoryName == '解决方案' && window.location.pathname.indexOf('solution') > -1) {
  174. _this.columnTypes = res.data[i].children
  175. _this.id = (_this.getQuery('isTwo') == 1) ? _this.getQuery('id') : _this.columnTypes[0].id;
  176. _this.getArticalData(_this.id)
  177. //解决方案旧
  178. $.ajax({
  179. type: 'POST',
  180. dataType: 'json',
  181. url: window.FQDN + 'Solution/index',
  182. data: {
  183. id: '1'
  184. }
  185. }).done(function (arr) {
  186. _this.array = arr;
  187. console.log(_this.array)
  188. }).fail(function (err) {});
  189. }
  190. if (res.data[i].categoryName == '新闻动态' && window.location.pathname.indexOf('news') > -1) {
  191. _this.columnTypes = res.data[i].children
  192. _this.id = (_this.getQuery('isTwo') == 1) ? _this.getQuery('id') : _this.columnTypes[0].id;
  193. _this.getArticalData(_this.id)
  194. }
  195. if (res.data[i].categoryName == '产品服务' && window.location.pathname.indexOf('product') > -1) {
  196. _this.columnTypes = res.data[i].children
  197. _this.id = (_this.getQuery('isTwo') == 1) ? _this.getQuery('id') : _this.columnTypes[0].id;
  198. _this.getArticalData(_this.id)
  199. }
  200. }
  201. }
  202. })
  203. },
  204. //获取内容
  205. getArticalData(param) {
  206. $.ajax({
  207. type: 'GET',
  208. dataType: 'json',
  209. url: window.FQDN2 + 'siteArticle/siteArticleList',
  210. data: {
  211. categoryid: param,
  212. pageNum: _this.currentPageNum,
  213. pageSize: _this.one_page_size,
  214. title: _this.title
  215. }
  216. }).done(function (res) {
  217. var aa = res.data.records;
  218. aa.sort(_this.compare("lmtitle"))
  219. _this.loading = false;
  220. _this.articalArray = aa;
  221. _this.totalPageSzie = res.data.total
  222. _this.totalPageNum = Math.ceil(res.data.total / res.data.size);
  223. console.log(aa)
  224. }).fail(function (err) {});
  225. },
  226. //类型点击
  227. facilityClick(e, item) {
  228. this.id = item.id
  229. this.getArticalData(item.id)
  230. this.currentPageNum = 1
  231. // console.log(item.id)
  232. },
  233. // 分页
  234. oneInnerBox: function (param) {
  235. window.location = "./read.html?id=" + param.categoryid + '&title=' + param.title;
  236. // window.location = "./read.html?id=154"
  237. },
  238. enterPage: function (res) {
  239. if (this.goPage >= 1 && this.goPage <= this.totalPageNum) {
  240. this.currentPageNum = this.goPage
  241. this.getArticalData(this.id)
  242. } else {
  243. this.goPage = 1
  244. alert('输入页数有误!')
  245. }
  246. },
  247. currentChange: function (res) {
  248. this.currentPageNum = res
  249. this.getArticalData(this.id)
  250. },
  251. //首页
  252. scrollToTop() {
  253. window.scrollTo({
  254. top: 0,
  255. behavior: "smooth"
  256. });
  257. },
  258. //公共弹框
  259. submitForm(formName) {
  260. _this = this
  261. this.$refs[formName].validate((valid) => {
  262. if (valid) {
  263. console.log(_this.ruleForm)
  264. let param = JSON.stringify(_this.ruleForm)
  265. jQuery.ajax({
  266. type: 'POST',
  267. // dataType: 'json',
  268. contentType: 'application/json;charset=UTF-8',
  269. url: window.FQDN2 + 'siteReview',
  270. data: param
  271. }).done(function (res) {
  272. if (res.status === "SUCCESS") {
  273. _this.$message({
  274. message: '提交成功',
  275. type: 'success'
  276. });
  277. _this.centerDialogVisible = false
  278. _this.$refs[formName].resetFields(); //重置from校验
  279. }
  280. }).fail(function (err) {});
  281. } else {
  282. console.log('error submit!!');
  283. return false;
  284. }
  285. });
  286. },
  287. resetForm(formName) {
  288. this.$refs[formName].resetFields();
  289. this.centerDialogVisible = false
  290. },
  291. // 排序
  292. compare(property) {
  293. return function (a, b) {
  294. var value1 = a[property];
  295. var value2 = b[property];
  296. return value1 - value2;
  297. }
  298. },
  299. // 获取路由参数
  300. getQuery(name) {
  301. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  302. var r = window.location.search.substr(1).match(reg);
  303. if (r != null) return decodeURI(r[2]);
  304. return null;
  305. },
  306. //获得年月日时分秒 //传入日期//例:2020-10-27T14:36:23
  307. timeFormatSeconds(time) {
  308. var d = time ? new Date(time) : new Date();
  309. var year = d.getFullYear();
  310. var month = d.getMonth() + 1;
  311. var day = d.getDate();
  312. var hours = d.getHours();
  313. var min = d.getMinutes();
  314. var seconds = d.getSeconds();
  315. if (month < 10) month = '0' + month;
  316. if (day < 10) day = '0' + day;
  317. if (hours < 0) hours = '0' + hours;
  318. if (min < 10) min = '0' + min;
  319. if (seconds < 10) seconds = '0' + seconds;
  320. return (year + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + seconds);
  321. }
  322. }
  323. });