演示项目-图书馆
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

441 lines
10 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div class="main">
  3. <!-- <div class="index-header">当前活动</div> -->
  4. <div class="active-main">
  5. <div class="active-list">
  6. <div class="active-item" @click="toActiveDetail">
  7. <div class="active-img">
  8. <img src="@assets/images/bookimg.png" alt="" />
  9. <span>限选3册</span>
  10. </div>
  11. <div class="active-info">
  12. <div class="active-info-top">
  13. <h4>你选书我买单</h4>
  14. <span></span>
  15. </div>
  16. </div>
  17. <div class="active-time">
  18. 活动时间2023/10/1 - 2023/12/31
  19. </div>
  20. <div class="active-bottom">
  21. <p class="active-slogn">新书 · 选书· 下单· 借阅</p>
  22. <span class="active-btn" @click.stop="toBookList"></span>
  23. </div>
  24. </div>
  25. <div class="active-item">
  26. <div class="active-img">
  27. <img src="@assets/images/bookimg.png" alt="" />
  28. <span>限选3册</span>
  29. </div>
  30. <div class="active-info">
  31. <div class="active-info-top">
  32. <h4>你选书我买单</h4>
  33. <span>活动仅剩最后3天</span>
  34. </div>
  35. </div>
  36. <div class="active-time">
  37. 活动时间2023/10/1 - 2023/12/31
  38. </div>
  39. <div class="active-bottom">
  40. <p class="active-slogn">新书 · 选书· 下单· 借阅</p>
  41. <span class="active-btn"></span>
  42. </div>
  43. </div>
  44. <div class="active-item">
  45. <div class="active-img">
  46. <img src="@assets/images/bookimg.png" alt="" />
  47. <span>限选3册</span>
  48. </div>
  49. <div class="active-info">
  50. <div class="active-info-top">
  51. <h4>你选书我买单</h4>
  52. <span>12.13 09:00开始</span>
  53. </div>
  54. </div>
  55. <div class="active-time">
  56. 活动时间2023/10/1 - 2023/12/31
  57. </div>
  58. <div class="active-bottom">
  59. <p class="active-slogn">新书 · 选书· 下单· 借阅</p>
  60. <span class="active-btn wait-btn"></span>
  61. </div>
  62. </div>
  63. </div>
  64. <div class="active-nodata">
  65. <img src="@assets/images/nodata.png" alt="" />
  66. </div>
  67. </div>
  68. <TabBar :tabCur.sync="data.tabCur" />
  69. </div>
  70. </template>
  71. <script>
  72. import { reactive, computed, onMounted, getCurrentInstance } from 'vue'
  73. import TabBar from '@/components/tabBar/index.vue'
  74. import { useStore, mapGetters } from 'vuex'
  75. import { useRoute } from 'vue-router'
  76. import { isWeiXin } from '@/utils/tool.js'
  77. import { Toast } from 'vant'
  78. export default {
  79. components: { TabBar },
  80. setup() {
  81. const store = useStore()
  82. const { proxy } = getCurrentInstance()
  83. const data = reactive({
  84. tabCur: 0,
  85. isWeiXin: true,
  86. weChatUserInfo: {},
  87. showLoginDialog: false,
  88. isTryOutLogin: true,
  89. key: '',
  90. iv: '',
  91. })
  92. onMounted(async () => {
  93. data.isWeiXin = isWeiXin()
  94. data.key = CryptoJS.enc.Utf8.parse('0yxk2020aiyx2021')
  95. data.iv = CryptoJS.enc.Utf8.parse('0yxk2020aiyx2021')
  96. let option = proxy.$route.query
  97. if (option.sid) {
  98. localStorage.setItem('aiyxSid', option.sid)
  99. // 外部试用
  100. if (option.sid == 'aiyxlibmultimediaadmin') {
  101. ToTryLogin()
  102. data.isTryOutLogin = false
  103. localStorage.setItem('isTryout', 1)
  104. }
  105. }
  106. /* 登录判断 */
  107. proxy.isLogin(option)
  108. const userData = localStorage.getItem('userData') || ''
  109. if (userData) {
  110. }
  111. })
  112. let toBookList = () => {
  113. proxy.$router.push({ path: '/BookList' })
  114. }
  115. let toActiveDetail = () => {
  116. proxy.$router.push({ path: '/ActiveDetail' })
  117. }
  118. let Encrypt = (o) => {
  119. if (typeof o === 'string') {
  120. if (o) {
  121. var srcs = CryptoJS.enc.Utf8.parse(o)
  122. return CryptoJS.AES.encrypt(srcs, data.key, {
  123. keySize: 128 / 8,
  124. iv: data.iv,
  125. mode: CryptoJS.mode.CBC,
  126. padding: CryptoJS.pad.Pkcs7,
  127. }).toString()
  128. }
  129. } else if (typeof o === 'object') {
  130. for (var _o in o) {
  131. if (o[_o]) {
  132. var srcs = CryptoJS.enc.Utf8.parse(o[_o])
  133. o[_o] = CryptoJS.AES.encrypt(srcs, data.key, {
  134. keySize: 128 / 8,
  135. iv: data.iv,
  136. mode: CryptoJS.mode.CBC,
  137. padding: CryptoJS.pad.Pkcs7,
  138. }).toString()
  139. }
  140. }
  141. }
  142. return o
  143. }
  144. // 试用直接登录
  145. let ToTryLogin = () => {
  146. let param = {
  147. Phone: 'a0c82379-37c1-d2e3-a2bf-82e0d081787c',
  148. Pwd: Encrypt('123456'),
  149. }
  150. proxy.$http
  151. .post(proxy.$API.LOGIN, param, {
  152. headers: {
  153. 'Content-Type': 'application/x-www-form-urlencoded',
  154. },
  155. })
  156. .then((res) => {
  157. if (res.type == 200) {
  158. localStorage.setItem(
  159. 'userData',
  160. JSON.stringify(res.data)
  161. )
  162. localStorage.setItem(
  163. 'userphone',
  164. 'a0c82379-37c1-d2e3-a2bf-82e0d081787c'
  165. )
  166. if (localStorage.getItem('actOnlinePage')) {
  167. const actionUrl =
  168. localStorage.getItem('actonlineLink')
  169. location.href = actionUrl
  170. } else {
  171. location.href = '/'
  172. }
  173. } else if (res.type == 403) {
  174. Toast(res.content)
  175. setTimeout(() => {
  176. // let url = '/ChangeMineCard?custId=' + res.data.custId
  177. // proxy.$router.push(url)
  178. }, 1000)
  179. } else {
  180. Toast(res.content)
  181. }
  182. })
  183. .catch((res) => {
  184. console.log(res)
  185. })
  186. }
  187. /* 登录判断 */
  188. let isLogin = (option) => {
  189. /* 如果微信code 存在, 则获取微信用户信息进行微信登录或者注册 */
  190. if (option.code) {
  191. localStorage.setItem('aiyxWeChatLoginStatus', 'noLogin')
  192. proxy.getWeChatUserInfo()
  193. localStorage.setItem('aiyxWeChatCode', option.code)
  194. } else {
  195. const userData = localStorage.getItem('userData') || ''
  196. if (!userData) {
  197. data.showLoginDialog = true
  198. }
  199. }
  200. }
  201. // 微信登录
  202. let weChatLogin = () => {
  203. if (!data.isWeiXin) {
  204. Toast('请使用微信登录')
  205. return
  206. }
  207. let homeUrl = location.protocol + '//' + location.host
  208. let url =
  209. 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd2a2989d0fb9cf1c&redirect_uri=' +
  210. homeUrl +
  211. '&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'
  212. location.href = url
  213. }
  214. /* 获取微信用户信息 */
  215. let getWeChatUserInfo = () => {
  216. const that = data
  217. let option = proxy.$route.query
  218. let param = {
  219. Code: option.code || '',
  220. }
  221. proxy.$http
  222. .post(proxy.$API.WECHATLOGIN, param, {
  223. headers: {
  224. 'Content-Type': 'application/x-www-form-urlencoded',
  225. },
  226. })
  227. .then((res) => {
  228. if (res.type == 200) {
  229. data.showLoginDialog = false
  230. if (res.data) {
  231. localStorage.setItem(
  232. 'userData',
  233. JSON.stringify(res.data)
  234. )
  235. localStorage.setItem('userphone', res.data.phone)
  236. localStorage.setItem(
  237. 'aiyxWeChatLoginStatus',
  238. 'isLogin'
  239. )
  240. }
  241. console.log('微信登录成功')
  242. } else if (res.type == 203 && res.data) {
  243. that.weChatUserInfo = res.data
  244. localStorage.setItem(
  245. 'weChatUserInfo',
  246. JSON.stringify(that.weChatUserInfo)
  247. )
  248. // proxy.$router.push('/bindMobilePhone')
  249. } else {
  250. console.log(res.content)
  251. }
  252. })
  253. .catch((res) => {
  254. console.log(res)
  255. })
  256. }
  257. /* 获取token 和用户信息 */
  258. let getTokenAndUserInfo = () => {
  259. if (!location.search) {
  260. return
  261. }
  262. let code = proxy.$route.query.code
  263. if (code) {
  264. proxy.$http
  265. .get(proxy.$API.GETWECHATTOkEN, {
  266. params: { Code: code },
  267. })
  268. .then((res) => {
  269. if (res.type == 200) {
  270. let data = res.data
  271. let access_token = data.access_token
  272. let openid = data.openid
  273. proxy.$http
  274. .get(proxy.$API.GETWECHATUSERINFO, {
  275. params: {
  276. AccessToken: access_token,
  277. OpenId: openid,
  278. },
  279. })
  280. .then((res) => {
  281. if (res.type == 200) {
  282. let datas = res.data
  283. alert(
  284. '我的昵称是:' +
  285. datas.nickname +
  286. ',我的openid是:' +
  287. datas.openid +
  288. ',我的城市是:' +
  289. datas.city
  290. )
  291. }
  292. })
  293. .catch((res) => {
  294. console.log(res)
  295. })
  296. }
  297. })
  298. .catch((res) => {
  299. console.log(res)
  300. })
  301. }
  302. }
  303. return {
  304. data,
  305. toBookList,
  306. toActiveDetail,
  307. Encrypt,
  308. ToTryLogin,
  309. isLogin,
  310. getTokenAndUserInfo,
  311. weChatLogin,
  312. getWeChatUserInfo,
  313. }
  314. },
  315. }
  316. </script>
  317. <style lang="scss" scoped>
  318. .index-header {
  319. padding: 0 0.32rem;
  320. height: 1.125rem;
  321. line-height: 1.125rem;
  322. font-size: 0.5rem;
  323. color: #fff;
  324. background-color: #5a86f4;
  325. }
  326. .active-main{
  327. padding-bottom: 1.2rem;
  328. }
  329. .active-list {
  330. padding: 0 .16rem;
  331. font-size: 0.24rem;
  332. color: #191a1a;
  333. .active-item {
  334. background-color: #fff;
  335. margin-top: 0.2rem;
  336. box-shadow: 0px 0.0375rem 0.75rem 1px rgba(0, 0, 0, 0.08);
  337. border-radius: 0.1rem;
  338. .active-img {
  339. position: relative;
  340. img {
  341. display: block;
  342. width: 100%;
  343. }
  344. span {
  345. position: absolute;
  346. top: 0;
  347. left: 0;
  348. display: block;
  349. padding: 0 0.1rem;
  350. height: 0.6rem;
  351. line-height: 0.6rem;
  352. font-size: 0.24rem;
  353. text-align: center;
  354. color: #fff;
  355. background-color: rgba(0, 0, 0, 0.4);
  356. border-radius: 0.08rem 0 0.08rem 0;
  357. }
  358. }
  359. .active-info {
  360. margin-top: 0.2rem;
  361. padding: 0 0.2rem;
  362. .active-info-top {
  363. display: flex;
  364. justify-content: flex-start;
  365. h4 {
  366. margin-right: 0.125rem;
  367. font-size: 0.36rem;
  368. font-weight: 800;
  369. }
  370. span {
  371. margin-top: 0.17rem;
  372. color: #f3a916;
  373. }
  374. }
  375. }
  376. .active-time {
  377. padding: 0 0.2rem 0 0.55rem;
  378. background: url('@assets/images/time.png') no-repeat 0.2rem center;
  379. background-size: 0.26rem 0.26rem;
  380. }
  381. .active-bottom {
  382. display: flex;
  383. justify-content: space-between;
  384. align-items: center;
  385. padding: 0.12rem 0.2rem 0.2rem 0.2rem;
  386. .active-slogn {
  387. position: relative;
  388. height: 0.44rem;
  389. line-height: 0.44rem;
  390. font-size: 0.2rem;
  391. padding: 0 0.12rem;
  392. background-color: #f4f6fc;
  393. border-radius: 0.05rem;
  394. &::before {
  395. content: '';
  396. position: absolute;
  397. top: -0.08rem;
  398. left: 0.12rem;
  399. width: 0.14rem;
  400. height: 0.14rem;
  401. background: url('@assets/images/yh1.png') no-repeat;
  402. background-size: 100% 100%;
  403. }
  404. &::after {
  405. content: '';
  406. position: absolute;
  407. bottom: -0.08rem;
  408. right: 0.12rem;
  409. width: 0.14rem;
  410. height: 0.14rem;
  411. background: url('@assets/images/yh2.png') no-repeat;
  412. background-size: 100% 100%;
  413. }
  414. }
  415. .active-btn {
  416. width: 1.83rem;
  417. height: 0.6rem;
  418. background: url('@assets/images/btn1.png') no-repeat;
  419. background-size: 100% 100%;
  420. &.wait-btn {
  421. background: url('@assets/images/btn2.png') no-repeat;
  422. background-size: 100% 100%;
  423. }
  424. }
  425. }
  426. }
  427. }
  428. .active-nodata {
  429. img {
  430. display: block;
  431. width: 4rem;
  432. margin: 0 auto;
  433. }
  434. }
  435. </style>