Browse Source

Script 保存

master
修宁 6 months ago
parent
commit
7e5e46ec70
  1. 12
      src/core/script/LCCScript.ts
  2. 2
      src/editor/ModelMain.vue
  3. 86
      src/editor/widgets/script/ScriptView.vue
  4. 6
      src/types/LCC.d.ts

12
src/core/script/LCCScript.ts

@ -54,6 +54,18 @@ export default class LCCScript implements LCC {
return res.data return res.data
} }
saveAndSyncScripts(scriptList: { name: string; content: string }[]): Promise<ServerResponse<{ name: string; content: string }[]>> {
if (!worldModel.state.project_uuid || !worldModel.state.runState.currentEnvId) {
return Promise.reject(new Error('Project UUID or Environment ID is not set.'))
}
return Request.request.post('/api/workbench/LccController@saveAndSyncScripts', {
projectUUID: worldModel.state.project_uuid,
envId: worldModel.state.runState.currentEnvId,
scriptList: scriptList
})
}
// 从后台读取所有车 // 从后台读取所有车
async loadExecutor(): Promise<ServerResponse<ExecutorVo>> { async loadExecutor(): Promise<ServerResponse<ExecutorVo>> {
const res = await Request.request.post('/api/workbench/LccController@loadExecutor', { const res = await Request.request.post('/api/workbench/LccController@loadExecutor', {

2
src/editor/ModelMain.vue

@ -23,7 +23,7 @@
</el-select> </el-select>
</div> </div>
<div class="field-block" style="margin-right: 5px;"> <div class="field-block" style="margin-right: 5px;">
<el-select style="width:130px;" placeholder="时间速率" <el-select style="width:80px;" placeholder="时间速率"
v-model="worldModelState.runState.timeRate" v-model="worldModelState.runState.timeRate"
v-if="worldModelState.runState.isVirtual"> v-if="worldModelState.runState.isVirtual">
<el-option v-for="option in timeRateOptions" <el-option v-for="option in timeRateOptions"

86
src/editor/widgets/script/ScriptView.vue

@ -5,6 +5,9 @@
脚本编辑 脚本编辑
</h3> </h3>
<el-row> <el-row>
<el-button :icon="renderIcon('Sync')" link
@click="saveAndSyncScripts">保存并同步
</el-button>
<el-button :icon="renderIcon('CirclePlus')" link <el-button :icon="renderIcon('CirclePlus')" link
@click="addScript">添加 @click="addScript">添加
</el-button> </el-button>
@ -25,8 +28,9 @@
</el-button> </el-button>
<el-divider direction="vertical" /> <el-divider direction="vertical" />
<el-radio-group v-model="scriptIndex" size="small"> <el-radio-group v-model="scriptIndex" size="small">
<el-radio-button v-for="(item, index) in scriptList" :key="index" <!-- vue3-menus 在这里加一个右键重命名-->
:label="item.name" :value="index" /> <el-radio-button v-for="(item, index) in scriptList" :key="index" :class="'script_'+index"
:label="item.name" :value="index" v-menus="scriptMenu" />
</el-radio-group> </el-radio-group>
</el-row> </el-row>
<span class="close" @click="closeMe"> <span class="close" @click="closeMe">
@ -44,6 +48,7 @@ import localforage from 'localforage'
import YvSrcEditor from '@/components/YvSrcEditor.vue' import YvSrcEditor from '@/components/YvSrcEditor.vue'
import IWidgets from '../IWidgets.js' import IWidgets from '../IWidgets.js'
import CodeDropper from '@/core/manager/CodeDropper.js' import CodeDropper from '@/core/manager/CodeDropper.js'
import { escByKeyboard } from '@/core/ModelUtils.js'
export default { export default {
name: 'ScriptView', name: 'ScriptView',
@ -52,11 +57,59 @@ export default {
}, },
mixins: [IWidgets], mixins: [IWidgets],
data() { data() {
const me = this
return { return {
scriptIsRunning: false, scriptIsRunning: false,
scriptIndex: 0, scriptIndex: 0,
scriptList: [], scriptList: [],
searchKeyword: '' searchKeyword: '',
scriptMenu: [
{
name: 'removeScript', label: '删除',
click(menu, { class: classJoinStr }) {
// classJoinStr , scriptIndex
const index = parseInt(classJoinStr.split('_').pop())
if (isNaN(index) || index < 0 || index >= me.scriptList.length) {
system.msg('脚本索引错误', 'error')
return
}
const script = me.scriptList[index]
if (!script) {
system.msg('脚本不存在', 'error')
return
}
if (confirm(`确定要删除脚本 "${script.name}" 吗?`)) {
_.remove(me.scriptList, (item, idx) => idx === index)
if (me.scriptList.length === 0) {
me.scriptIndex = 0
} else if (me.scriptIndex >= me.scriptList.length) {
me.scriptIndex = me.scriptList.length - 1
}
}
}
},
{
name: 'rename', label: '重命名',
click(menu, { class: classJoinStr }) {
// classJoinStr , scriptIndex
const index = parseInt(classJoinStr.split('_').pop())
if (isNaN(index) || index < 0 || index >= me.scriptList.length) {
system.msg('脚本索引错误', 'error')
return
}
const script = me.scriptList[index]
if (!script) {
system.msg('脚本不存在', 'error')
return
}
const newName = prompt('请输入新的脚本名称', script.name)
if (newName && newName.trim()) {
script.name = newName.trim()
}
}
}
]
} }
}, },
watch: { watch: {
@ -71,6 +124,33 @@ export default {
this.loadFromLocal() this.loadFromLocal()
}, },
methods: { methods: {
async saveAndSyncScripts() {
//
const originName = this.scriptList[this.scriptIndex]?.name
system.showLoading()
try {
const serverResponse = await LCC.saveAndSyncScripts(this.scriptList)
if (serverResponse.success) {
this.scriptList = serverResponse.data || []
// originName
if (originName) {
const index = this.scriptList.findIndex(item => item.name === originName)
if (index >= 0) {
this.scriptIndex = index
return
}
}
this.scriptIndex = 0
}
system.msg('脚本已保存并同步到服务器')
} finally {
system.clearLoading()
}
},
runScript() { runScript() {
this.scriptIsRunning = true this.scriptIsRunning = true
this.viewport.modelManager.executestring(this.currentScript) this.viewport.modelManager.executestring(this.currentScript)

6
src/types/LCC.d.ts

@ -26,6 +26,12 @@ declare interface LCC {
* Model * Model
*/ */
loadExecutor(): Promise<ServerResponse<ExecutorVo>> loadExecutor(): Promise<ServerResponse<ExecutorVo>>
/**
*
* @param scriptList
*/
saveAndSyncScripts(scriptList: { name: string, content: string }[]): Promise<ServerResponse<{ name: string, content: string }[]>>
} }
type ContainerT = 'pallet' | 'tote' | 'carton' | 'box' type ContainerT = 'pallet' | 'tote' | 'carton' | 'box'

Loading…
Cancel
Save