luohailiang 2 years ago
parent
commit
ee1802d745
16 changed files with 1638 additions and 0 deletions
  1. 26 0
      .gitignore
  2. 3 0
      .vscode/extensions.json
  3. 14 0
      index.html
  4. 29 0
      package.json
  5. 1272 0
      pnpm-lock.yaml
  6. 38 0
      public/config.js
  7. 10 0
      src/App.vue
  8. 1 0
      src/assets/vue.svg
  9. 41 0
      src/components/FileUpload/index.vue
  10. 11 0
      src/main.js
  11. 10 0
      src/router/index.js
  12. 6 0
      src/utils/day.js
  13. 80 0
      src/utils/request.js
  14. 7 0
      src/utils/string.js
  15. 73 0
      vite.config.js
  16. 17 0
      windi.config.ts

+ 26 - 0
.gitignore

@@ -0,0 +1,26 @@
+# 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?
+
+src/*.d.ts

+ 3 - 0
.vscode/extensions.json

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

+ 14 - 0
index.html

@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html lang="zh-CN">
+  <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, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
+    <title>ಥ_ಥ</title>
+  </head>
+  <body>
+    <div id="app"></div>
+    <script src="/config.js"></script>
+    <script type="module" src="/src/main.js"></script>
+  </body>
+</html>

+ 29 - 0
package.json

@@ -0,0 +1,29 @@
+{
+  "name": "vant-js-template",
+  "private": true,
+  "version": "0.0.0",
+  "type": "module",
+  "scripts": {
+    "dev": "vite",
+    "build": "vite build",
+    "preview": "vite preview"
+  },
+  "dependencies": {
+    "@vueuse/core": "^9.1.0",
+    "axios": "^0.27.2",
+    "dayjs": "^1.11.5",
+    "vue": "^3.2.37",
+    "vue-router": "^4.1.3"
+  },
+  "devDependencies": {
+    "@iconify/json": "^2.1.92",
+    "@vitejs/plugin-vue": "^3.0.3",
+    "sass": "^1.54.4",
+    "unplugin-auto-import": "^0.11.1",
+    "unplugin-icons": "^0.14.8",
+    "unplugin-vue-components": "^0.22.4",
+    "vite": "^3.0.7",
+    "vite-plugin-windicss": "^1.8.7",
+    "windicss": "^3.5.6"
+  }
+}

File diff suppressed because it is too large
+ 1272 - 0
pnpm-lock.yaml


+ 38 - 0
public/config.js

@@ -0,0 +1,38 @@
+// 本地开发环境
+const local = {
+  web_pc: 'https://nml.bozedu.net/',
+  web_mobile: 'https://nmlm.bozedu.net/',
+
+  api: 'https://nmlopenapi.bozedu.net/',
+  oss: 'https://nmlopenapi.bozedu.net/'
+}
+
+// 测试服环境
+const development = {
+  web_pc: 'https://nml.bozedu.net/',
+  web_mobile: 'https://nmlm.bozedu.net/',
+
+  api: 'https://nmlopenapi.bozedu.net/',
+  oss: 'https://nmlopenapi.bozedu.net/',
+}
+
+// 正式服环境
+const production = {
+  web_pc: 'https://nml.bozedu.net/',
+  web_mobile: 'https://nmlm.bozedu.net/',
+
+  api: 'https://nmlopenapi.bozedu.net/',
+  oss: 'https://nmlopenapi.bozedu.net/'
+}
+
+function isWhich() {
+  if (window.location.host.includes('nmlm.bozedu.net')) {
+    return development
+  } else if (window.location.host.includes('nmlm.bozedu.net')) {
+    return production
+  } else {
+    return local
+  }
+}
+window.GLOBAL_CONFIG = isWhich()
+

+ 10 - 0
src/App.vue

@@ -0,0 +1,10 @@
+<script setup>
+
+</script>
+
+<template>
+  <router-view></router-view>
+</template>
+
+
+

+ 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>

+ 41 - 0
src/components/FileUpload/index.vue

@@ -0,0 +1,41 @@
+<script setup>
+import { REQUEST } from '~/utils/request';
+
+const props = defineProps({
+  part: String,
+  full: String,
+})
+
+
+const fileList = $ref([])
+
+const handleAfterRead = (fileProxy) => {
+  fileProxy.status = 'uploading'
+  fileProxy.message = '上传中...'
+  const { file } = fileProxy
+  REQUEST['upload']({
+    url: 'upload/main/file',
+    data: { filedata: file }
+  }).then(res => {
+    console.log('res :>> ', res)
+    console.log('fileList :>> ', fileList);
+    if (res.code === '0') {
+      // fileList.value.push(res.data)
+      fileProxy.status = 'done'
+      fileProxy.message = ''
+    } else {
+      fileProxy.status = 'failed'
+      fileProxy.message = '上传失败'
+    }
+  }).catch((err) => {
+    console.error(err)
+  })
+}
+
+
+
+</script>
+
+<template>
+  <van-uploader :after-read="handleAfterRead" v-model="fileList"></van-uploader>
+</template>

+ 11 - 0
src/main.js

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

+ 10 - 0
src/router/index.js

@@ -0,0 +1,10 @@
+import { createRouter, createWebHashHistory } from "vue-router";
+
+export default createRouter({
+  history: createWebHashHistory(),
+  routes: [
+
+
+  ]
+})
+

+ 6 - 0
src/utils/day.js

@@ -0,0 +1,6 @@
+import * as dayjs from 'dayjs';
+
+
+export const getTimestamp = (date) => {
+  return dayjs(date).valueOf();
+}

+ 80 - 0
src/utils/request.js

@@ -0,0 +1,80 @@
+import axios from 'axios'
+const token = ''
+
+const _request = axios.create({
+  baseURL: window.GLOBAL_CONFIG.api,
+  timeout: 3 * 1000,
+  headers: {
+    'Content-Type': 'application/x-www-form-urlencoded',
+  },
+  method: 'post'
+})
+
+_request.interceptors.request.use(
+  async (config) => {
+    if (config.method?.toLocaleLowerCase() === 'get') {
+      config.params = Object.assign({ token, }, config.params)
+    } else {
+      config.data = Object.assign({ token, client: 'web', api: 'json', issubmit: '1', }, config.data)
+    }
+    return config
+  },
+  (error) => {
+    console.error('request error: ', error)
+    return Promise.reject(error)
+  }
+)
+
+// response interceptor
+_request.interceptors.response.use(
+  (response) => {
+    response.data.code = response.data?.code?.toString()
+    response.data.msg = response.data.msg.replaceAll(/<.*?>/g, ' ')
+    const { code, msg } = response.data
+    if (code !== '1') {
+      showFailToast(msg)
+    }
+    return response.data
+  },
+  (error) => {
+    console.error('response error: ' + error)
+    return Promise.reject(error)
+  }
+)
+
+export default _request
+
+const obj2form = (data) => {
+  const formData = new FormData()
+  Object.keys(data).forEach(key => formData.append(key, data[key]))
+  return formData;
+}
+
+export const REQUEST = {
+  empty: axios,
+  default: _request,
+  import: (c) => _request({
+    timeout: 10 * 60 * 1000,
+    transformRequest: [obj2form],
+    ...c
+  }),
+  upload: (c) => _request({
+    timeout: 3 * 60 * 1000,
+    transformRequest: [obj2form],
+    ...c
+  }),
+  download: (c) => _request({
+    timeout: 1 * 60 * 1000,
+    method: 'get',
+    params: { token, limit: 10000, page: 1, api: 'xls', ...c }
+  })
+}
+
+export function download(url, data) {
+  const params = Object.assign({ token, limit: 10000, page: 1, api: 'xls' }, data)
+  const paramsStr = Object.entries(params).map(([k, v]) => `${k}=${v}`).join('&')
+  const el = document.createElement('a')
+  const href = `${window.GLOBAL_CONFIG.api}${url}?${paramsStr}`
+  el.setAttribute('href', href)
+  el.click()
+}

+ 7 - 0
src/utils/string.js

@@ -0,0 +1,7 @@
+export function paddingLeft(str, length = '2', pad = '0') {
+  str = str.toString();
+  if (str.length >= length) {
+    return str;
+  }
+  return paddingLeft(pad + str, length, pad);
+}

+ 73 - 0
vite.config.js

@@ -0,0 +1,73 @@
+import { defineConfig } from 'vite'
+import vue from '@vitejs/plugin-vue'
+import path from 'path'
+import WindiCss from 'vite-plugin-windicss';
+import AutoImport from 'unplugin-auto-import/vite'
+import Components from 'unplugin-vue-components/vite'
+import Icons from 'unplugin-icons/vite'
+import IconsResolver from 'unplugin-icons/resolver'
+
+// https://vitejs.dev/config/
+export default defineConfig({
+  resolve: {
+    alias: {
+      '@': path.resolve(__dirname, 'src'),
+      '~': path.resolve(__dirname, 'src'),
+      // '~components': path.resolve(__dirname, 'src/components'),
+      // '~pages': path.resolve(__dirname, 'src/pages'),
+      // '~utils': path.resolve(__dirname, 'src/utils'),
+      // '~assets': path.resolve(__dirname, 'src/assets'),
+      // '~styles': path.resolve(__dirname, 'src/styles'),
+      // '~lib': path.resolve(__dirname, 'src/lib'),
+      // '~plugins': path.resolve(__dirname, 'src/plugins'),
+      // '~router': path.resolve(__dirname, 'src/router'),
+      // '~store': path.resolve(__dirname, 'src/store'),
+      // '~config': path.resolve(__dirname, 'src/config'),
+      // '~api': path.resolve(__dirname, 'src/api'),
+      // '~constants': path.resolve(__dirname, 'src/constants'),
+      // '~locales': path.resolve(__dirname, 'src/locales'),
+    }
+  },
+  plugins: [
+    vue({
+      reactivityTransform: true
+    }),
+    WindiCss(),
+    AutoImport({
+      dts: 'src/auto-imports.d.ts',
+      imports: ['vue', 'vue/macros', 'vue-router',],
+      dirs: [
+        'src/composables',
+        'src/store',
+        'src/utils',
+      ],
+      resolvers: [],
+      vueTemplate: true,
+    }),
+    Components({
+      dts: 'src/components.d.ts',
+      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: [IconsResolver()],
+    }),
+    Icons({
+      compiler: 'vue3',
+      autoInstall: true,
+    })
+  ],
+  server: {
+    host: true
+  },
+  build: {
+    rollupOptions: {
+      output: {
+        manualChunks: {
+          axios: ['axios'],
+        }
+      }
+    }
+  }
+})

+ 17 - 0
windi.config.ts

@@ -0,0 +1,17 @@
+import { defineConfig } from 'windicss/helpers'
+
+export default defineConfig({
+  darkMode:'class',
+  shortcuts: {
+    card: 'rounded-xl bg-light-50 p-3 relative box-border',
+    divider: 'w-full h-0 border border-solid border-gray-100 my-2',
+    divider_y: 'w-0 h-full border border-solid border-gray-100 mx-2',
+    icon: 'w-24px h-24px fill-blue-600 bg-light-100 rounded-2px cursor-pointer  mx-4px box-border',
+    icon_reserve:
+      'w-24px h-24px bg-blue-600 fill-light-100 rounded-2px cursor-pointer mx-4px p-2px box-border',
+    flex_center: 'flex justify-center items-center',
+    flex_start: 'flex justify-start items-center',
+    area:'flex bg-gray-100 text-gray-600 my-2 p-4 text-sm h-300px overflow-auto',
+    pre:'before:content-["|"] before:w-4px before:h-full before:inline-block before:text-transparent before:mr-6px before:bg-blue-400'
+  },
+})