bzkf30 před 1 rokem
revize
75b21a6a30

+ 27 - 0
.gitignore

@@ -0,0 +1,27 @@
+# Logs
+logs
+*.log
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+pnpm-debug.log*
+lerna-debug.log*
+
+node_modules
+dist
+dist-ssr
+*.local
+
+# Editor directories and files
+.vscode/*
+!.vscode/extensions.json
+.idea
+.DS_Store
+*.suo
+*.ntvs*
+*.njsproj
+*.sln
+*.sw?
+
+components.d.ts
+auto-imports.d.ts

+ 3 - 0
.vscode/extensions.json

@@ -0,0 +1,3 @@
+{
+  "recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
+}

+ 18 - 0
README.md

@@ -0,0 +1,18 @@
+# Vue 3 + TypeScript + Vite
+
+This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
+
+## Recommended IDE Setup
+
+- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).
+
+## Type Support For `.vue` Imports in TS
+
+TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types.
+
+If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps:
+
+1. Disable the built-in TypeScript Extension
+   1. Run `Extensions: Show Built-in Extensions` from VSCode's command palette
+   2. Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
+2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.

+ 13 - 0
index.html

@@ -0,0 +1,13 @@
+<!doctype html>
+<html lang="en">
+  <head>
+    <meta charset="UTF-8" />
+    <link rel="icon" type="image/svg+xml" href="/vite.svg" />
+    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+    <title>Ai慕课</title>
+  </head>
+  <body>
+    <div id="app"></div>
+    <script type="module" src="/src/main.ts"></script>
+  </body>
+</html>

+ 31 - 0
package.json

@@ -0,0 +1,31 @@
+{
+  "name": "ai_mooc_h5",
+  "private": true,
+  "version": "0.0.0",
+  "type": "module",
+  "scripts": {
+    "dev": "vite",
+    "build": "vue-tsc && vite build",
+    "preview": "vite preview"
+  },
+  "dependencies": {
+    "@vueuse/core": "^10.1.2",
+    "axios": "^1.6.2",
+    "sass": "1.62.1",
+    "vant": "^4.8.0",
+    "vite-plugin-pages": "^0.32.0",
+    "vite-plugin-windicss": "^1.9.2",
+    "vue": "^3.3.11",
+    "vue-router": "^4.2.5"
+  },
+  "devDependencies": {
+    "@vitejs/plugin-legacy": "^4.0.5",
+    "@vitejs/plugin-vue": "^4.5.2",
+    "typescript": "^5.2.2",
+    "unplugin-auto-import": "^0.16.7",
+    "unplugin-vue-components": "^0.25.2",
+    "unplugin-vue-macros": "^2.6.2",
+    "vite": "^5.0.8",
+    "vue-tsc": "^1.8.25"
+  }
+}

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 4520 - 0
pnpm-lock.yaml


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 1 - 0
public/vite.svg


+ 10 - 0
src/App.vue

@@ -0,0 +1,10 @@
+<script setup lang="ts">
+</script>
+
+<template>
+  <router-view class="h-screen w-screen bg-hex-40424a"></router-view>
+</template>
+
+<style scoped>
+
+</style>

binární
src/assets/caiji.png


binární
src/assets/caiji_active.png


+ 1 - 0
src/assets/vue.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>

binární
src/assets/wode.png


binární
src/assets/wode_active.png


+ 38 - 0
src/components/HelloWorld.vue

@@ -0,0 +1,38 @@
+<script setup lang="ts">
+import { ref } from 'vue'
+
+defineProps<{ msg: string }>()
+
+const count = ref(0)
+</script>
+
+<template>
+  <h1>{{ msg }}</h1>
+
+  <div class="card">
+    <button type="button" @click="count++">count is {{ count }}</button>
+    <p>
+      Edit
+      <code>components/HelloWorld.vue</code> to test HMR
+    </p>
+  </div>
+
+  <p>
+    Check out
+    <a href="https://vuejs.org/guide/quick-start.html#local" target="_blank"
+      >create-vue</a
+    >, the official Vue + Vite starter
+  </p>
+  <p>
+    Install
+    <a href="https://github.com/vuejs/language-tools" target="_blank">Volar</a>
+    in your IDE for a better DX
+  </p>
+  <p class="read-the-docs">Click on the Vite and Vue logos to learn more</p>
+</template>
+
+<style scoped>
+.read-the-docs {
+  color: #888;
+}
+</style>

+ 11 - 0
src/main.ts

@@ -0,0 +1,11 @@
+import { createApp } from 'vue'
+import router from './router/index'
+import App from './App.vue'
+
+import './style.css'
+import 'virtual:windi.css'
+
+const app = createApp(App)
+
+app.use(router)
+app.mount('#app')

+ 71 - 0
src/pages/home.vue

@@ -0,0 +1,71 @@
+<template>
+  <div>
+    <router-view></router-view>
+    <van-tabbar v-model="active" @change="onChange">
+      <van-tabbar-item v-for="(item, index) in tabData" :key="index" :name="item.name">
+        <span>{{item.title}}</span>
+        <template #icon="props">
+          <img :src="props.active ? item.icon_active : item.icon" />
+        </template>
+      </van-tabbar-item>
+    </van-tabbar>
+  </div>
+</template>
+
+<script setup>
+import caiji from "~/assets/caiji.png";
+import caiji_active from "~/assets/caiji_active.png";
+import wode from "~/assets/wode.png";
+import wode_active from "~/assets/wode_active.png";
+
+const router = useRouter()
+
+let active = $ref("");
+const tabData = $ref([
+  {
+    title: "采集",
+    name: "caiji",
+    icon: caiji,
+    icon_active: caiji_active,
+    url: "/home/caiji"
+  },
+  {
+    title: "我的",
+    name: "wode",
+    icon: wode,
+    icon_active: wode_active,
+    url: "/home/wode"
+  }
+])
+
+init()
+function init() {
+  let path = router.currentRoute.value.path;
+  let index = tabData.findIndex(item => path.includes(item.url));
+  if (index !== -1)
+    active = tabData[index].name;
+  else
+    active = tabData[0].name;
+}
+
+function onChange(name) {
+  let index = tabData.findIndex(item => item.name === name);
+  let url = tabData[index].url;
+  router.push({
+    path: url
+  })
+}
+</script>
+
+<style lang="scss" scoped>
+.van-tabbar {
+  background: unset;
+  .van-tabbar-item {
+    color: #b3b3b3;
+  }
+  .van-tabbar-item--active {
+    color: #db664d;
+    background: unset;
+  }
+}
+</style>

+ 15 - 0
src/pages/home/caiji/index.vue

@@ -0,0 +1,15 @@
+<template>
+  <div>
+    <van-nav-bar title="采集"></van-nav-bar>
+  </div>
+</template>
+
+<script>
+export default {
+
+}
+</script>
+
+<style>
+
+</style>

+ 15 - 0
src/pages/home/wode/index.vue

@@ -0,0 +1,15 @@
+<template>
+  <div>
+    <van-nav-bar title="个人中心"></van-nav-bar>
+  </div>
+</template>
+
+<script>
+export default {
+
+}
+</script>
+
+<style>
+
+</style>

+ 22 - 0
src/router/index.ts

@@ -0,0 +1,22 @@
+import routes from 'virtual:generated-pages'
+import { createRouter, createWebHashHistory } from 'vue-router'
+
+// import { user } from '~/store/index'
+
+console.log('routes : ', routes)
+const router = createRouter({
+  history: createWebHashHistory(import.meta.env.BASE_URL),
+  routes,
+})
+
+router.beforeEach((to, from) => {
+  if (to.path === "/" || to.path === "/home") {
+    return { path: '/home/caiji' }
+  }
+  // if (user.value?.token)
+  return true
+  // else if (!user.value?.token && to.name !== 'login' && to.name !== 'forgetPsw' && to.path !== '/forgetPsw/newPsw')
+  //   return { name: 'login' }
+})
+
+export default router

+ 15 - 0
src/style.css

@@ -0,0 +1,15 @@
+body {
+  margin: 0;
+}
+
+.van-nav-bar {
+  background: unset !important;
+}
+
+.van-nav-bar .van-nav-bar__title {
+  color: #fff;
+}
+
+.van-nav-bar:after {
+  content: none !important;
+}

+ 1 - 0
src/vite-env.d.ts

@@ -0,0 +1 @@
+/// <reference types="vite/client" />

+ 25 - 0
tsconfig.json

@@ -0,0 +1,25 @@
+{
+  "compilerOptions": {
+    "target": "ES2020",
+    "useDefineForClassFields": true,
+    "module": "ESNext",
+    "lib": ["ES2020", "DOM", "DOM.Iterable"],
+    "skipLibCheck": true,
+
+    /* Bundler mode */
+    "moduleResolution": "bundler",
+    "allowImportingTsExtensions": true,
+    "resolveJsonModule": true,
+    "isolatedModules": true,
+    "noEmit": true,
+    "jsx": "preserve",
+
+    /* Linting */
+    "strict": true,
+    "noUnusedLocals": true,
+    "noUnusedParameters": true,
+    "noFallthroughCasesInSwitch": true
+  },
+  "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
+  "references": [{ "path": "./tsconfig.node.json" }]
+}

+ 10 - 0
tsconfig.node.json

@@ -0,0 +1,10 @@
+{
+  "compilerOptions": {
+    "composite": true,
+    "skipLibCheck": true,
+    "module": "ESNext",
+    "moduleResolution": "bundler",
+    "allowSyntheticDefaultImports": true
+  },
+  "include": ["vite.config.ts"]
+}

+ 90 - 0
vite.config.ts

@@ -0,0 +1,90 @@
+/// <reference types="vitest" />
+
+import path from 'node:path'
+import { defineConfig } from 'vite'
+import Vue from '@vitejs/plugin-vue'
+import Pages from 'vite-plugin-pages'
+import Components from 'unplugin-vue-components/vite'
+
+import AutoImport from 'unplugin-auto-import/vite'
+import WindiCSS from 'vite-plugin-windicss'
+import VueMacros from 'unplugin-vue-macros/vite'
+import { VantResolver } from 'unplugin-vue-components/resolvers'
+import legacyPlugin from '@vitejs/plugin-legacy'
+export default defineConfig({
+  base: '',
+  resolve: {
+    alias: {
+      '~/': `${path.resolve(__dirname, 'src')}/`,
+    },
+  },
+  server: {
+    hmr: { overlay: false }, // 禁用或配置 HMR 连接 设置 server.hmr.overlay 为 false 可以禁用服务器错误遮罩层
+  },
+  plugins: [
+    legacyPlugin({
+      targets: ['chrome 52'],  // 需要兼容的目标列表,可以设置多个
+      additionalLegacyPolyfills: ['regenerator-runtime/runtime'] // 面向IE11时需要此插件
+    }),
+
+    VueMacros({
+      defineOptions: false,
+      defineModels: false,
+      plugins: {
+        vue: Vue({
+          script: {
+            propsDestructure: true,
+            defineModel: true,
+          },
+        }),
+      },
+    }),
+
+    // https://github.com/hannoeru/vite-plugin-pages
+    Pages(
+      {
+        dirs: 'src/pages',
+        exclude: ['**/components/*.vue'],
+      },
+    ),
+
+    // https://github.com/antfu/unplugin-auto-import
+    AutoImport({
+      imports: [
+        'vue',
+        'vue/macros',
+        'vue-router',
+        '@vueuse/core',
+      ],
+      dts: true,
+      dirs: [
+        './src/composables',
+        './src/request',
+        './src/utils',
+      ],
+      vueTemplate: true,
+      resolvers: [
+
+      ],
+    }),
+
+    // https://github.com/antfu/vite-plugin-components
+    Components({
+      dirs: ['src/components/'],
+      // allow auto load markdown components under `./src/components/`
+      extensions: ['vue', 'md'],
+      // allow auto import and register components used in markdown
+      include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
+      resolvers: [VantResolver()],
+    }),
+
+    // https://github.com/antfu/unocss
+    // see uno.config.ts for config
+    WindiCSS(),
+  ],
+
+  // https://github.com/vitest-dev/vitest
+  test: {
+    environment: 'jsdom',
+  },
+})