Homepage.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <div class="home-wrapper">
  3. <div class="nav" stype="height:500px">
  4. <!--搜索框-->
  5. <el-row class="container search-nav" style="padding: 30px 0 20px 0" :gutter="40">
  6. <el-col :span="5">
  7. <div class="pull-left to-mooctest-ranking" @click="handleLogoClick">
  8. <!-- <img class="logo-img" :src="logo_transparent" :to="'/home'"/>-->
  9. <!-- <span class="logo-title">{{ logoTitle }}</span>-->
  10. </div>
  11. </el-col>
  12. <el-col :span="15">
  13. <div class="search-nav-input">
  14. <div id="search-block ">
  15. <el-tabs v-model="searchType" type="card" @tab-click="handleTypeClick">
  16. <el-tab-pane v-for="item in searchTypeArr" v-if="item.value!=='all'" :label="item.name"
  17. :name="item.value" :key="item.value"></el-tab-pane>
  18. </el-tabs>
  19. <div class="search-input">
  20. <el-input ref="searchInput" placeholder="请输入内容" v-model="searchVal" class="input-with-select">
  21. <el-button class="search-button" slot="append" type="primary" @click="handleSearchData">搜索</el-button>
  22. </el-input>
  23. </div>
  24. </div>
  25. </div>
  26. </el-col>
  27. <el-col :span="4">
  28. <el-button type="primary pull-right" class="releaseBtn" @click="checkLogin()">免费发布众测需求</el-button>
  29. </el-col>
  30. </el-row>
  31. <!--TabNav-->
  32. <el-tabs v-model="currTab" @tab-click="handleTabClick" class="container square-tab">
  33. <el-tab-pane v-for="item in homeTabArr.menuArr1" :label="item.label" :name="item.name"
  34. :key="item.name"></el-tab-pane>
  35. <el-tab-pane v-for="item in homeTabArr.menuArr2" :label="item.name" :name="item.code"
  36. :key="item.code"></el-tab-pane>
  37. <el-tab-pane v-for="item in homeTabArr.menuArr3" :label="item.label" :name="item.name"
  38. :key="item.name"></el-tab-pane>
  39. </el-tabs>
  40. <div>
  41. </div>
  42. </div>
  43. <div class="container home-page ">
  44. <el-row :gutter="15">
  45. <el-col :span="5" class="homepage-right-modules">
  46. <LoginCard v-if="HOME_DISPLAY.login_card"/>
  47. <HotCrowd :applicationTypeRank="homeDataNoCache.applicationTypeRank" v-if="HOME_DISPLAY.hot_crowd"/>
  48. <HotAgency :agencyRank="homeDataNoCache.agencyRank" v-if="HOME_DISPLAY.hot_agency"/>
  49. <HotUser :userRank="homeDataNoCache.userRank" v-if="HOME_DISPLAY.hot_user"/>
  50. <HotContest :competitionList="homeData.competitionList" v-if="HOME_DISPLAY.hot_contest"/>
  51. </el-col>
  52. <el-col :span="19" class="test-type-wrapper">
  53. <TestMenu :testTypeList="homeData.testTypeList" v-if="HOME_DISPLAY.test_menu && homeData.testTypeList"></TestMenu>
  54. <RankingCard></RankingCard>
  55. <TestCard :applicationTypeList="homeData.applicationTypeList" v-if="HOME_DISPLAY.test_card && homeData.applicationTypeList"></TestCard>
  56. <el-row style="margin-top: 10px" v-if="HOME_DISPLAY.resource_and_tool">
  57. <ResourceAndTool :resourceList="homeDataNoCache.toolList && homeDataNoCache.toolList"></ResourceAndTool>
  58. </el-row>
  59. </el-col>
  60. </el-row>
  61. <InstitutionCard v-if="HOME_DISPLAY.institution_card"></InstitutionCard>
  62. </div>
  63. </div>
  64. </template>
  65. <script>
  66. // import commonData from '../../constants/tabMenu'
  67. import SearchBar from '../../components/commons/SearchBar'
  68. import TestMenu from './TestMenu'
  69. import LoginCard from './LoginCard'
  70. import BrandCard from './BrandCard'
  71. import ResourceAndTool from './ResourceAndTool'
  72. import TestCard from './TestCard'
  73. import InstitutionCard from './InstitutionCard'
  74. import HotCrowd from './HotCrowd'
  75. import HotAgency from './HotAgency'
  76. import HotUser from './HotUser'
  77. import RankingCard from './RankingCard'
  78. import HotContest from './HotContest'
  79. import PopularProject from '../Square/PopularProject'
  80. import Http from '@/js/http.js'
  81. import {mapGetters} from 'vuex'
  82. import Waterfall from 'vue-waterfall/lib/waterfall'
  83. import WaterfallSlot from 'vue-waterfall/lib/waterfall-slot'
  84. import {getAllFields, storageGet} from '@/js/index.js'
  85. import {notify} from "../../constants";
  86. import Apis from '@/js/api'
  87. import {CONFIG} from "../../config";
  88. // console.log(commonData);
  89. export default {
  90. name: 'Homepage',
  91. components: {
  92. HotCrowd,
  93. HotContest,
  94. HotUser,
  95. HotAgency,
  96. InstitutionCard,
  97. SearchBar,
  98. TestMenu,
  99. PopularProject,
  100. LoginCard,
  101. RankingCard,
  102. TestCard,
  103. BrandCard,
  104. ResourceAndTool,
  105. Waterfall,
  106. WaterfallSlot
  107. // vueWaterfallEasy
  108. },
  109. data() {
  110. return {
  111. logoTitle:CONFIG.logoTitle,
  112. HOME_DISPLAY:CONFIG.HOME_DISPLAY,
  113. logo_transparent:CONFIG.logo_transparent,
  114. user: {},
  115. isLogin: false,
  116. searchType: CONFIG.home_searchType,
  117. searchTypeArr: CONFIG.home_searchTypeArr,
  118. searchVal: '',
  119. homeTabArr: {
  120. menuArr1: CONFIG.home_homeTabArr_left,
  121. menuArr2: [{code: '', name: ''}],
  122. menuArr3: CONFIG.home_homeTabArr_right
  123. },
  124. homeData: {},
  125. homeDataNoCache: {},
  126. currTab: CONFIG.home_homeTabArr_default
  127. }
  128. },
  129. computed: {
  130. ...mapGetters(['getUserInfo'])
  131. },
  132. methods: {
  133. loadData() {
  134. this.showLoading();
  135. if (storageGet('user') != null) {
  136. this.isLogin = true;
  137. }
  138. this.setFields();
  139. let p1 = new Promise((resolve, reject) => {
  140. Http.get('/api/common/index/info/cache').then((res) => {
  141. this.homeData = res.data;
  142. // this.homeData.applicationTypeList.map((item)=>{
  143. // item.height = (item.testTypeList.length / 2) * 24 + 100;
  144. // return item;
  145. // })
  146. resolve(res.data);
  147. }).catch((error) => {
  148. notify('error', error.data)
  149. reject(error)
  150. })
  151. });
  152. let p2 = new Promise((resolve, reject) => {
  153. Http.get('/api/common/index/info/nocache').then((res) => {
  154. this.homeDataNoCache = res.data;
  155. resolve(res.data);
  156. }).catch((error) => {
  157. notify('error', error.data)
  158. reject(error)
  159. })
  160. });
  161. Promise.all([p1, p2]).then((result) => {
  162. this.hideLoading();
  163. }).catch((error) => {
  164. notify('error', error.data)
  165. })
  166. },
  167. setFields() {
  168. getAllFields().then((res) => {
  169. this.homeTabArr.menuArr2 = res
  170. })
  171. },
  172. checkLogin() {
  173. this.checkCreateProjectAuth();
  174. },
  175. handleLogoClick(){
  176. window.open('http://47.98.174.59:8200/#/');
  177. },
  178. checkCreateProjectAuth() {
  179. if (!this.isLogin) {
  180. notify('warning', '请登录后访问');
  181. } else if (this.isLogin) {
  182. Http.get(Apis.USER.IS_PART.replace('{userId}', this.user.id)).then((res) => {
  183. this.$router.push('/project/create');
  184. }).catch((error) => {
  185. notify('error', error)
  186. })
  187. }
  188. },
  189. handleTabClick(tab) {
  190. this.currTab = tab.name;
  191. // console.log(this.currTab + " " + tab.index + " " + tab.name );
  192. for (let i = 0; i < this.homeTabArr.menuArr3.length; i++) {
  193. if (this.currTab === this.homeTabArr.menuArr3[i].name) {
  194. this.$router.push(this.homeTabArr.menuArr3[i].linkTo);
  195. }
  196. }
  197. for (let i = 0; i < this.homeTabArr.menuArr2.length; i++) {
  198. if (this.currTab === this.homeTabArr.menuArr2[i].code) {
  199. this.$router.push('/field/detail');
  200. }
  201. }
  202. this.$router.push(this.homeTabArr.menuArr1[Number(tab.index)] && this.homeTabArr.menuArr1[Number(tab.index)].linkTo);
  203. },
  204. handleTypeClick(tab, e) {
  205. this.searchType = tab.name;
  206. // e.target.style.backgroundColor = $color-primary
  207. this.$refs.searchInput.focus()
  208. },
  209. handleSearchData() {
  210. if (this.searchType == 0) {
  211. this.$router.push({
  212. name: 'Square',
  213. params: {searchVal: this.searchVal, searchType: "project", currTab: "project"}
  214. });
  215. } else if (this.searchType == 1) {
  216. this.$router.push({name: 'AgencyList', params: {searchVal: this.searchVal}});
  217. } else if (this.searchType == 2) {
  218. this.$router.push({name: 'ResourceList', params: {searchVal: this.searchVal}});
  219. } else if (this.searchType == 3) {
  220. this.$router.push({name: 'ExpertList', params: {searchVal: this.searchVal}});
  221. }
  222. },
  223. showLoading() {
  224. this.loading = true
  225. },
  226. hideLoading() {
  227. this.loading = false
  228. },
  229. setUserInfo() {
  230. this.user = storageGet('user') && storageGet('user').userVO;
  231. }
  232. },
  233. mounted() {
  234. this.setUserInfo();
  235. this.loadData();
  236. },
  237. watch: {
  238. getUserInfo(val) {
  239. this.setUserInfo();
  240. this.loadData();
  241. }
  242. }
  243. }
  244. </script>
  245. <style lang="scss">
  246. @import "../../style/search-nav.scss";
  247. .home-wrapper {
  248. /deep/ .square-tab .el-tabs__item {
  249. font-size: 16px !important;
  250. margin-right: 0px !important;
  251. }
  252. /deep/ .login-card .popular-list {
  253. padding: 0 10px !important;
  254. }
  255. .home-page {
  256. padding: 15px 0;
  257. }
  258. .test-type-wrapper {
  259. padding-right: 15px;
  260. margin-bottom: 15px;
  261. }
  262. .homepage-right-modules {
  263. .login-card .el-card__body {
  264. padding: 10px !important;
  265. }
  266. .popular-card .el-card__header {
  267. padding: 10px !important;
  268. }
  269. .popular-card .el-card__body {
  270. padding: 10px !important;
  271. }
  272. }
  273. }
  274. </style>