Homepage.vue 10 KB

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