一企一码

This commit is contained in:
xiaozhang 2024-02-19 16:46:15 +08:00
commit 02ae71d10b
18 changed files with 2016 additions and 0 deletions

30
.gitignore vendored Normal file
View File

@ -0,0 +1,30 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
.DS_Store
dist
dist-ssr
coverage
*.local
/cypress/videos/
/cypress/screenshots/
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
*.tsbuildinfo

3
.vscode/extensions.json vendored Normal file
View File

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

29
README.md Normal file
View File

@ -0,0 +1,29 @@
# SoloQRCode
This template should help get you started developing with Vue 3 in Vite.
## Recommended IDE Setup
[VSCode](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).
## Customize configuration
See [Vite Configuration Reference](https://vitejs.dev/config/).
## Project Setup
```sh
npm install
```
### Compile and Hot-Reload for Development
```sh
npm run dev
```
### Compile and Minify for Production
```sh
npm run build
```

13
index.html Normal file
View File

@ -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>一企一码</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>

8
jsconfig.json Normal file
View File

@ -0,0 +1,8 @@
{
"compilerOptions": {
"paths": {
"@/*": ["./src/*"]
}
},
"exclude": ["node_modules", "dist"]
}

1664
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

22
package.json Normal file
View File

@ -0,0 +1,22 @@
{
"name": "soloqrcode",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@types/xml2js": "^0.4.14",
"axios": "^1.6.7",
"vue": "^3.4.15",
"vue-router": "^4.2.5",
"xml2js": "^0.6.2"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.0.3",
"vite": "^5.0.11"
}
}

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

15
src/App.vue Normal file
View File

@ -0,0 +1,15 @@
<template>
<div>
<RouterView />
</div>
</template>
<script setup>
</script>
<style scoped>
</style>

1
src/assets/logo.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 261.76 226.69"><path d="M161.096.001l-30.225 52.351L100.647.001H-.005l130.877 226.688L261.749.001z" fill="#41b883"/><path d="M161.096.001l-30.225 52.351L100.647.001H52.346l78.526 136.01L209.398.001z" fill="#34495e"/></svg>

After

Width:  |  Height:  |  Size: 276 B

5
src/assets/main.css Normal file
View File

@ -0,0 +1,5 @@
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}

13
src/main.js Normal file
View File

@ -0,0 +1,13 @@
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
const app = createApp(App)
app.use(router)
app.mount('#app')

25
src/router/index.js Normal file
View File

@ -0,0 +1,25 @@
import { createRouter, createWebHistory } from 'vue-router'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
name: 'home',
component: () => import('../views/home.vue')
},
{
path: '/index',
name: 'index',
component: () => import('../views/index.vue')
},
{
path: '/test',
name: 'test',
component: () => import('../views/test.vue')
}
]
})
export default router

13
src/utils/getToken.js Normal file
View File

@ -0,0 +1,13 @@
// 获取token的方法
import axios from 'axios';
export async function fetchToken() {
try {
const response = await axios.get('api/seeyon/rest/token/test/6fc1c885-3aac-4489-95f0-7b6923622743');
return response.data;
} catch (error) {
console.error('Error fetching token:', error);
return null;
}
}

77
src/views/home.vue Normal file
View File

@ -0,0 +1,77 @@
<template>
<div>
<div v-if="jsonData">
<pre>{{ jsonData }}</pre>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue';
import axios from 'axios';
import { fetchToken } from '../utils/getToken'; // fetchToken
const token = ref('');
const data = ref('')
const jsonData = ref(null);
// fetchToken
fetchToken().then((response) => {
if (response) {
token.value = response;
fetchData(response); // token fetchData
}
});
// token
const fetchData = async (token) => {
try {
const response = await axios.get(`api/seeyon/rest/dee/task/getMineral?token=${token.id}`);
data.value = response.data;
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(response.data, 'text/xml');
const json = xmlToJson(xmlDoc);
jsonData.value = JSON.stringify(json, null, 2);
} catch (error) {
console.error(error);
}
};
// XML JSON
function xmlToJson(xml) {
let obj = {};
if (xml.nodeType === 1) { // element
// do attributes
if (xml.attributes.length > 0) {
obj['@attributes'] = {};
for (let j = 0; j < xml.attributes.length; j++) {
const attribute = xml.attributes.item(j);
obj['@attributes'][attribute.nodeName] = attribute.nodeValue;
}
}
} else if (xml.nodeType === 3) { // text
obj = xml.nodeValue;
}
// do children
if (xml.hasChildNodes()) {
for (let i = 0; i < xml.childNodes.length; i++) {
const item = xml.childNodes.item(i);
const nodeName = item.nodeName;
if (typeof obj[nodeName] === 'undefined') {
obj[nodeName] = xmlToJson(item);
} else {
if (typeof obj[nodeName].push === 'undefined') {
const old = obj[nodeName];
obj[nodeName] = [];
obj[nodeName].push(old);
}
obj[nodeName].push(xmlToJson(item));
}
}
}
return obj;
}
</script>

31
src/views/index.vue Normal file
View File

@ -0,0 +1,31 @@
<template>
<div>
<div v-if="data">{{ data }}</div>
</div>
</template>
<script setup>
import { ref } from 'vue';
import axios from 'axios';
import { fetchToken } from '../utils/getToken'; // fetchToken
const token = ref('');
const data = ref('');
// fetchToken
fetchToken().then((response) => {
if (response) {
token.value = response;
fetchData(response); // token fetchData
}
});
//token
const fetchData = async (token) => {
try {
const response = await axios.get(`api/seeyon/rest/dee/task/getMineral?token=${token.id}`);
data.value = response.data;
} catch (error) {
console.error(error);
}
};
</script>

42
src/views/test.vue Normal file
View File

@ -0,0 +1,42 @@
<template>
<div>
<div v-if="jsonData">{{ jsonData }}</div>
</div>
</template>
<script setup>
import { ref } from 'vue';
import axios from 'axios';
import xml2js from 'xml2js';
import { fetchToken } from '../utils/getToken'; // fetchToken
const token = ref('');
const jsonData = ref('');
// fetchToken
fetchToken().then((response) => {
if (response) {
token.value = response;
fetchData(response); // token fetchData
}
});
// token
const fetchData = async (token) => {
try {
const response = await axios.get(`api/seeyon/rest/dee/task/getMineral?token=${token.id}`);
const xmlData = response.data;
xml2js.parseString(xmlData, (err, result) => {
if (err) {
console.error(err);
return;
} else {
jsonData.value = JSON.stringify(result);
}
});
} catch (error) {
console.error(error);
}
};
</script>

25
vite.config.js Normal file
View File

@ -0,0 +1,25 @@
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
server: {
proxy: {
'/api': {
target:'https://qdngz.guizhoujc.com',
changeOrigin: true,
rewrite: (p) => p.replace(/^\/api/, '')
}
}
}
})