增加shift+鼠标左键定位代码功能,增加自动创建资源权限标识功能,细节调优。 (#1225)

* fix: 增加索引解决登录太慢的问题

* 增加shift+鼠标左键自动定位到编辑工具代码行的功能

* 过滤功能性标签 防止意外错误

* [utils\validator.go]:修复了当判断字符长度时,当字符串长度为中文,会判断错误。

* 增加资源标识

Co-authored-by: hexiang3000 <91460121+hexiang3000@users.noreply.github.com>
Co-authored-by: fanyibo <29974992@qq.com>
This commit is contained in:
奇淼(piexlmax
2022-09-21 21:42:10 +08:00
committed by GitHub
co-authored by hexiang3000 fanyibo
parent b5c79be625
commit ef35c53712
15 changed files with 228 additions and 13 deletions
+3
View File
@@ -3,5 +3,8 @@ VITE_CLI_PORT = 8080
VITE_SERVER_PORT = 8888
VITE_BASE_API = /api
VITE_BASE_PATH = http://127.0.0.1
VITE_EDITOR = vscode
// VITE_EDITOR = webstorm 如果使用webstorm开发且要使用dom定位到代码行功能 请先自定添加 webstorm到环境变量 再将VITE_EDITOR值修改为webstorm
// 如果使用docker-compose开发模式,设置为下面的地址或本机主机IP
//VITE_BASE_PATH = http://177.7.0.12
+2
View File
@@ -12,6 +12,8 @@ import run from '@/core/gin-vue-admin.js'
import auth from '@/directive/auth'
import { store } from '@/pinia'
import App from './App.vue'
import { initDom } from './utils/positionToCode'
initDom()
/**
* @description 导入加载进度条,防止首屏加载时间过长,用户等待
*
+36
View File
@@ -0,0 +1,36 @@
export const initDom = () => {
if (import.meta.env.MODE === 'development') {
document.onmousedown = function(e) {
if (e.shiftKey && e.button === 0) {
e.preventDefault()
sendRequestToOpenFileInEditor(getFilePath(e))
}
}
}
}
const getFilePath = (e) => {
let element = e
if (e.target) {
element = e.target
}
if (!element || !element.getAttribute) return null
if (element.getAttribute('code-location')) {
return element.getAttribute('code-location')
}
return getFilePath(element.parentNode)
}
const sendRequestToOpenFileInEditor = (filePath) => {
const protocol = window.location.protocol
? window.location.protocol
: 'http:'
const hostname = window.location.hostname
? window.location.hostname
: 'localhost'
const port = window.location.port ? window.location.port : '80'
fetch(`${protocol}//${hostname}:${port}/gvaPositionCode?filePath=${filePath}`)
.catch((error) => {
console.log(error)
})
}
@@ -5,7 +5,9 @@
</div>
<div class="log">
<div v-for="(item,key) in dataTimeline" :key="key" class="log-item">
<div class="flex-1 flex key-box"><span class="key" :class="key<3&&'top'">{{ key+1 }}</span></div>
<div class="flex-1 flex key-box">
<span class="key" :class="key<3&&'top'">{{ key+1 }}</span>
</div>
<div class="flex-5 flex message">{{ item.message }}</div>
<div class="flex-3 flex form">{{ item.from }}</div>
</div>
@@ -71,6 +71,14 @@
<el-icon class="auto-icon" @click="getPkgs"><refresh /></el-icon>
<el-icon class="auto-icon" @click="goPkgs"><document-add /></el-icon>
</el-form-item>
<el-form-item>
<template #label>
<el-tooltip content="注:会自动在结构体添加 created_by updated_by deleted_by,方便用户进行资源权限控制" placement="bottom" effect="light">
<div> 创建资源标识 <el-icon><QuestionFilled /></el-icon> </div>
</el-tooltip>
</template>
<el-checkbox v-model="form.autoCreateResource" />
</el-form-item>
<el-form-item>
<template #label>
<el-tooltip content="注:把自动生成的API注册进数据库" placement="bottom" effect="light">
@@ -228,6 +236,7 @@ const form = ref({
description: '',
autoCreateApiToSql: true,
autoMoveFile: true,
autoCreateResource: false,
fields: []
})
const rules = ref({
+4
View File
@@ -6,6 +6,8 @@ import * as path from 'path'
import * as dotenv from 'dotenv'
import * as fs from 'fs'
import vuePlugin from '@vitejs/plugin-vue'
import GvaPosition from './vite_plugin/gva-position'
import GvaPositionServer from './vite_plugin/code-server'
// @see https://cn.vitejs.dev/config/
export default ({
command,
@@ -77,6 +79,8 @@ export default ({
esbuild,
optimizeDeps,
plugins: [
GvaPositionServer(),
GvaPosition(),
legacyPlugin({
targets: ['Android > 39', 'Chrome >= 60', 'Safari >= 10.1', 'iOS >= 10.3', 'Firefox >= 54', 'Edge >= 15'],
}), vuePlugin(), [Banner(`\n Build based on gin-vue-admin \n Time : ${timestamp}`)]
+59
View File
@@ -0,0 +1,59 @@
const child_process = require('child_process')
import * as dotenv from 'dotenv'
import * as fs from 'fs'
const NODE_ENV = process.env.NODE_ENV || 'development'
const envFiles = [
`.env.${NODE_ENV}`
]
for (const file of envFiles) {
const envConfig = dotenv.parse(fs.readFileSync(file))
for (const k in envConfig) {
process.env[k] = envConfig[k]
}
}
export default function GvaPositionServer() {
return {
name: 'gva-position-server',
apply: 'serve',
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (req._parsedUrl.pathname === '/gvaPositionCode') {
const path = req._parsedUrl.query && req._parsedUrl.query.split('=')[1]
if (path) {
if (process.env.VITE_EDITOR === 'webstorm') {
const linePath = path.split(':')[1]
const filePath = path.split(':')[0]
const platform = os()
if (platform === 'win32') {
child_process.exec(`webstorm64.exe --line ${linePath} ${filePath}`)
} else {
child_process.exec(`webstorm64 --line ${linePath} ${filePath}`)
}
} else {
child_process.exec('code -r -g ' + path)
}
}
}
next()
})
}
}
}
function os() {
'use strict'
const os = require('os')
const platform = os.platform()
switch (platform) {
case 'darwin':
return 'MacOSX'
case 'linux':
return 'Linux'
case 'win32':
return 'Windows'
default:
return '无法确定操作系统!'
}
}
+51
View File
@@ -0,0 +1,51 @@
export default function GvaPosition() {
return {
name: 'gva-position',
apply: 'serve',
transform(code, id) {
const index = id.lastIndexOf('.')
const ext = id.substr(index + 1)
if (ext.toLowerCase() === 'vue') {
return codeLineTrack(code, id)
}
},
}
}
const codeLineTrack = (code, id) => {
const lineList = code.split('\n')
const newList = []
lineList.forEach((item, index) => {
newList.push(addLineAttr(item, index + 1, id)) // 添加位置属性,index+1为具体的代码行号
})
return newList.join('\n')
}
const addLineAttr = (lineStr, line, id) => {
if (!/^\s+</.test(lineStr)) {
return lineStr
}
const reg = /((((^(\s)+\<))|(^\<))[\w-]+)|(<\/template)/g
let leftTagList = lineStr.match(reg)
if (leftTagList) {
leftTagList = Array.from(new Set(leftTagList))
leftTagList.forEach((item) => {
const skip = [
'KeepAlive',
'template',
'keep-alive',
'transition',
'el-',
'El',
'router-view',
]
if (item && !skip.some((i) => item.indexOf(i) > -1)) {
const reg = new RegExp(`${item}`)
const location = `${item} code-location="${id}:${line}"`
lineStr = lineStr.replace(reg, location)
}
})
}
return lineStr
}