ASW-1 feat: ASW gui 项目初始化

This commit is contained in:
zyh
2024-06-27 17:12:25 +08:00
parent 9d88f421cd
commit 28b7256483
33 changed files with 4389 additions and 83 deletions

24
.gitignore vendored Normal file
View File

@@ -0,0 +1,24 @@
# 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?

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

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

104
README.md
View File

@@ -2,92 +2,30 @@
## Getting started
> A Vue3.js project + vite
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
## Build Setup
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
``` bash
# install dependencies
npm install
## Add your files
# serve with hot reload at localhost:8080
npm run dev
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
# build for production with minification
npm run build
```
## 参考
``` bash
vue3 https://cn.vuejs.org/guide/introduction.html
vite https://cn.vitejs.dev/guide/
ui https://element-plus.org/zh-CN/#/zh-CN
pinia 状态管理库 https://pinia.vuejs.org/zh/
```
cd existing_repo
git remote add origin https://git.mesalab.cn/appsketch-works/asw-gui.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://git.mesalab.cn/appsketch-works/asw-gui/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
# 启动
npm run dev

10
index.css Normal file
View File

@@ -0,0 +1,10 @@
* {
margin: 0;
padding: 0;
list-style: none;
}
#app{
width: 100vw;
height: 100vh;
}

14
index.html Normal file
View File

@@ -0,0 +1,14 @@
<!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>AppSketch</title>
<link rel="stylesheet" href="./index.css"/>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>

3748
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

30
package.json Normal file
View File

@@ -0,0 +1,30 @@
{
"name": "app-sketch",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@vueuse/core": "^10.11.0",
"axios": "^1.7.2",
"codemirror": "^5.65.16",
"codemirror-editor-vue3": "^2.7.0",
"element-plus": "^2.7.6",
"lodash": "^4.17.21",
"pinia": "^2.1.7",
"v-code-diff": "^1.12.0",
"vue": "^3.4.21",
"vue-router": "^4.3.3"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.0.4",
"sass": "^1.77.6",
"sass-loader": "^14.2.1",
"vite": "^5.2.0",
"vue-i18n": "^9.13.1"
}
}

1
public/vite.svg Normal file
View File

@@ -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="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

25
src/App.vue Normal file
View File

@@ -0,0 +1,25 @@
<template>
<el-config-provider :locale="locale">
<router-view />
</el-config-provider>
</template>
<script setup>
import { ref, computed } from 'vue'
import { ElConfigProvider } from 'element-plus'
import { useI18n } from "vue-i18n"
import { useMainStore } from '@/store/index'
import { useTheme } from '@/hooks/useTheme'
const { messages } = useI18n()
// elmentui组件国际化
const mainStore = useMainStore()
const locale = computed(() => {
return mainStore.language === 'zh' ? messages.value['zh'] : messages.value['en']
})
// 初始化主题
const { themeSet } = useTheme()
themeSet(mainStore.theme)
</script>

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

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

After

Width:  |  Height:  |  Size: 496 B

8
src/axios/index.js Normal file
View File

@@ -0,0 +1,8 @@
import axios from 'axios'
const axiosInstance = axios.create({
baseURL: '',
timeout: undefined,
})
export default axiosInstance

View File

@@ -0,0 +1,42 @@
<template>
<div>
<CodeDiff
:hideHeader="false"
language="json"
:old-string="oldJson"
new-string="{}"
output-format="line-by-line"
:theme="theme"
/>
</div>
</template>
<script setup>
import { ref, watch } from 'vue';
import { CodeDiff } from 'v-code-diff';
import { useMainStore } from '@/store/index';
const mainStore = useMainStore();
let oldJson = {
a: {
b: {
c: "66666666666666666666666666666666666666666666666",
},
},
};
oldJson = ref(JSON.stringify(oldJson, null, 2));
let theme = ref(mainStore.theme);
watch(
() => mainStore.theme,
(value) => {
theme.value = value
}
);
</script>
<style lang="scss" scoped></style>

View File

@@ -0,0 +1,156 @@
<template>
<div class="box" style="width: 100%">
<codemirror
ref="editor"
v-model:value="value"
:options="cmOptions"
@change="change"
/>
</div>
</template>
<script setup>
import { ref, onMounted, watch, onUnmounted } from 'vue';
import { useMainStore } from '@/store/index';
const mainStore = useMainStore();
import Codemirror from 'codemirror-editor-vue3';
// language
import 'codemirror/mode/javascript/javascript.js';
// theme 主题
import 'codemirror/theme/ttcn.css';
import 'codemirror/theme/monokai.css';
// 折叠功能
import 'codemirror/addon/fold/foldcode.js';
import 'codemirror/addon/fold/foldgutter.js';
import 'codemirror/addon/fold/foldgutter.css';
import 'codemirror/addon/fold/brace-fold.js';
// 自动提示
import 'codemirror/addon/hint/show-hint.js';
import 'codemirror/addon/hint/show-hint.css';
import 'codemirror/addon/hint/javascript-hint.js';
// 代码校验 lint
import 'codemirror/addon/lint/lint.js';
import 'codemirror/addon/lint/lint.css';
import 'codemirror/addon/lint/json-lint.js';
import jsonlint from 'jsonlint-mod';
// 其他
import 'codemirror/addon/edit/matchbrackets.js';
import 'codemirror/addon/edit/closebrackets.js';
window.jsonlint = jsonlint;
let value = {
a: {
b: {
c: 666,
},
},
text: {
demo: 999,
},
};
value = JSON.stringify(value, null, 2); // 数组对象格式化的逻辑
const hint = (cm, options) => {
//获取CodeMirror上面的一个方法
const Pos = CodeMirror.Pos;
// 获取光标位置
const cursor = cm.getCursor();
// 获取当前行的内容
const cursorLine = cm.getLine(cursor.line)
// 获取当前单词的信息
const token = cm.getTokenAt(cursor);
// 当前正在输入的单词
const currentStr = token.string;
const keyword = [
'name', 'nameaaa', 'namebbb', 'text', 'aaa',
]
const replaceStr = currentStr.replace(/"/g, '')
// 用来放提示的单词
const found = [];
keyword.forEach(item=>{
if(item.includes(replaceStr)){
found.push(`"${item}"`)
}
})
const result = {
list: found,
from: Pos(cursor.line, token.start),
to: Pos(cursor.line, token.end),
};
return result;
};
const showHint = (cm, e)=>{
const arr = [13,38,40] // 回车 上下箭头不触发提示 防止选择时冲突
if(arr.find((item)=>item == e.keyCode)){
return
}
editor.value?.cminstance?.showHint()
}
onMounted (()=>{
editor.value?.cminstance?.on('keyup', showHint)
})
onUnmounted(()=>{
editor.value?.cminstance?.off('keyup', showHint)
})
// json的配置
let cmOptions = {
mode: 'application/json', //编辑器的编程语言
theme: mainStore.theme === 'dark' ? 'monokai' : 'ttcn',
readOnly: false, // 只读
tabSize: 4, // 缩进单元格为 4 个空格
indentUnit: 2,
viewportMargin: Infinity, // 指定当前滚动到视图中内容上⽅和下⽅要渲染的⾏数
autofocus: false, // 自动聚焦
firstLineNumber: 1, // 从哪个数字开始计算行数
lineNumbers: true, // 是否显示左边换行数字
lineWrapping: true, // 是否应对长行进行滚动或换行
lint: true, // 打开json校验
matchBrackets: true, // 在光标点击紧挨{、]括号左、右侧时,自动突出显示匹配的括号 }
autoCloseBrackets: true, // 自动关闭括号
gutters: [
'CodeMirror-linenumbers',
'CodeMirror-foldgutter',
'CodeMirror-lint-markers',
],
extraKeys: {
// 触发提示按键
Ctrl: 'autocomplete',
},
hintOptions: {
// 自定义提示选项
completeSingle: false, // 当匹配只有一项的时候是否自动补全
hint: hint,
},
};
const editor = ref(null);
watch(
() => mainStore.theme,
(value) => {
let theme = value === 'dark' ? 'monokai' : 'ttcn';
editor.value?.cminstance?.setOption('theme', theme);
}
);
const change = (val, cm) => {
try {
// console.log(jsonlint.parse(val));
} catch (error) {
console.log(error.message);
}
};
</script>
<style lang="scss" scoped>
</style>

16
src/hooks/useTheme.js Normal file
View File

@@ -0,0 +1,16 @@
import { useMainStore } from '@/store/index'
export const useTheme = () => {
const mainStore = useMainStore();
const themeSet = (value) => {
document.documentElement.classList.remove('light', 'dark');
document.documentElement.classList.add(value);
mainStore.theme = value
localStorage.setItem('asg-theme', value)
};
return {
themeSet,
};
};

10
src/i18n/en.js Normal file
View File

@@ -0,0 +1,10 @@
// en.js
export default {
overall: {
add: 'Add',
edit: 'Edit',
save: 'Save',
cancel: 'Cancel',
}
}

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

@@ -0,0 +1,25 @@
import { createI18n } from 'vue-i18n'
import elEn from 'element-plus/es/locale/lang/en'
import elZh from 'element-plus/es/locale/lang/zh-cn'
import en from './en'
import zh from './zh'
const messages = {
en: {
...elEn,
...en
},
zh: {
...elZh,
...zh
}
}
const i18n= createI18n({
legacy: false,
globalInjection:true,
locale: localStorage.getItem('asg-language') || 'en',
messages,
})
export default i18n

10
src/i18n/zh.js Normal file
View File

@@ -0,0 +1,10 @@
// zh.js
export default {
overall: {
add: '新增',
edit: '编辑',
save: '保存',
cancel: '取消',
}
}

17
src/main.js Normal file
View File

@@ -0,0 +1,17 @@
import { createApp } from 'vue'
import App from './App.vue'
import './styles/index.scss'
import './styles/element/index.scss'
import router from "./router"
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import i18n from '@/i18n/index'
const app = createApp(App)
app.use(router)
app.use(createPinia())
app.use(ElementPlus)
app.use(i18n)
app.mount('#app')

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

@@ -0,0 +1,19 @@
import { createRouter, createWebHashHistory } from 'vue-router';
const routerHistory = createWebHashHistory();
const router = createRouter({
history: routerHistory,
routes: [
{
path: '/',
redirect: '/home',
},
{
path: '/home',
component: () => import('../views/home.vue'),
},
],
});
export default router;

13
src/store/index.js Normal file
View File

@@ -0,0 +1,13 @@
import { defineStore } from 'pinia';
export const useMainStore = defineStore({
id:'mainStore',
state: () => {
return {
language: localStorage.getItem('asg-language') || 'en',
theme: localStorage.getItem('asg-theme') || 'light',
}
},
getters: {
},
})

View File

@@ -0,0 +1,6 @@
.codemirror-container{
display: block !important;
.CodeMirror.CodeMirror-wrap{
line-height: inherit !important;
}
}

View File

@@ -0,0 +1,2 @@
@import './codemirror.scss';
@import './jsonDiff.scss';

View File

@@ -0,0 +1,8 @@
.code-diff-view {
.diff-table {
.blob-code{
padding-top: 1px;
padding-bottom: 1px;
}
}
}

View File

@@ -0,0 +1,9 @@
@forward 'element-plus/theme-chalk/src/dark/var.scss' with (
$colors: (
'primary': (
'base': #00ccff,
),
),
);
@use "element-plus/theme-chalk/src/dark/css-vars.scss" as *;

View File

@@ -0,0 +1,2 @@
@import "./light.scss";
@import "./dark.scss";

View File

@@ -0,0 +1,9 @@
@forward 'element-plus/theme-chalk/src/common/var.scss' with (
$colors: (
'primary': (
'base': pink,
),
),
);
@use "element-plus/theme-chalk/src/index.scss" as *;

3
src/styles/index.scss Normal file
View File

@@ -0,0 +1,3 @@
/* 加载主题变量 */
@import './theme/index.scss';
@import './components/index.scss';

View File

@@ -0,0 +1,9 @@
html.dark{
/* 1.字色 */
// 标题字色
--color-text-primary: #D8D8D8;
// 普通字色
--color-text-regular: #BEBEBE;
// 次要字色
--color-text-secondary: #999999;
}

View File

@@ -0,0 +1,2 @@
@import './light.scss';
@import './dark.scss';

View File

@@ -0,0 +1,9 @@
:root{
/* 1.字色 */
// 标题字色
--color-text-primary: #333333;
// 普通字色
--color-text-regular: #666666;
// 标题字色
--color-text-secondary: #999999;
}

View File

@@ -0,0 +1 @@
$aaa:green

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

@@ -0,0 +1,104 @@
<template>
<el-switch v-model="isDark" @change="themeChange"/>
<el-button type="primary">{{ isDark ? 'Dark' : 'Light' }}</el-button>
<p>自定义字体主题</p>
<el-table :data="tableData" style="width: 100%">
<el-table-column prop="date" label="Date" />
<el-table-column prop="name" label="Name" />
<el-table-column prop="address" label="Address" />
</el-table>
<el-date-picker
v-model="date"
type="datetime"
/>
<el-select
v-model="value"
placeholder="Select"
size="large"
style="width: 240px"
@change="language"
>
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
<p>{{$t('overall.add') }}</p>
<p>{{$t('overall.edit') }}</p>
<p>{{$t('overall.save') }}</p>
<jsonEditor></jsonEditor>
<jsonDiff></jsonDiff>
</template>
<script setup>
import jsonEditor from '@/components/jsonEditor.vue'
import jsonDiff from '@/components/jsonDiff.vue'
import { ref, } from 'vue'
import { useI18n } from "vue-i18n"
import { useMainStore } from '@/store/index'
import { useTheme } from '@/hooks/useTheme'
const { t, locale } = useI18n()
const value = ref(locale.value)
const options = [
{
value: 'en',
label: 'English',
},
{
value: 'zh',
label: '中文',
},
]
const mainStore = useMainStore()
const language = (val)=>{
locale.value = val
mainStore.language = val
localStorage.setItem('asg-language', val)
}
const { themeSet } = useTheme()
const isDark = ref(mainStore.theme === 'dark' )
const themeChange = (val)=>{
themeSet(val? 'dark' : 'light')
}
const date = ref('')
const tableData = [
{
date: '2016-05-03',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles',
},
{
date: '2016-05-02',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles',
},
{
date: '2016-05-04',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles',
},
{
date: '2016-05-01',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles',
},
]
</script>
<style lang="scss" scoped>
p {
color: var(--color-text-primary);
}
</style>

32
vite.config.js Normal file
View File

@@ -0,0 +1,32 @@
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.resolve(__dirname, "./src"),
},
},
//本地运行配置,以及反向代理配置
server: {
host: true,
port: "8080", //端口
open: true,//服务启动时自动在浏览器中打开应用
},
css: {
// css预处理器
preprocessorOptions: {
scss: {
// 引入 variables.scss 这样就可以在全局中使用 variables.scss中预定义的变量了
// 给导入的路径最后加上 ;
additionalData: `@use "@/styles/variables.scss" as *; `,
}
}
},
})