scriptManage.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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-col :span="20">
  171. <el-input v-model="form.scriptKey" placeholder="请输入脚本编码" :disabled="true"/>
  172. </el-col>
  173. <el-col :span="4">
  174. <el-button icon="el-icon-document-copy" v-clipboard:copy="form.scriptKey" v-clipboard:success="onCopy" v-clipboard:error="onError"></el-button>
  175. </el-col>
  176. </el-form-item>
  177. <el-form-item label="脚本名称:" prop="scriptName">
  178. <el-input v-model="form.scriptName" placeholder="请输入脚本名称" />
  179. </el-form-item>
  180. <el-form-item label="脚本类型:" prop="scriptType">
  181. <!-- <el-input v-model="form.scriptName" placeholder="请输入脚本名称" /> -->
  182. <el-select
  183. v-model="form.scriptType"
  184. placeholder="请选择脚本类型"
  185. filterable
  186. >
  187. <el-option
  188. v-for="item in dict.type.bpm_script_type"
  189. :key="item.value"
  190. :label="item.label"
  191. :value="item.value"
  192. >
  193. </el-option>
  194. </el-select>
  195. </el-form-item>
  196. <el-form-item label="行业类型:" prop="industryType">
  197. <el-select
  198. v-model="form.industryType"
  199. placeholder="请选择行业类型"
  200. filterable
  201. >
  202. <el-option
  203. v-for="item in dict.type.industry_type"
  204. :key="item.value"
  205. :label="item.label"
  206. :value="item.value"
  207. >
  208. </el-option>
  209. </el-select>
  210. </el-form-item>
  211. <el-form-item label="方法名:" prop="scriptFunctionName">
  212. <el-input
  213. v-model="form.scriptFunctionName"
  214. placeholder="请输入脚本方法名称"
  215. />
  216. </el-form-item>
  217. <el-form-item label="方法体:" prop="scriptFunctionCode">
  218. <!-- <el-input
  219. v-model="form.scriptFunctionCode"
  220. type="textarea"
  221. placeholder="请输入内容"
  222. /> -->
  223. <!-- <div ref="container" class="monaco-container">
  224. </div> -->
  225. <el-button icon="el-icon-edit" @click="drawerOpenHandler"></el-button>
  226. </el-form-item>
  227. <el-form-item label="脚本描述:" prop="scriptDescription">
  228. <el-input
  229. v-model="form.scriptDescription"
  230. placeholder="请输入脚本描述"
  231. />
  232. </el-form-item>
  233. </el-form>
  234. <div slot="footer" class="dialog-footer">
  235. <el-button type="primary" @click="submitForm">确 定</el-button>
  236. <el-button @click="cancel">取 消</el-button>
  237. </div>
  238. </el-dialog>
  239. <el-drawer
  240. :visible.sync="drawer"
  241. direction="rtl"
  242. :before-close="drawerHandleClose"
  243. :with-header="false"
  244. >
  245. <div ref="container" class="monaco-container"></div>
  246. </el-drawer>
  247. </div>
  248. </template>
  249. <script>
  250. import {
  251. listScript,
  252. getScript,
  253. addScript,
  254. } from "@/api/bpmprocess/process";
  255. import {updateScript,delScript} from "@/api/bpmprocess/script"
  256. import uuid from "@/utils/bpmn/uuid";
  257. import Editor from "vue2-ace-editor";
  258. import {v4 as uuidv4} from 'uuid';
  259. import * as monaco from "monaco-editor";
  260. import Clipboard from "clipboard";
  261. export default {
  262. name: "Script",
  263. dicts: ["bpm_script_type", "industry_type"],
  264. components: { Editor },
  265. data() {
  266. return {
  267. // 遮罩层
  268. loading: true,
  269. // 选中数组
  270. ids: [],
  271. // 非单个禁用
  272. single: true,
  273. // 非多个禁用
  274. multiple: true,
  275. // 显示搜索条件
  276. showSearch: true,
  277. // 总条数
  278. total: 0,
  279. // 流程节点脚本表格数据
  280. scriptList: [],
  281. // 弹出层标题
  282. title: "",
  283. // 是否显示弹出层
  284. open: false,
  285. // 查询参数
  286. queryParams: {
  287. pageNum: 1,
  288. pageSize: 10,
  289. scriptKey: null,
  290. scriptFunctionName: null,
  291. scriptName: null,
  292. scriptFunctionCode: null,
  293. scriptType: null,
  294. industryType: null,
  295. scriptDescription: null,
  296. },
  297. // 表单参数
  298. form: {
  299. },
  300. // 表单校验
  301. rules: {
  302. scriptName: [
  303. { required: true, message: "请输入脚本名称", trigger: "blur" },
  304. ],
  305. // scriptFunctionName: [
  306. // { required: true, message: "请输入脚本函数名", trigger: "blur" },
  307. // ],
  308. // scriptFunctionCode: [
  309. // { required: true, message: "请输入脚本函数体", trigger: "blur" },
  310. // ],
  311. scriptType: [
  312. { required: true, message: "请选择脚本类型", trigger: "change" },
  313. ],
  314. industryType: [
  315. { required: true, message: "请选择脚本类型", trigger: "change" },
  316. ],
  317. },
  318. // 代码编辑器相关数据
  319. monacoEditor: null,
  320. codes: "",
  321. readOnly: false,
  322. drawer: false,
  323. editorOptions: {
  324. selectOnLineNumbers: true,
  325. roundedSelection: false,
  326. readOnly: this.readOnly, // 只读
  327. cursorStyle: "line", // 光标样式
  328. automaticLayout: false, // 自动布局
  329. glyphMargin: true, // 字形边缘
  330. useTabStops: false,
  331. fontSize: 28, // 字体大小
  332. autoIndent: false, // 自动布局
  333. },
  334. };
  335. },
  336. created() {
  337. this.getList();
  338. // this.editorInit();
  339. },
  340. methods: {
  341. // 编辑器初始化
  342. editorInit() {
  343. require("brace/theme/chrome");
  344. require("brace/ext/language_tools"); //language extension prerequsite...
  345. require("brace/mode/yaml");
  346. require("brace/mode/json");
  347. require("brace/mode/less");
  348. require("brace/mode/java");
  349. require("brace/snippets/json");
  350. require("brace/mode/lua");
  351. require("brace/snippets/lua");
  352. require("brace/mode/javascript");
  353. require("brace/snippets/javascript");
  354. },
  355. // 复制成功
  356. onCopy() {
  357. this.$modal.msgSuccess("脚本编码已成功复制到剪贴板");
  358. },
  359. //复制失败
  360. onError() {
  361. this.$modal.msgError("脚本编码复制失败");
  362. },
  363. /** 查询流程节点脚本列表 */
  364. getList() {
  365. this.loading = true;
  366. listScript(this.queryParams).then((response) => {
  367. this.scriptList = response.rows;
  368. this.total = response.total;
  369. this.loading = false;
  370. });
  371. },
  372. // 取消按钮
  373. cancel() {
  374. this.open = false;
  375. this.reset();
  376. },
  377. // 表单重置
  378. reset() {
  379. this.form = {
  380. id: null,
  381. scriptKey: null,
  382. scriptFunctionName: null,
  383. scriptName: null,
  384. scriptFunctionCode: null,
  385. scriptType: null,
  386. industryType: null,
  387. scriptDescription: null,
  388. delFlag: null,
  389. createBy: null,
  390. createTime: null,
  391. updateBy: null,
  392. updateTime: null,
  393. };
  394. this.resetForm("form");
  395. },
  396. /** 搜索按钮操作 */
  397. handleQuery() {
  398. this.queryParams.pageNum = 1;
  399. this.getList();
  400. },
  401. /** 重置按钮操作 */
  402. resetQuery() {
  403. this.resetForm("queryForm");
  404. this.handleQuery();
  405. },
  406. // 多选框选中数据
  407. handleSelectionChange(selection) {
  408. this.ids = selection.map((item) => item.id);
  409. this.single = selection.length !== 1;
  410. this.multiple = !selection.length;
  411. },
  412. /** 新增按钮操作 */
  413. handleAdd() {
  414. this.monacoEditor?.dispose();
  415. this.reset();
  416. this.form.scriptKey= uuidv4();
  417. console.log(this.form.scriptKey);
  418. this.open = true;
  419. this.title = "添加流程节点脚本";
  420. // this.$nextTick(() => {
  421. // this.monacoEditor = monaco.editor.create(this.$refs.container, {
  422. // value: this.form.scriptFunctionCode,
  423. // language: "java",
  424. // theme: "vs-dark", // 编辑器主题:vs, hc-black, or vs-dark
  425. // editorOptions: this.editorOptions,
  426. // });
  427. // });
  428. },
  429. /** 修改按钮操作 */
  430. handleUpdate(row) {
  431. this.monacoEditor?.dispose();
  432. this.reset();
  433. const id = row.id || this.ids;
  434. getScript(id).then((response) => {
  435. response.data.scriptType = response.data.scriptType.toString();
  436. this.form = response.data;
  437. this.open = true;
  438. this.title = "修改流程节点脚本";
  439. });
  440. },
  441. /** 提交按钮 */
  442. submitForm() {
  443. // console.log(this.monacoEditor?.getValue());
  444. this.$refs["form"].validate((valid) => {
  445. if (valid) {
  446. if (this.form.id != null) {
  447. updateScript(this.form).then((response) => {
  448. this.$modal.msgSuccess("修改成功");
  449. this.open = false;
  450. this.getList();
  451. });
  452. } else {
  453. addScript(this.form).then((response) => {
  454. this.$modal.msgSuccess("新增成功");
  455. this.open = false;
  456. this.getList();
  457. });
  458. }
  459. }
  460. });
  461. },
  462. /** 删除按钮操作 */
  463. handleDelete(row) {
  464. const ids = row.id || this.ids;
  465. this.$modal
  466. .confirm('是否确认删除流程节点脚本编号为"' + ids + '"的数据项?')
  467. .then(function () {
  468. return delScript(ids);
  469. })
  470. .then(() => {
  471. this.getList();
  472. this.$modal.msgSuccess("删除成功");
  473. })
  474. .catch(() => {});
  475. },
  476. /** 导出按钮操作 */
  477. handleExport() {
  478. this.download(
  479. "system/script/export",
  480. {
  481. ...this.queryParams,
  482. },
  483. `script_${new Date().getTime()}.xlsx`
  484. );
  485. },
  486. // 获取字典对应label
  487. getDictLabel(value, dictLsit = []) {
  488. return dictLsit.find((item) => {
  489. return item.value == value;
  490. })?.label;
  491. },
  492. // 抽屉打开回调
  493. drawerOpenHandler() {
  494. this.monacoEditor?.dispose();
  495. this.drawer = true;
  496. this.$nextTick(() => {
  497. this.monacoEditor = monaco.editor.create(this.$refs.container, {
  498. value: this.form.scriptFunctionCode,
  499. language: "java",
  500. theme: "vs-dark", // 编辑器主题:vs, hc-black, or vs-dark,更多选择详见官网
  501. contextmenu: false, // 禁用右键菜单
  502. editorOptions: this.editorOptions, // 同codes
  503. });
  504. });
  505. },
  506. // 抽屉关闭前回调
  507. drawerHandleClose(done) {
  508. this.$confirm("即将关闭编辑器,是否保存代码?")
  509. .then(
  510. (val) => {
  511. this.form.scriptFunctionCode = this.monacoEditor?.getValue();
  512. // this.drawer = false;
  513. done();
  514. },
  515. (res) => {
  516. // this.drawer = false;
  517. done();
  518. }
  519. )
  520. .catch(() => {});
  521. },
  522. },
  523. };
  524. </script>
  525. <style lang="scss" scoped>
  526. .codeEditBox {
  527. width: 100%;
  528. height: 200px;
  529. }
  530. // ::v-deep div {
  531. // font-family: "新宋体", serif;
  532. // // font-family: Fira code, Fira Mono, Consolas, Menlo, Courier, monospace;
  533. // font-size: 16px;
  534. // }
  535. .monaco-container {
  536. width: 100%;
  537. height: 100%;
  538. }
  539. </style>