scriptManage.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. <template>
  2. <div class="app-container">
  3. <el-form
  4. :model="queryParams"
  5. ref="queryForm"
  6. size="small"
  7. :inline="true"
  8. v-show="showSearch"
  9. label-width="68px"
  10. >
  11. <!-- <el-form-item label="脚本编码" prop="scriptKey">
  12. <el-input
  13. v-model="queryParams.scriptKey"
  14. placeholder="请输入脚本编码"
  15. clearable
  16. @keyup.enter.native="handleQuery"
  17. />
  18. </el-form-item> -->
  19. <el-form-item label="脚本方法名称" prop="scriptFunctionName">
  20. <el-input
  21. v-model="queryParams.scriptFunctionName"
  22. placeholder="请输入脚本方法名称"
  23. clearable
  24. @keyup.enter.native="handleQuery"
  25. />
  26. </el-form-item>
  27. <el-form-item label="脚本名称" prop="scriptName">
  28. <el-input
  29. v-model="queryParams.scriptName"
  30. placeholder="请输入脚本名称"
  31. clearable
  32. @keyup.enter.native="handleQuery"
  33. />
  34. </el-form-item>
  35. <el-form-item>
  36. <el-button
  37. type="primary"
  38. icon="el-icon-search"
  39. size="mini"
  40. @click="handleQuery"
  41. >搜索</el-button
  42. >
  43. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
  44. >重置</el-button
  45. >
  46. </el-form-item>
  47. </el-form>
  48. <el-row :gutter="10" class="mb8">
  49. <el-col :span="1.5">
  50. <el-button
  51. type="primary"
  52. plain
  53. icon="el-icon-plus"
  54. size="mini"
  55. @click="handleAdd"
  56. v-hasPermi="['system:script:add']"
  57. >新增</el-button
  58. >
  59. </el-col>
  60. <el-col :span="1.5">
  61. <el-button
  62. type="success"
  63. plain
  64. icon="el-icon-edit"
  65. size="mini"
  66. :disabled="single"
  67. @click="handleUpdate"
  68. v-hasPermi="['system:script:edit']"
  69. >修改</el-button
  70. >
  71. </el-col>
  72. <el-col :span="1.5">
  73. <el-button
  74. type="danger"
  75. plain
  76. icon="el-icon-delete"
  77. size="mini"
  78. :disabled="multiple"
  79. @click="handleDelete"
  80. v-hasPermi="['system:script:remove']"
  81. >删除</el-button
  82. >
  83. </el-col>
  84. <el-col :span="1.5">
  85. <el-button
  86. type="warning"
  87. plain
  88. icon="el-icon-download"
  89. size="mini"
  90. @click="handleExport"
  91. v-hasPermi="['system:script:export']"
  92. >导出</el-button
  93. >
  94. </el-col>
  95. <right-toolbar
  96. :showSearch.sync="showSearch"
  97. @queryTable="getList"
  98. ></right-toolbar>
  99. </el-row>
  100. <el-table
  101. v-loading="loading"
  102. :data="scriptList"
  103. @selection-change="handleSelectionChange"
  104. >
  105. <el-table-column type="selection" width="55" align="center" />
  106. <el-table-column label="编号" align="center" prop="id" />
  107. <!-- <el-table-column label="脚本编码" align="center" prop="scriptKey" /> -->
  108. <el-table-column
  109. label="脚本方法名称"
  110. align="center"
  111. prop="scriptFunctionName"
  112. />
  113. <el-table-column label="脚本名称" align="center" prop="scriptName" />
  114. <!-- <el-table-column
  115. label="脚本方法体"
  116. align="center"
  117. prop="scriptFunctionCode"
  118. /> -->
  119. <el-table-column label="脚本类型" align="center" prop="scriptType">
  120. <template slot-scope="scope">
  121. {{ getDictLabel(scope.row.scriptType, dict.type.bpm_script_type) }}
  122. </template>
  123. </el-table-column>
  124. <el-table-column label="行业类型" align="center" prop="industryType">
  125. <template slot-scope="scope">
  126. {{ getDictLabel(scope.row.industryType, dict.type.industry_type) }}
  127. </template>
  128. </el-table-column>
  129. <el-table-column
  130. label="脚本描述"
  131. align="center"
  132. prop="scriptDescription"
  133. />
  134. <el-table-column
  135. label="操作"
  136. align="center"
  137. class-name="small-padding fixed-width"
  138. >
  139. <template slot-scope="scope">
  140. <el-button
  141. size="mini"
  142. type="text"
  143. icon="el-icon-edit"
  144. @click="handleUpdate(scope.row)"
  145. v-hasPermi="['system:script:edit']"
  146. >修改</el-button
  147. >
  148. <el-button
  149. size="mini"
  150. type="text"
  151. icon="el-icon-delete"
  152. @click="handleDelete(scope.row)"
  153. v-hasPermi="['system:script:remove']"
  154. >删除</el-button
  155. >
  156. </template>
  157. </el-table-column>
  158. </el-table>
  159. <pagination
  160. v-show="total > 0"
  161. :total="total"
  162. :page.sync="queryParams.pageNum"
  163. :limit.sync="queryParams.pageSize"
  164. @pagination="getList"
  165. />
  166. <!-- 添加或修改流程节点脚本对话框 -->
  167. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  168. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  169. <!-- <el-form-item label="脚本编码:" prop="scriptKey">
  170. <el-input v-model="form.scriptKey" placeholder="请输入脚本编码" />
  171. </el-form-item> -->
  172. <el-form-item label="脚本名称:" prop="scriptName">
  173. <el-input v-model="form.scriptName" placeholder="请输入脚本名称" />
  174. </el-form-item>
  175. <el-form-item label="脚本类型:" prop="scriptType">
  176. <!-- <el-input v-model="form.scriptName" placeholder="请输入脚本名称" /> -->
  177. <el-select
  178. v-model="form.scriptType"
  179. placeholder="请选择脚本类型"
  180. filterable
  181. >
  182. <el-option
  183. v-for="item in dict.type.bpm_script_type"
  184. :key="item.value"
  185. :label="item.label"
  186. :value="item.value"
  187. >
  188. </el-option>
  189. </el-select>
  190. </el-form-item>
  191. <el-form-item label="行业类型:" prop="industryType">
  192. <el-select
  193. v-model="form.industryType"
  194. placeholder="请选择行业类型"
  195. filterable
  196. >
  197. <el-option
  198. v-for="item in dict.type.industry_type"
  199. :key="item.value"
  200. :label="item.label"
  201. :value="item.value"
  202. >
  203. </el-option>
  204. </el-select>
  205. </el-form-item>
  206. <el-form-item label="方法名:" prop="scriptFunctionName">
  207. <el-input
  208. v-model="form.scriptFunctionName"
  209. placeholder="请输入脚本方法名称"
  210. />
  211. </el-form-item>
  212. <el-form-item label="方法体:" prop="scriptFunctionCode">
  213. <!-- <el-input
  214. v-model="form.scriptFunctionCode"
  215. type="textarea"
  216. placeholder="请输入内容"
  217. /> -->
  218. <!-- <div ref="container" class="monaco-container">
  219. </div> -->
  220. <el-button icon="el-icon-edit" @click="drawerOpenHandler"></el-button>
  221. </el-form-item>
  222. <el-form-item label="脚本描述:" prop="scriptDescription">
  223. <el-input
  224. v-model="form.scriptDescription"
  225. placeholder="请输入脚本描述"
  226. />
  227. </el-form-item>
  228. </el-form>
  229. <div slot="footer" class="dialog-footer">
  230. <el-button type="primary" @click="submitForm">确 定</el-button>
  231. <el-button @click="cancel">取 消</el-button>
  232. </div>
  233. </el-dialog>
  234. <el-drawer
  235. :visible.sync="drawer"
  236. direction="rtl"
  237. :before-close="drawerHandleClose"
  238. :with-header="false"
  239. >
  240. <div ref="container" class="monaco-container"></div>
  241. </el-drawer>
  242. </div>
  243. </template>
  244. <script>
  245. import {
  246. listScript,
  247. getScript,
  248. delScript,
  249. addScript,
  250. updateScript,
  251. } from "@/api/bpmprocess/process";
  252. import uuid from "@/utils/bpmn/uuid";
  253. import Editor from "vue2-ace-editor";
  254. import * as monaco from "monaco-editor";
  255. export default {
  256. name: "Script",
  257. dicts: ["bpm_script_type", "industry_type"],
  258. components: { Editor },
  259. data() {
  260. return {
  261. // 遮罩层
  262. loading: true,
  263. // 选中数组
  264. ids: [],
  265. // 非单个禁用
  266. single: true,
  267. // 非多个禁用
  268. multiple: true,
  269. // 显示搜索条件
  270. showSearch: true,
  271. // 总条数
  272. total: 0,
  273. // 流程节点脚本表格数据
  274. scriptList: [],
  275. // 弹出层标题
  276. title: "",
  277. // 是否显示弹出层
  278. open: false,
  279. // 查询参数
  280. queryParams: {
  281. pageNum: 1,
  282. pageSize: 10,
  283. scriptKey: null,
  284. scriptFunctionName: null,
  285. scriptName: null,
  286. scriptFunctionCode: null,
  287. scriptType: null,
  288. industryType: null,
  289. scriptDescription: null,
  290. },
  291. // 表单参数
  292. form: {},
  293. // 表单校验
  294. rules: {
  295. scriptName: [
  296. { required: true, message: "请输入脚本名称", trigger: "blur" },
  297. ],
  298. scriptFunctionName: [
  299. { required: true, message: "请输入脚本函数名", trigger: "blur" },
  300. ],
  301. scriptFunctionCode: [
  302. { required: true, message: "请输入脚本函数体", trigger: "blur" },
  303. ],
  304. scriptType: [
  305. { required: true, message: "请选择脚本类型", trigger: "change" },
  306. ],
  307. industryType: [
  308. { required: true, message: "请选择脚本类型", trigger: "change" },
  309. ],
  310. },
  311. // 代码编辑器相关数据
  312. monacoEditor: null,
  313. codes: "",
  314. readOnly: false,
  315. drawer: false,
  316. editorOptions: {
  317. selectOnLineNumbers: true,
  318. roundedSelection: false,
  319. readOnly: this.readOnly, // 只读
  320. cursorStyle: "line", // 光标样式
  321. automaticLayout: false, // 自动布局
  322. glyphMargin: true, // 字形边缘
  323. useTabStops: false,
  324. fontSize: 28, // 字体大小
  325. autoIndent: false, // 自动布局
  326. },
  327. };
  328. },
  329. created() {
  330. this.getList();
  331. // this.editorInit();
  332. },
  333. methods: {
  334. // 编辑器初始化
  335. editorInit() {
  336. require("brace/theme/chrome");
  337. require("brace/ext/language_tools"); //language extension prerequsite...
  338. require("brace/mode/yaml");
  339. require("brace/mode/json");
  340. require("brace/mode/less");
  341. require("brace/mode/java");
  342. require("brace/snippets/json");
  343. require("brace/mode/lua");
  344. require("brace/snippets/lua");
  345. require("brace/mode/javascript");
  346. require("brace/snippets/javascript");
  347. },
  348. /** 查询流程节点脚本列表 */
  349. getList() {
  350. this.loading = true;
  351. listScript(this.queryParams).then((response) => {
  352. this.scriptList = response.rows;
  353. this.total = response.total;
  354. this.loading = false;
  355. });
  356. },
  357. // 取消按钮
  358. cancel() {
  359. this.open = false;
  360. this.reset();
  361. },
  362. // 表单重置
  363. reset() {
  364. this.form = {
  365. id: null,
  366. scriptKey: null,
  367. scriptFunctionName: null,
  368. scriptName: null,
  369. scriptFunctionCode: null,
  370. scriptType: null,
  371. industryType: null,
  372. scriptDescription: null,
  373. delFlag: null,
  374. createBy: null,
  375. createTime: null,
  376. updateBy: null,
  377. updateTime: null,
  378. };
  379. this.resetForm("form");
  380. },
  381. /** 搜索按钮操作 */
  382. handleQuery() {
  383. this.queryParams.pageNum = 1;
  384. this.getList();
  385. },
  386. /** 重置按钮操作 */
  387. resetQuery() {
  388. this.resetForm("queryForm");
  389. this.handleQuery();
  390. },
  391. // 多选框选中数据
  392. handleSelectionChange(selection) {
  393. this.ids = selection.map((item) => item.id);
  394. this.single = selection.length !== 1;
  395. this.multiple = !selection.length;
  396. },
  397. /** 新增按钮操作 */
  398. handleAdd() {
  399. this.monacoEditor?.dispose();
  400. this.reset();
  401. this.open = true;
  402. this.title = "添加流程节点脚本";
  403. // this.$nextTick(() => {
  404. // this.monacoEditor = monaco.editor.create(this.$refs.container, {
  405. // value: this.form.scriptFunctionCode,
  406. // language: "java",
  407. // theme: "vs-dark", // 编辑器主题:vs, hc-black, or vs-dark
  408. // editorOptions: this.editorOptions,
  409. // });
  410. // });
  411. },
  412. /** 修改按钮操作 */
  413. handleUpdate(row) {
  414. this.monacoEditor?.dispose();
  415. this.reset();
  416. const id = row.id || this.ids;
  417. getScript(id).then((response) => {
  418. response.data.scriptType = response.data.scriptType.toString();
  419. this.form = response.data;
  420. this.open = true;
  421. this.title = "修改流程节点脚本";
  422. });
  423. },
  424. /** 提交按钮 */
  425. submitForm() {
  426. // console.log(this.monacoEditor?.getValue());
  427. this.$refs["form"].validate((valid) => {
  428. if (valid) {
  429. if (this.form.id != null) {
  430. updateScript(this.form).then((response) => {
  431. this.$modal.msgSuccess("修改成功");
  432. this.open = false;
  433. this.getList();
  434. });
  435. } else {
  436. this.form.scriptKey = uuid();
  437. addScript(this.form).then((response) => {
  438. this.$modal.msgSuccess("新增成功");
  439. this.open = false;
  440. this.getList();
  441. });
  442. }
  443. }
  444. });
  445. },
  446. /** 删除按钮操作 */
  447. handleDelete(row) {
  448. const ids = row.id || this.ids;
  449. this.$modal
  450. .confirm('是否确认删除流程节点脚本编号为"' + ids + '"的数据项?')
  451. .then(function () {
  452. return delScript(ids);
  453. })
  454. .then(() => {
  455. this.getList();
  456. this.$modal.msgSuccess("删除成功");
  457. })
  458. .catch(() => {});
  459. },
  460. /** 导出按钮操作 */
  461. handleExport() {
  462. this.download(
  463. "system/script/export",
  464. {
  465. ...this.queryParams,
  466. },
  467. `script_${new Date().getTime()}.xlsx`
  468. );
  469. },
  470. // 获取字典对应label
  471. getDictLabel(value, dictLsit = []) {
  472. return dictLsit.find((item) => {
  473. return item.value == value;
  474. })?.label;
  475. },
  476. // 抽屉打开回调
  477. drawerOpenHandler() {
  478. this.monacoEditor?.dispose();
  479. this.drawer = true;
  480. this.$nextTick(() => {
  481. this.monacoEditor = monaco.editor.create(this.$refs.container, {
  482. value: this.form.scriptFunctionCode,
  483. language: "java",
  484. theme: "vs-dark", // 编辑器主题:vs, hc-black, or vs-dark,更多选择详见官网
  485. contextmenu: false, // 禁用右键菜单
  486. editorOptions: this.editorOptions, // 同codes
  487. });
  488. });
  489. },
  490. // 抽屉关闭前回调
  491. drawerHandleClose(done) {
  492. this.$confirm("即将关闭编辑器,是否保存代码?")
  493. .then(
  494. (val) => {
  495. this.form.scriptFunctionCode = this.monacoEditor?.getValue();
  496. // this.drawer = false;
  497. done();
  498. },
  499. (res) => {
  500. // this.drawer = false;
  501. done();
  502. }
  503. )
  504. .catch(() => {});
  505. },
  506. },
  507. };
  508. </script>
  509. <style lang="scss" scoped>
  510. .codeEditBox {
  511. width: 100%;
  512. height: 200px;
  513. }
  514. // ::v-deep div {
  515. // font-family: "新宋体", serif;
  516. // // font-family: Fira code, Fira Mono, Consolas, Menlo, Courier, monospace;
  517. // font-size: 16px;
  518. // }
  519. .monaco-container {
  520. width: 100%;
  521. height: 100%;
  522. }
  523. </style>