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