HomeH5.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <div class="home bg-gray-900 comBg">
  3. <HeaderH5 @search="searchChange" :searchName="searchName" />
  4. <div class="min-h-screen text-white px-4">
  5. <div class="container mx-auto py-2">
  6. <div class="flex mb-3">
  7. <div class="flex space-x-4">
  8. <button class="px-3 py-2 rounded topActive fontH5">热门</button>
  9. <button class="bg-gray-800 px-3 py-2 rounded fontH5">趋势</button>
  10. <button class="bg-gray-800 px-3 py-2 rounded fontH5">最新</button>
  11. </div>
  12. </div>
  13. <div class="flex flex-wrap flex-grow mb-3 items-center">
  14. <input
  15. type="text"
  16. placeholder="搜索标签"
  17. class="searchInput fontH5 w-full mr-2 px-3 py-2 mb-1 rounded focus:border-blue-300 focus:outline-none "
  18. />
  19. <div
  20. v-for="(item, index) in selectLabelObj"
  21. :key="index"
  22. class="fontH5 px-3 py-1 mx-1 mb-1 rounded flex items-center cursor-pointer buttonBg1"
  23. @click="clickLabel(item)"
  24. >
  25. {{ item.labelName }}
  26. <i class="fas el-icon-close text-white"></i>
  27. </div>
  28. <el-button v-show="selectLabelObj.length > 0" class="textButton mx-1" type="text" @click="clearSelectLabel">移除所有</el-button>
  29. </div>
  30. <div class="flex flex-wrap">
  31. <div
  32. v-for="(item, index) in labelData.slice(0, labelLength)"
  33. :key="index"
  34. :class="[
  35. selectLabel.indexOf(item.id) != -1 ? 'buttonBg1' : 'labelButton',
  36. 'fontH5 labelButton px-3 py-1 mx-1 mb-1 rounded flex items-center cursor-pointer'
  37. ]"
  38. @click="clickLabel(item)"
  39. >
  40. <i class="fas fa-fire text-yellow-500 mr-2"></i>
  41. {{ item.labelName }}({{item.num}})
  42. </div>
  43. <div v-show="labelData.length > 8 && labelLength == 8" @click="labelLength = labelData.length" class="fontH5 labelButton px-3 py-1 mx-1 mb-1 rounded cursor-pointer">
  44. ....
  45. </div>
  46. <div v-show="labelData.length > 8 && labelLength == 8" @click="labelLength = labelData.length" class="fontH5 labelButton px-3 py-1 mx-1 mb-1 rounded cursor-pointer">
  47. 显示更多
  48. </div>
  49. <div v-show="labelData.length > 8 && labelLength > 8" @click="labelLength = 8" class="fontH5 labelButton px-3 py-1 mx-1 mb-1 rounded cursor-pointer">
  50. 隐藏
  51. </div>
  52. </div>
  53. <div class="mt-4">
  54. <div
  55. v-for="(item, index) in characterList"
  56. :key="index"
  57. class="box2 rounded-lg overflow-hidden shadow-lg cursor-pointer mb-3"
  58. @click="toDetail(item)"
  59. >
  60. <div class="p-3 flex justify-between">
  61. <img :src="baseApi + item.picture" class="w-24 h-24 img rounded" />
  62. <div class="info ml-3 flex-1">
  63. <h3 class="text-lg font-bold">{{ item.characterName }}</h3>
  64. <div class="flex flex-wrap labels">
  65. <div v-for="(item2, index2) in item.labelArr" :key="index2" class="m-0.5 tag px-2 py-1 rounded flex items-center text-xs">
  66. <!-- <i class="fas fa-smile text-yellow-400 mr-2"></i> -->
  67. {{ item2 }}
  68. </div>
  69. </div>
  70. <p class="text-sm prologue">
  71. {{ item.prologue }}
  72. </p>
  73. </div>
  74. </div>
  75. <div class="flex items-center justify-between px-3 pb-3">
  76. <div class="flex items-center box1">
  77. <v-icon name="heart" scale="1"/>
  78. <span class="ml-1">{{ item.likeNum }}</span>
  79. </div>
  80. <div class="flex items-center box1">
  81. <!-- <i class="fas fa-comment mr-1"></i> -->
  82. <v-icon name="star" scale="1"/>
  83. <span class="ml-1">{{ item.collections }}</span>
  84. </div>
  85. <!-- <div class="flex items-center">
  86. <v-icon name="share" scale="1.5"/>
  87. <span>{{ item.likeNum }}</span>
  88. </div> -->
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. </div>
  94. </div>
  95. </template>
  96. <script>
  97. import HeaderH5 from "@/views/homeComponents/HeaderH5.vue"
  98. import { labelListApi, characterListApi } from "@/api/home.js"
  99. // 引入需要的图标
  100. import 'vue-awesome/icons/heart'
  101. // import 'vue-awesome/icons/comment'
  102. import 'vue-awesome/icons/star'
  103. export default {
  104. name: "HomeH5",
  105. components: {
  106. HeaderH5
  107. },
  108. data() {
  109. return {
  110. labelLength: 8,
  111. searchName: '',
  112. labelData: [],
  113. selectLabel: [],
  114. selectLabelObj: [],
  115. characterList: [],
  116. url: [
  117. require('@/assets/images/1.png'),
  118. require('@/assets/images/2.png'),
  119. require('@/assets/images/3.png'),
  120. require('@/assets/images/4.png'),
  121. ]
  122. }
  123. },
  124. mounted() {
  125. // 获取标签
  126. this.getLabelList()
  127. // 获取角色列表
  128. if (this.$route.params.searchValue) {
  129. // 有查询条件,做查询处理
  130. this.searchChange(this.$route.params.searchValue)
  131. } else {
  132. // 没有查询条件则直接调用默认查询
  133. this.getCharacterList()
  134. }
  135. },
  136. methods: {
  137. searchChange(value) {
  138. // console.log('查询条件', value);
  139. this.searchName = value
  140. let query = {
  141. characterName: this.searchName,
  142. labelId: this.selectLabel
  143. }
  144. this.getCharacterList(query)
  145. },
  146. getLabelList() {
  147. let params = {
  148. pageSize: 20,
  149. pageNum: 1
  150. }
  151. labelListApi(params).then(res => {
  152. // console.log(res, '标签列表');
  153. this.labelData = res.rows
  154. })
  155. },
  156. getCharacterList(query) {
  157. let params = {
  158. pageSize: 20,
  159. pageNum: 1
  160. }
  161. if (query) {
  162. params = {
  163. ...params,
  164. ...query
  165. }
  166. }
  167. characterListApi(params).then(res => {
  168. // console.log(res, '角色列表');
  169. this.characterList = res.rows
  170. })
  171. },
  172. clickLabel(item) {
  173. let index = this.selectLabel.indexOf(item.id)
  174. if (index == -1) {
  175. this.selectLabel.push(item.id)
  176. this.selectLabelObj.push(item)
  177. } else {
  178. this.selectLabel.splice(index, 1)
  179. this.selectLabelObj.splice(index, 1)
  180. }
  181. let query = {
  182. characterName: this.searchName,
  183. labelId: this.selectLabel
  184. }
  185. this.getCharacterList(query)
  186. },
  187. clearSelectLabel() {
  188. this.selectLabel = []
  189. this.selectLabelObj = []
  190. let query = {
  191. characterName: this.searchName,
  192. labelId: this.selectLabel
  193. }
  194. this.getCharacterList(query)
  195. },
  196. toDetail(item) {
  197. this.$router.push({
  198. path: '/detailH5',
  199. query: {
  200. id: item.id
  201. }
  202. })
  203. }
  204. },
  205. };
  206. </script>
  207. <style scoped lang="scss">
  208. .home {
  209. font-size: 17.5px;
  210. blockquote {
  211. padding: 10px 20px;
  212. margin: 0 0 20px;
  213. font-size: 17.5px;
  214. border-left: 5px solid #eee;
  215. }
  216. hr {
  217. margin-top: 20px;
  218. margin-bottom: 20px;
  219. border: 0;
  220. border-top: 1px solid #eee;
  221. }
  222. .col-item {
  223. margin-bottom: 20px;
  224. }
  225. ul {
  226. padding: 0;
  227. margin: 0;
  228. }
  229. font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  230. font-size: 16px;
  231. color: #676a6c;
  232. overflow-x: hidden;
  233. ul {
  234. list-style-type: none;
  235. }
  236. h4 {
  237. margin-top: 0px;
  238. }
  239. h2 {
  240. margin-top: 10px;
  241. font-size: 26px;
  242. font-weight: 100;
  243. }
  244. p {
  245. margin-top: 2px;
  246. b {
  247. font-weight: 700;
  248. }
  249. }
  250. .update-log {
  251. ol {
  252. display: block;
  253. list-style-type: decimal;
  254. margin-block-start: 1em;
  255. margin-block-end: 1em;
  256. margin-inline-start: 0;
  257. margin-inline-end: 0;
  258. padding-inline-start: 40px;
  259. }
  260. }
  261. }
  262. .textButton {
  263. color: #eee;
  264. // margin-left: 5px;
  265. }
  266. .textButton:hover {
  267. color: #9333ea;
  268. }
  269. .labelButton {
  270. background: #ffffff1a;
  271. }
  272. .buttonBg1 {
  273. background: linear-gradient(270deg, #5ea1f9, #d287f1);
  274. }
  275. .topActive {
  276. background: var(--bg-color1);
  277. }
  278. .tag {
  279. flex-shrink: 0;
  280. background: rgba(245, 174, 67, 0.2);
  281. }
  282. .searchInput {
  283. background: #ffffff00;
  284. border: 1px solid #ffffff4d;
  285. }
  286. .box1 {
  287. border: 1px solid #ffffff4d;
  288. height: 30px;
  289. padding: 0 10px;
  290. border-radius: 18px;
  291. width: 68px;
  292. font-size: 14px;
  293. }
  294. .box2 {
  295. background: #ffffff0f;
  296. border: 1px solid #ffffff2e;
  297. }
  298. .info {
  299. width: calc(100% - 6.75rem);
  300. }
  301. .img {
  302. max-height: 220px;
  303. object-fit: cover;
  304. object-position: top;
  305. }
  306. .labels {
  307. flex-wrap: nowrap;
  308. overflow-x: auto;
  309. }
  310. .prologue {
  311. overflow:hidden;
  312. text-overflow: ellipsis;
  313. -webkit-line-clamp: 2;
  314. display: -webkit-box;
  315. -webkit-box-orient: vertical;
  316. }
  317. </style>