index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template>
  2. <div class="My">
  3. <!-- 输入框 -->
  4. <div class="inputBox" @keydown.enter="searchFu()">
  5. <div class="searInco">
  6. <van-icon name="search" />
  7. </div>
  8. <div class="searBtn" @click="searchFu()">搜索</div>
  9. <van-field
  10. maxlength="10"
  11. v-model="txt"
  12. placeholder="输入您感兴趣的内容"
  13. />
  14. </div>
  15. <!-- 精彩必体验 -->
  16. <div class="titleTit">精彩必体验</div>
  17. <div class="bsBox">
  18. <div
  19. @click="bsInd = item.id"
  20. :class="{ bsAc: bsInd === item.id }"
  21. v-for="item in bsData"
  22. :key="item.id"
  23. >
  24. {{ item.name }}
  25. </div>
  26. </div>
  27. <!-- 主体内容 -->
  28. <div class="mainBoxNull" v-if="dataShow.length === 0">暂无内容</div>
  29. <div class="mainBox" v-else>
  30. <div
  31. class="row"
  32. @click="$router.push(`/layout/interact/info/${item.id}`)"
  33. v-for="item in dataShow"
  34. :key="item.id"
  35. >
  36. <img v-lazy="baseURL + item.thumb" alt="" />
  37. <div class="name">{{ item.name }}</div>
  38. <div class="author">
  39. <div class="author_ll">
  40. <img :src="item.avatarUrl" alt="" />
  41. <p>{{ item.nickName }}</p>
  42. </div>
  43. <div class="author_rr">{{ item.createTime.slice(0, 10) }}</div>
  44. </div>
  45. </div>
  46. </div>
  47. <!-- +号 -->
  48. <div class="issue">
  49. <img
  50. src="../../assets/img/interact/issue.png"
  51. alt=""
  52. @click="addInteract"
  53. />
  54. </div>
  55. </div>
  56. </template>
  57. <script>
  58. import { baseURL } from "@/utils/request";
  59. import { getCodeAPI, getDictAPI, getListAPI } from "@/api/interact.js";
  60. export default {
  61. components: {},
  62. data() {
  63. return {
  64. baseURL,
  65. txt: "",
  66. bsInd: null,
  67. bsData: [
  68. // { id: 1, name: "景点" },
  69. // { id: 2, name: "美食" },
  70. // { id: 3, name: "游玩" },
  71. // { id: 4, name: "酒店" },
  72. ],
  73. dataShow: [],
  74. };
  75. },
  76. computed: {},
  77. watch: {
  78. bsInd() {
  79. this.getListFu();
  80. },
  81. },
  82. methods: {
  83. // 封装获取用户code的方法
  84. getUserCode() {
  85. //此处的ID是在文档的开发-基本配置里面
  86. let appid = "wx3255043d1b21a4f7";
  87. // let url = "http://192.168.20.48:8080/#/layout/interact";
  88. let url = "https://yifangyice.4dage.com/web/index.html#/layout/interact";
  89. window.location.href =
  90. "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
  91. appid +
  92. "&redirect_uri=" +
  93. encodeURIComponent(url) +
  94. "&response_type=code&scope=snsapi_userinfo&state=bc17befd6d5060f16de95e38f6eaf69c&connect_redirect=1#wechat_redirect";
  95. },
  96. // 点击+号
  97. async addInteract() {
  98. let userInfo = localStorage.getItem("YFYC_userInfo");
  99. let nowTime = Date.now();
  100. if (userInfo) {
  101. let data = JSON.parse(userInfo);
  102. // 超过了6个小时
  103. if (nowTime - data.time >= 1000 * 60 * 60 * 6) this.getUserCode();
  104. else this.$router.push("/layout/interact/issue");
  105. } else this.getUserCode();
  106. },
  107. searchFu() {
  108. this.getListFu();
  109. },
  110. // 获取地址栏参数的方法
  111. getQueryCode(name) {
  112. // 未传参,返回空
  113. if (!name) return null;
  114. // 查询参数:先通过search取值,如果取不到就通过hash来取
  115. var after = window.location.search;
  116. after = after.substr(1) || window.location.hash.split("?")[1];
  117. // 地址栏URL没有查询参数,返回空
  118. if (!after) return null;
  119. // 如果查询参数中没有"name",返回空
  120. if (after.indexOf(name) === -1) return null;
  121. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  122. // 当地址栏参数存在中文时,需要解码,不然会乱码
  123. var r = decodeURI(after).match(reg);
  124. // 如果url中"name"没有值,返回空
  125. if (!r) return null;
  126. return r[2];
  127. },
  128. // getQueryCode() {
  129. // return this.$route.query.code ? this.$route.query.code : "";
  130. // },
  131. // 封装一个获取列表的方法
  132. async getListFu() {
  133. const obj = {
  134. dictTopicId: this.bsInd,
  135. pageNum: 1,
  136. pageSize: 9999,
  137. searchKey: this.txt,
  138. };
  139. const res = await getListAPI(obj);
  140. this.dataShow = res.data.records;
  141. },
  142. },
  143. async created() {
  144. document.querySelector("#app").style.maxWidth = "500px";
  145. this.getListFu();
  146. // 获取话题列表
  147. const res1 = await getDictAPI("topic");
  148. this.bsData = res1.data;
  149. this.bsData.unshift({ id: null, name: "全部" });
  150. let code = this.getQueryCode("code");
  151. console.log("-----------", code);
  152. if (code) {
  153. let res = await getCodeAPI(code);
  154. if (res.code === 0) {
  155. localStorage.setItem("YFYC_token", res.data.token);
  156. localStorage.setItem(
  157. "YFYC_userInfo",
  158. JSON.stringify({ ...res.data.wxUser, time: Date.now() })
  159. );
  160. this.$router.push("/layout/interact/issue");
  161. }
  162. // else {
  163. // Toast.fail("登录失败,请联系管理人员");
  164. // }
  165. }
  166. },
  167. mounted() {},
  168. beforeCreate() {}, //生命周期 - 创建之前
  169. beforeMount() {}, //生命周期 - 挂载之前
  170. beforeUpdate() {}, //生命周期 - 更新之前
  171. updated() {}, //生命周期 - 更新之后
  172. beforeDestroy() {}, //生命周期 - 销毁之前
  173. destroyed() {}, //生命周期 - 销毁完成
  174. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  175. };
  176. </script>
  177. <style lang='less' scoped>
  178. .My {
  179. width: 100%;
  180. height: calc(100% - 130px);
  181. overflow-y: auto;
  182. padding: 20px 15px;
  183. position: relative;
  184. .issue {
  185. position: fixed;
  186. z-index: 10;
  187. bottom: 80px;
  188. left: 50%;
  189. transform: translateX(-50%);
  190. height: 40px;
  191. text-align: center;
  192. & > img {
  193. width: 40px;
  194. }
  195. }
  196. .inputBox {
  197. margin: 0px auto;
  198. width: 100%;
  199. height: 30px;
  200. position: relative;
  201. .searBtn {
  202. position: absolute;
  203. right: 0;
  204. top: 0;
  205. width: 40px;
  206. height: 30px;
  207. border-radius: 3px;
  208. z-index: 2;
  209. background-color: #fe6e69;
  210. font-size: 14px;
  211. color: #fff;
  212. line-height: 30px;
  213. text-align: center;
  214. }
  215. .searInco {
  216. color: #a0a0a0;
  217. display: flex;
  218. justify-content: center;
  219. align-items: center;
  220. font-size: 16px;
  221. position: absolute;
  222. top: 0;
  223. left: 10px;
  224. z-index: 3;
  225. width: 20px;
  226. height: 30px;
  227. }
  228. /deep/.van-cell {
  229. width: 100%;
  230. height: 30px;
  231. line-height: 30px;
  232. padding: 0px 0 0px 36px;
  233. background-color: #f4f4f4;
  234. border-radius: 5px;
  235. }
  236. }
  237. .titleTit {
  238. font-size: 16px;
  239. font-weight: 700;
  240. margin: 15px 0;
  241. color: #000000;
  242. }
  243. .bsBox {
  244. display: flex;
  245. flex-wrap: wrap;
  246. & > div {
  247. text-align: center;
  248. min-width: 60px;
  249. padding: 0 5px;
  250. height: 30px;
  251. line-height: 30px;
  252. border-radius: 2px;
  253. background-color: #f4f4f4;
  254. margin: 0 15px 15px 0;
  255. font-size: 12px;
  256. color: #333333;
  257. }
  258. .bsAc {
  259. background-color: #333333;
  260. color: #f4f4f4;
  261. }
  262. }
  263. .mainBoxNull {
  264. width: 100%;
  265. height: 300px;
  266. display: flex;
  267. justify-content: center;
  268. align-items: center;
  269. font-size: 16px;
  270. }
  271. .mainBox {
  272. display: flex;
  273. flex-wrap: wrap;
  274. .row {
  275. margin-right: 4%;
  276. margin-bottom: 4%;
  277. overflow: hidden;
  278. width: 48%;
  279. height: 260px;
  280. background-color: #f7f8fa;
  281. border-radius: 4px;
  282. color: #333333;
  283. &:nth-of-type(2n) {
  284. margin-right: 0;
  285. }
  286. & > img {
  287. width: 100%;
  288. height: 180px;
  289. object-fit: cover;
  290. }
  291. .name {
  292. overflow: hidden;
  293. text-overflow: ellipsis;
  294. white-space: nowrap;
  295. padding: 10px 8px 5px;
  296. font-size: 14px;
  297. font-weight: 700;
  298. }
  299. .author {
  300. margin-top: 10px;
  301. height: 20px;
  302. padding: 0 8px;
  303. display: flex;
  304. align-items: center;
  305. justify-content: space-between;
  306. font-size: 12px;
  307. .author_ll {
  308. height: 100%;
  309. width: calc(100% - 65px);
  310. display: flex;
  311. align-items: center;
  312. & > img {
  313. margin-top: -3px;
  314. margin-right: 5px;
  315. width: 12px;
  316. height: 12px;
  317. border-radius: 50%;
  318. }
  319. p {
  320. overflow: hidden;
  321. text-overflow: ellipsis;
  322. white-space: nowrap;
  323. width: calc(100% - 18px);
  324. }
  325. }
  326. .author_rr {
  327. width: 61px;
  328. }
  329. }
  330. }
  331. }
  332. }
  333. </style>