Showing
2 changed files
with
66 additions
and
61 deletions
src/composables/useBookList.js
0 → 100644
| 1 | +import { ref } from 'vue' | ||
| 2 | +import axios from '@/utils/axios'; | ||
| 3 | +import { Toast } from 'vant'; | ||
| 4 | + | ||
| 5 | +export const bookFn = ($route) => { | ||
| 6 | + const kg_id = $route.query.kg_id ? $route.query.kg_id : ''; | ||
| 7 | + const kgInfo = ref({ | ||
| 8 | + id: '', | ||
| 9 | + logo: '', | ||
| 10 | + name: '', | ||
| 11 | + book_list: [] | ||
| 12 | + }); | ||
| 13 | + if (kg_id) { // 从学校列表进入 | ||
| 14 | + axios.get('/srv/?a=kg_book_list', { | ||
| 15 | + params: { | ||
| 16 | + kg_id | ||
| 17 | + } | ||
| 18 | + }) | ||
| 19 | + .then(res => { | ||
| 20 | + if (res.data.code === 1) { | ||
| 21 | + kgInfo.value = res.data.data; | ||
| 22 | + } else { | ||
| 23 | + console.warn(res); | ||
| 24 | + Toast({ | ||
| 25 | + icon: 'close', | ||
| 26 | + message: res.data.msg | ||
| 27 | + }); | ||
| 28 | + } | ||
| 29 | + }) | ||
| 30 | + .catch(err => { | ||
| 31 | + console.error(err); | ||
| 32 | + }) | ||
| 33 | + } else { // 从访客进入 | ||
| 34 | + axios.get('/srv/?a=book_list') | ||
| 35 | + .then(res => { | ||
| 36 | + if (res.data.code === 1) { | ||
| 37 | + kgInfo.value = { | ||
| 38 | + book_list: res.data.data | ||
| 39 | + } | ||
| 40 | + } else { | ||
| 41 | + console.warn(res); | ||
| 42 | + Toast({ | ||
| 43 | + icon: 'close', | ||
| 44 | + message: res.data.msg | ||
| 45 | + }); | ||
| 46 | + } | ||
| 47 | + }) | ||
| 48 | + .catch(err => { | ||
| 49 | + console.error(err); | ||
| 50 | + }) | ||
| 51 | + } | ||
| 52 | + return { | ||
| 53 | + kg_id, | ||
| 54 | + kgInfo | ||
| 55 | + } | ||
| 56 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -3,11 +3,11 @@ | ... | @@ -3,11 +3,11 @@ |
| 3 | <div class="modify-top"></div> | 3 | <div class="modify-top"></div> |
| 4 | <div class="belong-school"> | 4 | <div class="belong-school"> |
| 5 | <template v-if="kg_id"> | 5 | <template v-if="kg_id"> |
| 6 | - <van-image round width="2rem" height="2rem" lazy-load :src="kindergartenInfo.logo" | 6 | + <van-image round width="2rem" height="2rem" lazy-load :src="kgInfo.logo" |
| 7 | style="vertical-align: text-bottom;"> | 7 | style="vertical-align: text-bottom;"> |
| 8 | <template v-slot:error>加载失败</template> | 8 | <template v-slot:error>加载失败</template> |
| 9 | </van-image> | 9 | </van-image> |
| 10 | - <p class="title">{{ kindergartenInfo.name }}</p> | 10 | + <p class="title">{{ kgInfo.name }}</p> |
| 11 | </template> | 11 | </template> |
| 12 | </div> | 12 | </div> |
| 13 | <div style="position: relative;"> | 13 | <div style="position: relative;"> |
| ... | @@ -24,7 +24,7 @@ | ... | @@ -24,7 +24,7 @@ |
| 24 | <div class="ding right"></div> | 24 | <div class="ding right"></div> |
| 25 | </div> | 25 | </div> |
| 26 | <div class="book-list"> | 26 | <div class="book-list"> |
| 27 | - <template v-for="(item, key) in kindergartenInfo.book_list" :key="key"> | 27 | + <template v-for="(item, key) in kgInfo.book_list" :key="key"> |
| 28 | <book-card type="C" :item="item" @on-click="onClick(item)"></book-card> | 28 | <book-card type="C" :item="item" @on-click="onClick(item)"></book-card> |
| 29 | </template> | 29 | </template> |
| 30 | </div> | 30 | </div> |
| ... | @@ -37,15 +37,18 @@ | ... | @@ -37,15 +37,18 @@ |
| 37 | import MyButton from '@/components/MyButton/index.vue' | 37 | import MyButton from '@/components/MyButton/index.vue' |
| 38 | import BookCard from '@/components/BookCard/index.vue' | 38 | import BookCard from '@/components/BookCard/index.vue' |
| 39 | import ShortcutFixed from '@/components/ShortcutFixed/index.vue' | 39 | import ShortcutFixed from '@/components/ShortcutFixed/index.vue' |
| 40 | -import { ref, reactive, onMounted } from 'vue' | 40 | + |
| 41 | +import { bookFn } from '@/composables/useBookList.js' | ||
| 42 | + | ||
| 43 | +import { reactive } from 'vue' | ||
| 41 | import { useRoute, useRouter } from 'vue-router' | 44 | import { useRoute, useRouter } from 'vue-router' |
| 42 | -import axios from '@/utils/axios'; | ||
| 43 | import _ from 'lodash' | 45 | import _ from 'lodash' |
| 44 | -import $ from 'jquery' | 46 | + |
| 45 | -import { Toast } from 'vant'; | ||
| 46 | const $route = useRoute(); | 47 | const $route = useRoute(); |
| 47 | const $router = useRouter(); | 48 | const $router = useRouter(); |
| 48 | 49 | ||
| 50 | +const { kg_id, kgInfo } = bookFn($route) | ||
| 51 | + | ||
| 49 | // 自定义按钮颜色样式 | 52 | // 自定义按钮颜色样式 |
| 50 | const styleObject = reactive({ | 53 | const styleObject = reactive({ |
| 51 | backgroundColor: '#F4675A', | 54 | backgroundColor: '#F4675A', |
| ... | @@ -53,56 +56,6 @@ const styleObject = reactive({ | ... | @@ -53,56 +56,6 @@ const styleObject = reactive({ |
| 53 | borderColor: '#F4675A' | 56 | borderColor: '#F4675A' |
| 54 | }) | 57 | }) |
| 55 | 58 | ||
| 56 | -// 页面数据绑定 | ||
| 57 | -const kg_id = $route.query.kg_id ? $route.query.kg_id : ''; | ||
| 58 | -const kindergartenInfo = ref({ | ||
| 59 | - id: '', | ||
| 60 | - logo: '', | ||
| 61 | - name: '', | ||
| 62 | - book_list: [] | ||
| 63 | -}); | ||
| 64 | -onMounted(() => { | ||
| 65 | - if (kg_id) { // 从学校列表进入 | ||
| 66 | - axios.get('/srv/?a=kg_book_list', { | ||
| 67 | - params: { | ||
| 68 | - kg_id | ||
| 69 | - } | ||
| 70 | - }) | ||
| 71 | - .then(res => { | ||
| 72 | - if (res.data.code === 1) { | ||
| 73 | - kindergartenInfo.value = res.data.data; | ||
| 74 | - } else { | ||
| 75 | - console.warn(res); | ||
| 76 | - Toast({ | ||
| 77 | - icon: 'close', | ||
| 78 | - message: res.data.msg | ||
| 79 | - }); | ||
| 80 | - } | ||
| 81 | - }) | ||
| 82 | - .catch(err => { | ||
| 83 | - console.error(err); | ||
| 84 | - }) | ||
| 85 | - } else { // 从访客进入 | ||
| 86 | - axios.get('/srv/?a=book_list') | ||
| 87 | - .then(res => { | ||
| 88 | - if (res.data.code === 1) { | ||
| 89 | - kindergartenInfo.value = { | ||
| 90 | - book_list: res.data.data | ||
| 91 | - } | ||
| 92 | - } else { | ||
| 93 | - console.warn(res); | ||
| 94 | - Toast({ | ||
| 95 | - icon: 'close', | ||
| 96 | - message: res.data.msg | ||
| 97 | - }); | ||
| 98 | - } | ||
| 99 | - }) | ||
| 100 | - .catch(err => { | ||
| 101 | - console.error(err); | ||
| 102 | - }) | ||
| 103 | - } | ||
| 104 | -}) | ||
| 105 | - | ||
| 106 | // 跳转书籍详情页 | 59 | // 跳转书籍详情页 |
| 107 | const onClick = (item) => { | 60 | const onClick = (item) => { |
| 108 | $router.push({ | 61 | $router.push({ |
| ... | @@ -112,10 +65,6 @@ const onClick = (item) => { | ... | @@ -112,10 +65,6 @@ const onClick = (item) => { |
| 112 | } | 65 | } |
| 113 | }); | 66 | }); |
| 114 | } | 67 | } |
| 115 | - | ||
| 116 | -const gotoMe = () => { | ||
| 117 | - console.warn('跳转我的地址'); | ||
| 118 | -} | ||
| 119 | </script> | 68 | </script> |
| 120 | 69 | ||
| 121 | <script> | 70 | <script> | ... | ... |
-
Please register or login to post a comment