Connect front web app to workbench APIs
This commit is contained in:
3
RuoYi-Vue/easycode-web/package-lock.json
generated
3
RuoYi-Vue/easycode-web/package-lock.json
generated
@@ -18,6 +18,9 @@
|
|||||||
"@vitejs/plugin-vue": "^5.2.1",
|
"@vitejs/plugin-vue": "^5.2.1",
|
||||||
"sass": "^1.83.0",
|
"sass": "^1.83.0",
|
||||||
"vite": "^6.0.7"
|
"vite": "^6.0.7"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/helper-string-parser": {
|
"node_modules/@babel/helper-string-parser": {
|
||||||
|
|||||||
@@ -8,6 +8,9 @@
|
|||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview --host 0.0.0.0"
|
"preview": "vite preview --host 0.0.0.0"
|
||||||
},
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@element-plus/icons-vue": "^2.3.1",
|
"@element-plus/icons-vue": "^2.3.1",
|
||||||
"axios": "^1.7.9",
|
"axios": "^1.7.9",
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import { SwitchButton } from '@element-plus/icons-vue'
|
import { SwitchButton } from '@element-plus/icons-vue'
|
||||||
|
import { logout } from '@/api/auth'
|
||||||
import { getToken, getUser, removeToken } from '@/utils/auth'
|
import { getToken, getUser, removeToken } from '@/utils/auth'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -41,9 +42,13 @@ const user = computed(() => {
|
|||||||
})
|
})
|
||||||
const displayName = computed(() => user.value?.nickName || user.value?.userName || '已登录')
|
const displayName = computed(() => user.value?.nickName || user.value?.userName || '已登录')
|
||||||
|
|
||||||
function handleLogout() {
|
async function handleLogout() {
|
||||||
|
try {
|
||||||
|
await logout()
|
||||||
|
} finally {
|
||||||
removeToken()
|
removeToken()
|
||||||
router.push('/')
|
router.push('/')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -132,6 +132,64 @@ watch(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
tables,
|
||||||
|
(nextTables) => {
|
||||||
|
nextTables.forEach(normalizeTable)
|
||||||
|
},
|
||||||
|
{ deep: true, immediate: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
function toPascalCase(value) {
|
||||||
|
return String(value || '')
|
||||||
|
.split(/[^A-Za-z0-9]+|_/)
|
||||||
|
.filter(Boolean)
|
||||||
|
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
||||||
|
.join('')
|
||||||
|
}
|
||||||
|
|
||||||
|
function toCamelCase(value) {
|
||||||
|
const pascal = toPascalCase(value)
|
||||||
|
return pascal ? pascal.charAt(0).toLowerCase() + pascal.slice(1) : ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function javaTypeOf(columnType) {
|
||||||
|
const normalized = String(columnType || '').toLowerCase()
|
||||||
|
if (normalized.startsWith('bigint')) return 'Long'
|
||||||
|
if (normalized.startsWith('int')) return 'Integer'
|
||||||
|
if (normalized.startsWith('decimal')) return 'BigDecimal'
|
||||||
|
if (normalized === 'datetime' || normalized === 'date') return 'Date'
|
||||||
|
return 'String'
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeTable(table) {
|
||||||
|
if (!table) return
|
||||||
|
table.className = toPascalCase(table.tableName)
|
||||||
|
table.moduleName = table.moduleName || 'system'
|
||||||
|
table.businessName = toCamelCase(table.tableName)
|
||||||
|
table.functionName = table.tableComment || table.tableName
|
||||||
|
table.tplCategory = table.tplCategory || 'crud'
|
||||||
|
table.tplWebType = table.tplWebType || 'element-plus'
|
||||||
|
|
||||||
|
const columns = Array.isArray(table.columns) ? table.columns : []
|
||||||
|
columns.forEach((column) => normalizeColumn(column))
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeColumn(column) {
|
||||||
|
if (!column) return
|
||||||
|
column.javaField = toCamelCase(column.columnName)
|
||||||
|
column.javaType = javaTypeOf(column.columnType)
|
||||||
|
column.isPk = column.isPk === '1' ? '1' : '0'
|
||||||
|
column.isIncrement = column.isIncrement === '1' ? '1' : '0'
|
||||||
|
column.isRequired = column.isRequired === '1' ? '1' : '0'
|
||||||
|
column.isInsert = column.isInsert || '1'
|
||||||
|
column.isEdit = column.isEdit || '1'
|
||||||
|
column.isList = column.isList || '1'
|
||||||
|
column.isQuery = column.isQuery || '0'
|
||||||
|
column.queryType = column.queryType || 'EQ'
|
||||||
|
column.htmlType = column.htmlType || 'input'
|
||||||
|
}
|
||||||
|
|
||||||
function uid(prefix) {
|
function uid(prefix) {
|
||||||
return `${prefix}_${Date.now()}_${Math.random().toString(16).slice(2)}`
|
return `${prefix}_${Date.now()}_${Math.random().toString(16).slice(2)}`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,14 @@ function normalizeNodes(nodes, prefix = '') {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pickCodeContent(data) {
|
||||||
|
if (typeof data === 'string') return data
|
||||||
|
if (!data || typeof data !== 'object') return ''
|
||||||
|
if (typeof data.content === 'string') return data.content
|
||||||
|
const firstValue = Object.values(data).find((value) => typeof value === 'string')
|
||||||
|
return firstValue || ''
|
||||||
|
}
|
||||||
|
|
||||||
async function loadType(type) {
|
async function loadType(type) {
|
||||||
const result = await getProjectStructure(projectId.value, type)
|
const result = await getProjectStructure(projectId.value, type)
|
||||||
const data = unwrap(result)
|
const data = unwrap(result)
|
||||||
@@ -96,7 +104,7 @@ async function handleFileSelect(file) {
|
|||||||
category: file.category || file.path || file.label
|
category: file.category || file.path || file.label
|
||||||
})
|
})
|
||||||
const data = unwrap(result)
|
const data = unwrap(result)
|
||||||
code.value = typeof data === 'string' ? data : data.content || ''
|
code.value = pickCodeContent(data)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
ElMessage.error(error.message || '加载文件内容失败')
|
ElMessage.error(error.message || '加载文件内容失败')
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user