Browse Source

Merge remote-tracking branch 'origin/master'

master
lizw-2015 6 months ago
parent
commit
b60bf3cb53
  1. 7
      src/core/manager/EnvManager.ts
  2. 12
      src/core/script/LCCScript.ts
  3. 2
      src/editor/ModelMain.vue
  4. 86
      src/editor/widgets/script/ScriptView.vue
  5. 6
      src/types/LCC.d.ts

7
src/core/manager/EnvManager.ts

@ -60,10 +60,10 @@ export default class EnvManager {
system.showLoading()
worldModel.state.runState.isLoading = true
worldModel.state.runState.currentEnv = Object.freeze(env)
worldModel.state.runState.currentEnv = env
try {
await LCC.serverStart()
await LCC.loadExecutor()
await worldModel.lccMqttManager.start(env.envConfig.frontendMqtt)
await LCC.loadInv()
this.client = mqtt.connect(env.envConfig.mqtt.websocket, {
@ -77,7 +77,8 @@ export default class EnvManager {
keepalive: 60
})
await worldModel.lccMqttManager.start(env.envConfig.frontendMqtt)
await LCC.loadExecutor()
this.client.on('connect', this.onMqttConnect)
this.client.on('message', this.onMqttMessage)
this.client.on('error', this.onMqttError)

12
src/core/script/LCCScript.ts

@ -54,6 +54,18 @@ export default class LCCScript implements LCC {
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>> {
const res = await Request.request.post('/api/workbench/LccController@loadExecutor', {

2
src/editor/ModelMain.vue

@ -23,7 +23,7 @@
</el-select>
</div>
<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-if="worldModelState.runState.isVirtual">
<el-option v-for="option in timeRateOptions"

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

@ -5,6 +5,9 @@
脚本编辑
</h3>
<el-row>
<el-button :icon="renderIcon('Sync')" link
@click="saveAndSyncScripts">保存并同步
</el-button>
<el-button :icon="renderIcon('CirclePlus')" link
@click="addScript">添加
</el-button>
@ -25,8 +28,9 @@
</el-button>
<el-divider direction="vertical" />
<el-radio-group v-model="scriptIndex" size="small">
<el-radio-button v-for="(item, index) in scriptList" :key="index"
:label="item.name" :value="index" />
<!-- vue3-menus 在这里加一个右键重命名-->
<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-row>
<span class="close" @click="closeMe">
@ -44,6 +48,7 @@ import localforage from 'localforage'
import YvSrcEditor from '@/components/YvSrcEditor.vue'
import IWidgets from '../IWidgets.js'
import CodeDropper from '@/core/manager/CodeDropper.js'
import { escByKeyboard } from '@/core/ModelUtils.js'
export default {
name: 'ScriptView',
@ -52,11 +57,59 @@ export default {
},
mixins: [IWidgets],
data() {
const me = this
return {
scriptIsRunning: false,
scriptIndex: 0,
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: {
@ -71,6 +124,33 @@ export default {
this.loadFromLocal()
},
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() {
this.scriptIsRunning = true
this.viewport.modelManager.executestring(this.currentScript)

6
src/types/LCC.d.ts

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

Loading…
Cancel
Save