冯诚 2 years ago
commit
5b39253ccd
22 changed files with 2437 additions and 0 deletions
  1. 2 0
      .eslintignore
  2. 13 0
      .eslintrc.js
  3. 5 0
      .gitignore
  4. 6 0
      .prettierrc
  5. 3 0
      .vscode/extensions.json
  6. 11 0
      README.md
  7. 13 0
      index.html
  8. 24 0
      package.json
  9. 11 0
      postcss.config.js
  10. BIN
      public/favicon.ico
  11. 21 0
      src/App.vue
  12. BIN
      src/assets/logo.png
  13. 52 0
      src/components/HelloWorld.vue
  14. 8 0
      src/env.d.ts
  15. 6 0
      src/main.ts
  16. 4 0
      src/style/_variables.scss
  17. 1 0
      src/style/index.js
  18. 117 0
      src/style/normalize.scss
  19. 31 0
      src/utils/rem.js
  20. 19 0
      tsconfig.json
  21. 21 0
      vite.config.ts
  22. 2069 0
      yarn.lock

+ 2 - 0
.eslintignore

@@ -0,0 +1,2 @@
+node_modules
+/dist

+ 13 - 0
.eslintrc.js

@@ -0,0 +1,13 @@
+module.exports = {
+  extends: ['ktsn-vue'],
+
+  rules: {
+    'no-unused-expressions': 'off',
+    'no-empty': 'off',
+    'no-control-regex': 'off',
+    'vue/valid-template-root': 'off',
+    'vue/require-default-prop': 'off',
+    'vue/no-v-html': 'off',
+    '@typescript-eslint/no-empty-interface': 'off'
+  },
+}

+ 5 - 0
.gitignore

@@ -0,0 +1,5 @@
+node_modules
+.DS_Store
+dist
+dist-ssr
+*.local

+ 6 - 0
.prettierrc

@@ -0,0 +1,6 @@
+{
+  "semi": false,
+  "singleQuote": true,
+  "arrowParens": "avoid",
+  "trailingComma": "es5"
+}

+ 3 - 0
.vscode/extensions.json

@@ -0,0 +1,3 @@
+{
+  "recommendations": ["johnsoncodehk.volar"]
+}

+ 11 - 0
README.md

@@ -0,0 +1,11 @@
+# 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
+
+- [VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar)
+
+## Type Support For `.vue` Imports in TS
+
+Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can enable Volar's `.vue` type support plugin by running `Volar: Switch TS Plugin on/off` from VSCode command palette.

+ 13 - 0
index.html

@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="UTF-8" />
+    <link rel="icon" href="/favicon.ico" />
+    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+    <title>Vite App</title>
+  </head>
+  <body>
+    <div id="app"></div>
+    <script type="module" src="/src/main.ts"></script>
+  </body>
+</html>

+ 24 - 0
package.json

@@ -0,0 +1,24 @@
+{
+  "name": "ptc",
+  "version": "0.0.0",
+  "scripts": {
+    "dev": "vite",
+    "build": "vue-tsc --noEmit && vite build",
+    "preview": "vite preview"
+  },
+  "dependencies": {
+    "vue": "^3.2.25"
+  },
+  "devDependencies": {
+    "@vitejs/plugin-vue": "^2.0.0",
+    "eslint": "^6.7.2",
+    "eslint-config-ktsn-vue": "^2.1.0",
+    "postcss-pxtorem": "^5.1.1",
+    "prettier": "^1.19.1",
+    "sass": "^1.47.0",
+    "sass-loader": "^12.4.0",
+    "typescript": "^4.4.4",
+    "vite": "^2.7.2",
+    "vue-tsc": "^0.29.8"
+  }
+}

+ 11 - 0
postcss.config.js

@@ -0,0 +1,11 @@
+module.exports = {
+  plugins: {
+    'postcss-pxtorem': {
+      rootValue(input) {
+        return /[\\/]node_modules[\\/]vant/.test(input.file) ? 37.5 : 75
+      },
+      propList: ['*', '!filter'],
+      minPixelValue: 2, // 不对1像素做转换
+    },
+  },
+}

BIN
public/favicon.ico


+ 21 - 0
src/App.vue

@@ -0,0 +1,21 @@
+<script setup lang="ts">
+// This starter template is using Vue 3 <script setup> SFCs
+// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
+import HelloWorld from './components/HelloWorld.vue'
+</script>
+
+<template>
+  <img alt="Vue logo" src="./assets/logo.png" />
+  <HelloWorld msg="Hello Vue 3 + TypeScript + Vite" />
+</template>
+
+<style>
+#app {
+  font-family: Avenir, Helvetica, Arial, sans-serif;
+  -webkit-font-smoothing: antialiased;
+  -moz-osx-font-smoothing: grayscale;
+  text-align: center;
+  color: #2c3e50;
+  margin-top: 60px;
+}
+</style>

BIN
src/assets/logo.png


+ 52 - 0
src/components/HelloWorld.vue

@@ -0,0 +1,52 @@
+<script setup lang="ts">
+import { ref } from 'vue'
+
+defineProps<{ msg: string }>()
+
+const count = ref(0)
+</script>
+
+<template>
+  <h1>{{ msg }}</h1>
+
+  <p>
+    Recommended IDE setup:
+    <a href="https://code.visualstudio.com/" target="_blank">VSCode</a>
+    +
+    <a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a>
+  </p>
+
+  <p>See <code>README.md</code> for more information.</p>
+
+  <p>
+    <a href="https://vitejs.dev/guide/features.html" target="_blank">
+      Vite Docs
+    </a>
+    |
+    <a href="https://v3.vuejs.org/" target="_blank">Vue 3 Docs</a>
+  </p>
+
+  <button type="button" @click="count++">count is: {{ count }}</button>
+  <p>
+    Edit
+    <code>components/HelloWorld.vue</code> to test hot module replacement.
+  </p>
+</template>
+
+<style scoped>
+a {
+  color: #42b983;
+}
+
+label {
+  margin: 0 0.5em;
+  font-weight: bold;
+}
+
+code {
+  background-color: #eee;
+  padding: 2px 4px;
+  border-radius: 4px;
+  color: #304455;
+}
+</style>

+ 8 - 0
src/env.d.ts

@@ -0,0 +1,8 @@
+/// <reference types="vite/client" />
+
+declare module '*.vue' {
+  import { DefineComponent } from 'vue'
+  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
+  const component: DefineComponent<{}, {}, any>
+  export default component
+}

+ 6 - 0
src/main.ts

@@ -0,0 +1,6 @@
+import { createApp } from 'vue'
+import App from './App.vue'
+import './utils/rem'
+import './style'
+
+createApp(App).mount('#app')

+ 4 - 0
src/style/_variables.scss

@@ -0,0 +1,4 @@
+$primary-color: #1A3059;
+$danger-color: #EB3735;
+$border-color: #D9D9D9;
+$placeholder-color: #bebebe;

+ 1 - 0
src/style/index.js

@@ -0,0 +1 @@
+import './normalize.scss'

+ 117 - 0
src/style/normalize.scss

@@ -0,0 +1,117 @@
+*,
+*::before,
+*::after {
+  box-sizing: border-box;
+}
+
+html {
+  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
+  -webkit-overflow-scrolling: touch;
+  font-family: Avenir, Helvetica, Arial, sans-serif;
+  -webkit-font-smoothing: antialiased;
+  -moz-osx-font-smoothing: grayscale;
+}
+
+body,
+dl,
+dd,
+h1,
+h2,
+h3,
+h4,
+h5,
+h6,
+p,
+input {
+  margin: 0;
+}
+
+ol,
+ul {
+  margin: 0;
+  padding: 0;
+  list-style: none;
+  font-size: 0;
+}
+
+h1,
+h2,
+h3,
+h4,
+h5,
+h6 {
+  font-weight: normal;
+}
+
+article,
+aside,
+footer,
+header,
+hgroup,
+nav,
+section {
+  display: block;
+}
+
+button,
+input,
+select,
+textarea {
+  padding: 0;
+  border-radius: 0;
+  border: none;
+  outline: none;
+  font-size: inherit;
+  background: none;
+}
+
+textarea {
+  resize: none;
+}
+
+input::-webkit-outer-spin-button,
+input::-webkit-inner-spin-button {
+  -webkit-appearance: none;
+}
+
+input[type='search'] {
+  &::-webkit-search-cancel-button {
+    -webkit-appearance: none;
+  }
+  &::-webkit-search-decoration {
+    -webkit-appearance: none;
+  }
+}
+
+input[type='number'] {
+  -moz-appearance: textfield;
+}
+
+input,
+input:focus,
+button,
+button:focus {
+  -webkit-tap-highlight-color: transparent;
+}
+
+img {
+  border: none;
+  vertical-align: top;
+}
+
+a {
+  outline: none;
+  text-decoration: none;
+}
+
+i {
+  font-style: normal;
+}
+
+::-webkit-input-placeholder {
+  color: $placeholder-color;
+}
+
+::-webkit-scrollbar {
+  display: none;
+}

+ 31 - 0
src/utils/rem.js

@@ -0,0 +1,31 @@
+// 设置 rem 函数
+export function setRem() {
+  const doc = document
+  const h = Math.max(doc.documentElement.clientHeight, window.innerHeight || 0)
+  const w = Math.max(doc.documentElement.clientWidth, window.innerWidth || 0)
+
+  let width = w
+  width = width > 750 ? 750 : width
+
+  const fz = ~~((width * 100000) / 100) / 10000
+  doc.getElementsByTagName('html')[0].style.cssText = 'font-size: ' + fz + 'px'
+
+  const realfz =
+    ~~(
+      +window
+        .getComputedStyle(doc.getElementsByTagName('html')[0])
+        .fontSize.replace('px', '') * 10000
+    ) / 10000
+  if (fz !== realfz) {
+    doc.getElementsByTagName('html')[0].style.cssText =
+      'font-size: ' + fz * (fz / realfz) + 'px'
+  }
+}
+
+// 初始化
+setRem()
+
+// 改变窗口大小时重新设置 rem
+window.onresize = function() {
+  setRem()
+}

+ 19 - 0
tsconfig.json

@@ -0,0 +1,19 @@
+{
+  "compilerOptions": {
+    "target": "esnext",
+    "useDefineForClassFields": true,
+    "module": "esnext",
+    "moduleResolution": "node",
+    "strict": true,
+    "jsx": "preserve",
+    "sourceMap": true,
+    "resolveJsonModule": true,
+    "esModuleInterop": true,
+    "lib": ["esnext", "dom"],
+    "baseUrl": ".",
+    "paths": {
+      "@/*": ["src/*"]
+    }
+  },
+  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
+}

+ 21 - 0
vite.config.ts

@@ -0,0 +1,21 @@
+import { defineConfig } from 'vite'
+import vue from '@vitejs/plugin-vue'
+import path from 'path'
+
+// https://vitejs.dev/config/
+export default defineConfig({
+  plugins: [vue()],
+  resolve: {
+    alias: {
+      '@': path.join(__dirname, 'src'),
+      '@img': path.join(__dirname, 'src/assets'),
+    },
+  },
+  css: {
+    preprocessorOptions: {
+      scss: {
+        additionalData: '@import "@/style/_variables.scss";',
+      },
+    },
+  },
+})

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