scriptManage.vue 18 KB

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