lex 2 年 前
コミット
9813bf65b7

+ 19 - 1
src/state.ts

@@ -1,5 +1,6 @@
 import { reactive } from 'vue'
-import { setAuth } from './helpers/utils'
+import { browser, setAuth } from './helpers/utils'
+import { postMessage } from './helpers/native-message'
 
 type status = 'init' | 'login' | 'logout' | 'error'
 
@@ -35,3 +36,20 @@ export const setLoginError = () => {
   state.user.status = 'error'
   state.user.data = null
 }
+
+// 用于处理跳转地址,如果是在app内,则打开一个新的webview, 否则跳转连接
+export const openDefaultWebView = (url?: string, callBack?: any) => {
+  if (browser().isApp) {
+    postMessage({
+      api: 'openWebView',
+      content: {
+        url,
+        orientation: 1,
+        isHideTitle: false
+      }
+    })
+  } else {
+    callBack && callBack()
+  }
+
+}

+ 16 - 7
src/views/music/album-detail/index.tsx

@@ -20,7 +20,7 @@ import styles from './index.module.less'
 import { useRect } from '@vant/use'
 import { useEventListener, useWindowScroll } from '@vueuse/core'
 import { getRandomKey, musicBuy } from '../music'
-import { state } from '@/state'
+import { openDefaultWebView, state } from '@/state'
 import IconPan from './pan.png'
 import oStart from './oStart.png'
 import iStart from './iStart.png'
@@ -344,12 +344,21 @@ export default defineComponent({
                 list={rows.value}
                 onDetail={(item: any) => {
                   if (onItemClick === noop || !onItemClick) {
-                    router.push({
-                      path: '/music-detail',
-                      query: {
-                        id: item.id,
-                        albumId: route.params.id
-                      }
+                    const url =
+                      location.origin +
+                      location.pathname +
+                      '#/music-detail?id=' +
+                      item.id +
+                      '&albumId=' +
+                      route.params.id
+                    openDefaultWebView(url, () => {
+                      router.push({
+                        path: '/music-detail',
+                        query: {
+                          id: item.id,
+                          albumId: route.params.id
+                        }
+                      })
                     })
                   } else {
                     onItemClick(item)

+ 13 - 6
src/views/music/list/index.tsx

@@ -8,7 +8,7 @@ import { useRoute, useRouter } from 'vue-router'
 import ColResult from '@/components/col-result'
 import styles from './index.module.less'
 import { getRandomKey } from '../music'
-import { state as baseState } from '@/state'
+import { openDefaultWebView, state as baseState } from '@/state'
 import SelectSubject from '../search/select-subject'
 import { SubjectEnum, useSubjectId } from '@/helpers/hooks'
 import Song from '../component/song'
@@ -307,11 +307,18 @@ export default defineComponent({
                   list={data.value.rows}
                   onDetail={(item: any) => {
                     if (onItemClick === noop) {
-                      router.push({
-                        path: '/music-detail',
-                        query: {
-                          id: item.id
-                        }
+                      const url =
+                        location.origin +
+                        location.pathname +
+                        '#/music-detail?id=' +
+                        item.id
+                      openDefaultWebView(url, () => {
+                        router.push({
+                          path: '/music-detail',
+                          query: {
+                            id: item.id
+                          }
+                        })
                       })
                     } else {
                       onItemClick?.(item)

+ 13 - 6
src/views/music/list/list.tsx

@@ -1,7 +1,7 @@
 import ColResult from '@/components/col-result'
 import { SubjectEnum, useSubjectId } from '@/helpers/hooks'
 import request from '@/helpers/request'
-import { state } from '@/state'
+import { openDefaultWebView, state } from '@/state'
 import { List } from 'vant'
 import { defineComponent, reactive, ref } from 'vue'
 import { useRoute, useRouter } from 'vue-router'
@@ -107,11 +107,18 @@ export default defineComponent({
               list={data.value.rows}
               onDetail={(item: any) => {
                 if (onItemClick === noop) {
-                  router.push({
-                    path: '/music-detail',
-                    query: {
-                      id: item.id
-                    }
+                  const url =
+                    location.origin +
+                    location.pathname +
+                    '#/music-detail?id=' +
+                    item.id
+                  openDefaultWebView(url, () => {
+                    router.push({
+                      path: '/music-detail',
+                      query: {
+                        id: item.id
+                      }
+                    })
                   })
                 } else {
                   onItemClick?.(item)

+ 0 - 28
src/views/music/music.ts

@@ -34,32 +34,4 @@ export const musicBuy = (item: any, callBack?: any, moreQuery = {}) => {
       isOpenLight: true
     }
   })
-  return
-  // play :0 不能看,1 能看
-  const path =
-    !item.play && item.chargeType === 'VIP' ? '/memberCenter' : '/orderDetail'
-  if (!item.play && item.chargeType === 'VIP') {
-    Dialog.confirm({
-      title: '提示',
-      message: '您还不是会员,是否加入会员?',
-      confirmButtonColor: 'var(--van-primary)'
-    }).then(() => {
-      callBack && callBack(path)
-    })
-    return
-  } else if (!item.play && item.chargeType === 'CHARGE') {
-    orderStatus.orderObject.orderType = 'MUSIC'
-    orderStatus.orderObject.orderName = item.musicSheetName
-    orderStatus.orderObject.orderDesc = item.musicSheetName
-    orderStatus.orderObject.actualPrice = item.musicPrice
-    orderStatus.orderObject.orderList = [
-      {
-        orderType: 'MUSIC',
-        goodsName: item.musicSheetName,
-        actualPrice: item.musicPrice,
-        ...item
-      }
-    ]
-    callBack && callBack(path)
-  }
 }

+ 13 - 6
src/views/music/personal/collection.tsx

@@ -3,7 +3,7 @@ import { List } from 'vant'
 import request from '@/helpers/request'
 import { useRoute, useRouter } from 'vue-router'
 import ColResult from '@/components/col-result'
-import { state } from '@/state'
+import { openDefaultWebView, state } from '@/state'
 import styles from './index.module.less'
 import Song from '../component/song'
 
@@ -72,11 +72,18 @@ export default defineComponent({
             <Song
               list={rows.value}
               onDetail={(item: any) => {
-                router.push({
-                  path: '/music-detail',
-                  query: {
-                    id: item.id
-                  }
+                const url =
+                  location.origin +
+                  location.pathname +
+                  '#/music-detail?id=' +
+                  item.id
+                openDefaultWebView(url, () => {
+                  router.push({
+                    path: '/music-detail',
+                    query: {
+                      id: item.id
+                    }
+                  })
                 })
               }}
             />

+ 12 - 5
src/views/music/personal/personal.tsx

@@ -91,11 +91,18 @@ export default defineComponent({
             <Song
               list={rows.value}
               onDetail={(item: any) => {
-                router.push({
-                  path: '/music-detail',
-                  query: {
-                    id: item.id
-                  }
+                const url =
+                  location.origin +
+                  location.pathname +
+                  '#/music-detail?id=' +
+                  item.id
+                openDefaultWebView(url, () => {
+                  router.push({
+                    path: '/music-detail',
+                    query: {
+                      id: item.id
+                    }
+                  })
                 })
               }}
             />

+ 13 - 6
src/views/music/personal/practice.tsx

@@ -3,7 +3,7 @@ import { useAsyncState } from '@vueuse/core'
 import { defineComponent, ref } from 'vue'
 import { Cell, Skeleton } from 'vant'
 import Item from '../list/item'
-import { state } from '@/state'
+import { openDefaultWebView, state } from '@/state'
 import styles from './index.module.less'
 import Song from '../component/song'
 import { useRouter } from 'vue-router'
@@ -47,11 +47,18 @@ export default defineComponent({
             <Song
               list={list}
               onDetail={(item: any) => {
-                router.push({
-                  path: '/music-detail',
-                  query: {
-                    id: item.id
-                  }
+                const url =
+                  location.origin +
+                  location.pathname +
+                  '#/music-detail?id=' +
+                  item.id
+                openDefaultWebView(url, () => {
+                  router.push({
+                    path: '/music-detail',
+                    query: {
+                      id: item.id
+                    }
+                  })
                 })
               }}
             />

+ 13 - 6
src/views/music/songbook/list.tsx

@@ -9,7 +9,7 @@ import ColResult from '@/components/col-result'
 // import { state as tempState } from '@/state'
 import { SubjectEnum, useSubjectId } from '@/helpers/hooks'
 import Song from '../component/song'
-import { state } from '@/state'
+import { openDefaultWebView, state } from '@/state'
 
 export default defineComponent({
   name: 'Songbook',
@@ -101,11 +101,18 @@ export default defineComponent({
               <Song
                 list={data.value.rows}
                 onDetail={(item: any) => {
-                  router.push({
-                    path: '/music-detail',
-                    query: {
-                      id: item.id
-                    }
+                  const url =
+                    location.origin +
+                    location.pathname +
+                    '#/music-detail?id=' +
+                    item.id
+                  openDefaultWebView(url, () => {
+                    router.push({
+                      path: '/music-detail',
+                      query: {
+                        id: item.id
+                      }
+                    })
                   })
                 }}
               />