commonVue.js 11 KB

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