Browse Source

添加逻辑

lex 10 months ago
parent
commit
da71837ca9

File diff suppressed because it is too large
+ 9337 - 1
package-lock.json


+ 1 - 0
src/state.ts

@@ -21,6 +21,7 @@ export const state = reactive({
   payBackPath: '/tenant/',
   platformType: '' as 'STUDENT' | 'TEACHER',
   platformApi: '/api-student' as '/api-student' | '/api-teacher',
+  sourcType: 'colexiu' as 'colexiu' | 'kt', // 酷乐秀 课堂乐器
   version: '', // 版本号 例如: 1.0.0
   ossUploadUrl: 'https://ks3-cn-beijing.ksyuncs.com/',
   musicCertStatus: false as boolean, // 是否音乐认证

+ 95 - 63
src/student/main.ts

@@ -9,80 +9,112 @@ import {
   postMessage,
   promisefiyPostMessage
 } from '@/helpers/native-message'
-
 import 'normalize.css'
-
 import '../styles/index.less'
 import { state } from '@/state'
+import qs from 'query-string'
 import { browser, setAuth } from '@/helpers/utils'
+import request from '@/helpers/request'
 
 const app = createApp(App)
 
-// import Vconsole from 'vconsole'
-// const vconsole = new Vconsole()
-// 设置是否显示导航栏 0 显示 1 不显示
-postMessage({ api: 'setBarStatus', content: { status: 0 } })
-postMessage({
-  api: 'backIconChange',
-  content: { backIconHide: true }
-})
-postMessage(
-  {
-    api: 'getVersion'
-  },
-  (res: any) => {
-    state.version = res.content.version
+const getClassroomDefaultInfo = async () => {
+  state.sourcType = 'kt'
+  await promisefiyPostMessage({ api: 'getUserAccount' }).then(
+    async (res: any) => {
+      const content = res.content
+      // state.orchestraInfo.token = content.token.split(' ')[1]
+      // state.orchestraInfo.phone = content.phone
+      // state.orchestraInfo.nickname = content.nickname
+      // state.orchestraInfo.avatar = content.avatar
+      // state.orchestraInfo.unionId = content.unionId || 0
+      console.log(content, 'orchestra')
+      const { data } = await request.post('/api-auth/smsLogin', {
+        requestType: 'form',
+        data: {
+          clientId: 'student',
+          clientSecret: 'student',
+          phone: content.phone,
+          isSurportRegister: true,
+          token: content.token.split(' ')[1]
+        }
+      })
+      const { authentication } = data
+      setAuth(authentication.token_type + ' ' + authentication.access_token)
+    }
+  )
+}
+
+const initProject = async () => {
+  // import Vconsole from 'vconsole'
+  // const vconsole = new Vconsole()
+  // 设置是否显示导航栏 0 显示 1 不显示
+  postMessage({ api: 'setBarStatus', content: { status: 0 } })
+  postMessage({
+    api: 'backIconChange',
+    content: { backIconHide: true }
+  })
+  postMessage(
+    {
+      api: 'getVersion'
+    },
+    (res: any) => {
+      state.version = res.content.version
+    }
+  )
+
+  // 判断是否是管乐团学生端,用来获取基础数据
+  if (browser().isOrchestraStudent) {
+    // 获取管乐团token
+    promisefiyPostMessage({ api: 'getUserAccount' }).then((res: any) => {
+      const content = res.content
+      state.orchestraInfo.token = content.token.split(' ')[1]
+      state.orchestraInfo.phone = content.phone
+      state.orchestraInfo.nickname = content.nickname
+      state.orchestraInfo.avatar = content.avatar
+      state.orchestraInfo.unionId = content.unionId || 0
+    })
+
+    // 从缓存里面获取token
+    promisefiyPostMessage({
+      api: 'getCache',
+      content: { key: 'h5-colexiu-token' }
+    }).then((res: any) => {
+      const content = res.content
+      if (content.value) {
+        setAuth(content.value)
+      }
+    })
   }
-)
 
-// 判断是否是管乐团学生端,用来获取基础数据
-if (browser().isOrchestraStudent) {
-  // await promisefiyPostMessage({
-  //   api: 'setCache',
-  //   content: {
-  //     key: 'h5-colexiu-token',
-  //     value: ''
-  //   }
-  // })
+  // 判断是否是课堂乐器学生端,用来获取基础数据
+  const parseSearch: any = qs.parse(location.search)
+  const hashSearch = qs.parse(location.hash.split('?')[1])
+  const source: string = parseSearch.source || hashSearch.source || ''
+  if (source === 'kt') {
+    // 获取课堂乐器token
+    await getClassroomDefaultInfo()
+  }
 
-  // 获取管乐团token
-  promisefiyPostMessage({ api: 'getUserAccount' }).then((res: any) => {
-    const content = res.content
-    state.orchestraInfo.token = content.token.split(' ')[1]
-    state.orchestraInfo.phone = content.phone
-    state.orchestraInfo.nickname = content.nickname
-    state.orchestraInfo.avatar = content.avatar
-    state.orchestraInfo.unionId = content.unionId || 0
-  })
+  if (browser().isTeacher) {
+    state.platformType = 'TEACHER'
+  } else if (browser().isStudent) {
+    state.platformType = 'STUDENT'
+  } else {
+    state.platformType = 'STUDENT'
+  }
+  if (state.platformType === 'TEACHER') {
+    state.platformApi = '/api-teacher'
+  } else {
+    state.platformApi = '/api-student'
+  }
 
-  // 从缓存里面获取token
-  promisefiyPostMessage({
-    api: 'getCache',
-    content: { key: 'h5-colexiu-token' }
-  }).then((res: any) => {
-    const content = res.content
-    if (content.value) {
-      setAuth(content.value)
-    }
-  })
-}
+  dayjs.locale('zh-ch')
+  app.config.globalProperties.$dayjs = dayjs
+  app.config.globalProperties.$filters = vueFilter
+  app.use(router)
 
-if (browser().isTeacher) {
-  state.platformType = 'TEACHER'
-} else if (browser().isStudent) {
-  state.platformType = 'STUDENT'
-} else {
-  state.platformType = 'STUDENT'
+  app.mount('#app')
 }
-if (state.platformType === 'TEACHER') {
-  state.platformApi = '/api-teacher'
-} else {
-  state.platformApi = '/api-student'
-}
-
-dayjs.locale('zh-ch')
-app.config.globalProperties.$dayjs = dayjs
-app.config.globalProperties.$filters = vueFilter
-app.use(router)
 
-app.mount('#app')
+initProject()

+ 2 - 1
src/views/order-detail/payment/index.tsx

@@ -120,7 +120,8 @@ export default defineComponent({
           paymentClient: null as any
         }
         if (this.paymentType === 'goodsPay') {
-          params.paymentClient = state.platformType
+          params.paymentClient =
+            state.sourcType === 'kt' ? 'KT_STUDENT' : state.platformType
         }
         const res = await request.post(urlType[this.paymentType].payUrl, {
           data: {

+ 15 - 3
src/views/shop-mall/components/TheHomeHeader/index.tsx

@@ -11,6 +11,8 @@ import { Badge, Popover } from 'vant'
 import { postMessage } from '@/helpers/native-message'
 import { cartCount } from '../../shop-mall'
 import { useRect } from '@vant/use'
+import { state } from '@/state'
+import ColHeader from '@/components/col-header'
 
 export default defineComponent({
   name: 'TheHomeHeader',
@@ -55,9 +57,19 @@ export default defineComponent({
     ]
     return () => (
       <div class={styles.theHomeHeader} ref={homeHeaderDom}>
-        <div
-          style={{ height: navBarHeight.value + 'px', background: '#fff' }}
-        ></div>
+        {/* state.sourcType === 'kt' ? 0 : */}
+        {/* 课堂乐器进来时不显示头部 */}
+        {state.sourcType === 'kt' ? (
+          <ColHeader />
+        ) : (
+          <div
+            style={{
+              height: navBarHeight.value + 'px',
+              background: '#fff'
+            }}
+          ></div>
+        )}
+
         <div class={styles.content}>
           <img class={styles.mall} src={IconMall} />
           <div class={styles.searchBox} onClick={() => emit('search')}>

+ 220 - 212
src/views/shop-mall/index.tsx

@@ -1,212 +1,220 @@
-import ColHeader from '@/components/col-header'
-import {
-  Badge,
-  Dialog,
-  Divider,
-  Icon,
-  Image,
-  PullRefresh,
-  Sticky,
-  Swipe,
-  SwipeItem,
-  Tab,
-  Tabs
-} from 'vant'
-import { defineComponent } from 'vue'
-import HotGoods from './components/hot-goods'
-import MenuList from './components/menu-list'
-import TabList from './components/tab-list'
-import styles from './index.module.less'
-import iconShopCart from './images/icon-shop-cart.png'
-import request from '@/helpers/request'
-import { useRect } from '@vant/use'
-import {
-  listenerMessage,
-  postMessage,
-  removeListenerMessage
-} from '@/helpers/native-message'
-import ColSearch from '@/components/col-search'
-import { browser, setAuth } from '@/helpers/utils'
-import { cartCount, getCartCount } from './shop-mall'
-import TheHomeHeader from './components/TheHomeHeader'
-
-export default defineComponent({
-  name: 'shop-mall',
-  data() {
-    return {
-      loading: false,
-      height: 'auto' as any,
-      count: 0, // 购买车数量
-      advertiseList: [], // 广告列表
-      productList: [], // 商品分类
-      hotProductList: [], // 热门商品列表
-      productCategoryList: [] // 商品分类列表
-    }
-  },
-  mounted() {
-    this.init()
-    if (browser().ios) {
-      document.addEventListener('visibilitychange', event => {
-        if (!document.hidden) {
-          getCartCount()
-          const tabFirst = this.$refs.tabFirst as any
-          tabFirst?.onSearch()
-        }
-      })
-    } else {
-      listenerMessage('UpdateToken', result => {
-        if (result?.content.token) {
-          setAuth(result?.content.token)
-        }
-        getCartCount()
-        const tabFirst = this.$refs.tabFirst as any
-        tabFirst?.onSearch()
-      })
-    }
-  },
-  unmounted() {
-    removeListenerMessage('UpdateToken', () => {})
-  },
-  methods: {
-    onRefresh() {
-      this.productCategoryList = []
-      this.$nextTick(() => {
-        this.init()
-      })
-      const tabFirst = this.$refs.tabFirst as any
-      tabFirst?.onSearch()
-    },
-    async init() {
-      try {
-        const res = await request.get('/api-mall-portal/home/content')
-        const result = res.data || {}
-        this.count = result.count
-        cartCount.value = result.count
-        this.advertiseList = result.advertiseList
-        const category = result.productCategoryList || []
-        const categoryResult: any = []
-        while (category.length > 0) {
-          const chunk = category.splice(0, 5)
-          categoryResult.push(chunk)
-        }
-        this.productList = categoryResult
-        this.hotProductList = result.hotProductList || []
-        this.productCategoryList = result.productAttributeCategoryList || []
-      } catch {}
-      setTimeout(() => {
-        this.loading = false
-      }, 500)
-    },
-    openWebView(url: string): void {
-      try {
-        const origin = location.origin + location.pathname + '#'
-        if (!url) return
-
-        if (url.indexOf('http') < 0) {
-          url = origin + url
-        }
-        console.log('跳转url:', url)
-        if (!browser().isApp) {
-          location.href = url
-          return
-        }
-        postMessage({
-          api: 'openWebView',
-          content: {
-            url: url,
-            orientation: 1,
-            isHideTitle: false
-          }
-        })
-      } catch (error) {}
-    }
-  },
-  render() {
-    return (
-      <div class={styles.shopMall}>
-        <TheHomeHeader
-          onCart={() => this.openWebView('/cart')}
-          onSearch={() => this.openWebView('/goodsList?input=focus')}
-          onHeaderDom={(height: number) => {
-            console.log(height, 'height')
-            this.height = height + 'px'
-          }}
-          onMore={action => {
-            if (!action) return
-            if (action.text == '我的地址') {
-              postMessage({
-                api: 'setAddress',
-                content: {}
-              })
-            } else {
-              this.openWebView(action.url)
-            }
-          }}
-        />
-        <PullRefresh
-          v-model={this.loading}
-          loading-text="正在刷新..."
-          success-text="刷新完成"
-          onRefresh={() => this.onRefresh()}
-        >
-          <div class={styles.hotContent}>
-            <Swipe class={styles.swipe} autoplay={3000}>
-              {this.advertiseList.map((item: any) => (
-                <SwipeItem onClick={() => this.openWebView(item.url)}>
-                  <Image
-                    class={styles.swipeItemImg}
-                    src={item.pic}
-                    fit="fill"
-                  />
-                </SwipeItem>
-              ))}
-            </Swipe>
-
-            <MenuList
-              productList={this.productList}
-              onOpenWebView={this.openWebView}
-            />
-          </div>
-
-          {this.hotProductList.length === 3 && (
-            <HotGoods
-              hotProductList={this.hotProductList}
-              onOpenWebView={this.openWebView}
-            />
-          )}
-
-          <Tabs
-            shrink
-            lineWidth={25}
-            background={'#f6f8f9'}
-            color="var(--van-primary)"
-            class={styles.tabs}
-            sticky
-            offsetTop={this.height}
-            lazyRender
-          >
-            <Tab title="全部" name={0}>
-              <TabList
-                ref="tabFirst"
-                isTab={true}
-                productAttributeCategoryId={0}
-                onOpenWebView={this.openWebView}
-                showAdd={false}
-              />
-            </Tab>
-            {this.productCategoryList.map((item: any) => (
-              <Tab title={item.name} name={item.id}>
-                <TabList
-                  isTab={true}
-                  showAdd={false}
-                  productAttributeCategoryId={item.id}
-                  onOpenWebView={this.openWebView}
-                />
-              </Tab>
-            ))}
-          </Tabs>
-        </PullRefresh>
-      </div>
-    )
-  }
-})
+import ColHeader from '@/components/col-header'
+import {
+  Badge,
+  Dialog,
+  Divider,
+  Icon,
+  Image,
+  PullRefresh,
+  Sticky,
+  Swipe,
+  SwipeItem,
+  Tab,
+  Tabs
+} from 'vant'
+import { defineComponent } from 'vue'
+import HotGoods from './components/hot-goods'
+import MenuList from './components/menu-list'
+import TabList from './components/tab-list'
+import styles from './index.module.less'
+import iconShopCart from './images/icon-shop-cart.png'
+import request from '@/helpers/request'
+import { useRect } from '@vant/use'
+import {
+  listenerMessage,
+  postMessage,
+  removeListenerMessage
+} from '@/helpers/native-message'
+import ColSearch from '@/components/col-search'
+import { browser, setAuth } from '@/helpers/utils'
+import { cartCount, getCartCount } from './shop-mall'
+import TheHomeHeader from './components/TheHomeHeader'
+import { state } from '@/state'
+
+export default defineComponent({
+  name: 'shop-mall',
+  data() {
+    return {
+      loading: false,
+      height: 'auto' as any,
+      count: 0, // 购买车数量
+      advertiseList: [], // 广告列表
+      productList: [], // 商品分类
+      hotProductList: [], // 热门商品列表
+      productCategoryList: [] // 商品分类列表
+    }
+  },
+  mounted() {
+    this.init()
+    if (browser().ios) {
+      document.addEventListener('visibilitychange', event => {
+        if (!document.hidden) {
+          getCartCount()
+          const tabFirst = this.$refs.tabFirst as any
+          tabFirst?.onSearch()
+        }
+      })
+    } else {
+      listenerMessage('UpdateToken', result => {
+        if (result?.content.token) {
+          setAuth(result?.content.token)
+        }
+        getCartCount()
+        const tabFirst = this.$refs.tabFirst as any
+        tabFirst?.onSearch()
+      })
+    }
+  },
+  unmounted() {
+    removeListenerMessage('UpdateToken', () => {})
+  },
+  methods: {
+    onRefresh() {
+      this.productCategoryList = []
+      this.$nextTick(() => {
+        this.init()
+      })
+      const tabFirst = this.$refs.tabFirst as any
+      tabFirst?.onSearch()
+    },
+    async init() {
+      try {
+        const res = await request.get('/api-mall-portal/home/content')
+        const result = res.data || {}
+        this.count = result.count
+        cartCount.value = result.count
+        this.advertiseList = result.advertiseList
+        const category = result.productCategoryList || []
+        const categoryResult: any = []
+        while (category.length > 0) {
+          const chunk = category.splice(0, 5)
+          categoryResult.push(chunk)
+        }
+        this.productList = categoryResult
+        this.hotProductList = result.hotProductList || []
+        this.productCategoryList = result.productAttributeCategoryList || []
+      } catch {}
+      setTimeout(() => {
+        this.loading = false
+      }, 500)
+    },
+    openWebView(url: string): void {
+      try {
+        const origin = location.origin + location.pathname + '#'
+        if (!url) return
+
+        if (url.indexOf('http') < 0) {
+          url = origin + url
+        }
+        if (!browser().isApp) {
+          location.href = url
+          return
+        }
+
+        if (state.sourcType === 'kt') {
+          if (url.indexOf('?') !== -1) {
+            url += `&source=kt`
+          } else {
+            url += `?source=kt`
+          }
+        }
+        postMessage({
+          api: 'openWebView',
+          content: {
+            url: url,
+            orientation: 1,
+            isHideTitle: false
+          }
+        })
+      } catch (error) {}
+    }
+  },
+  render() {
+    return (
+      <div class={styles.shopMall}>
+        <TheHomeHeader
+          onCart={() => this.openWebView('/cart')}
+          onSearch={() => this.openWebView('/goodsList?input=focus')}
+          onHeaderDom={(height: number) => {
+            console.log(height, 'height')
+            this.height = height + 'px'
+          }}
+          onMore={action => {
+            if (!action) return
+            if (action.text == '我的地址') {
+              postMessage({
+                api: 'setAddress',
+                content: {}
+              })
+            } else {
+              this.openWebView(action.url)
+            }
+          }}
+        />
+        <PullRefresh
+          v-model={this.loading}
+          loading-text="正在刷新..."
+          success-text="刷新完成"
+          onRefresh={() => this.onRefresh()}
+        >
+          <div class={styles.hotContent}>
+            <Swipe class={styles.swipe} autoplay={3000}>
+              {this.advertiseList.map((item: any) => (
+                <SwipeItem onClick={() => this.openWebView(item.url)}>
+                  <Image
+                    class={styles.swipeItemImg}
+                    src={item.pic}
+                    fit="fill"
+                  />
+                </SwipeItem>
+              ))}
+            </Swipe>
+
+            <MenuList
+              productList={this.productList}
+              onOpenWebView={this.openWebView}
+            />
+          </div>
+
+          {this.hotProductList.length === 3 && (
+            <HotGoods
+              hotProductList={this.hotProductList}
+              onOpenWebView={this.openWebView}
+            />
+          )}
+
+          <Tabs
+            shrink
+            lineWidth={25}
+            background={'#f6f8f9'}
+            color="var(--van-primary)"
+            class={styles.tabs}
+            sticky
+            offsetTop={this.height}
+            lazyRender
+          >
+            <Tab title="全部" name={0}>
+              <TabList
+                ref="tabFirst"
+                isTab={true}
+                productAttributeCategoryId={0}
+                onOpenWebView={this.openWebView}
+                showAdd={false}
+              />
+            </Tab>
+            {this.productCategoryList.map((item: any) => (
+              <Tab title={item.name} name={item.id}>
+                <TabList
+                  isTab={true}
+                  showAdd={false}
+                  productAttributeCategoryId={item.id}
+                  onOpenWebView={this.openWebView}
+                />
+              </Tab>
+            ))}
+          </Tabs>
+        </PullRefresh>
+      </div>
+    )
+  }
+})

File diff suppressed because it is too large
+ 317 - 317
yarn.lock


Some files were not shown because too many files changed in this diff