index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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="样式key" prop="styleKey">
  12. <el-input
  13. v-model="queryParams.styleKey"
  14. placeholder="请输入样式key"
  15. clearable
  16. @keyup.enter.native="handleQuery"
  17. />
  18. </el-form-item>
  19. <el-form-item label="样式名称" prop="styleName">
  20. <el-input
  21. v-model="queryParams.styleName"
  22. placeholder="请输入样式名称"
  23. clearable
  24. @keyup.enter.native="handleQuery"
  25. />
  26. </el-form-item>
  27. <el-form-item label="样式描述" prop="styleDescription">
  28. <el-input
  29. v-model="queryParams.styleDescription"
  30. placeholder="请输入样式描述"
  31. clearable
  32. @keyup.enter.native="handleQuery"
  33. />
  34. </el-form-item>
  35. <el-form-item label="创建者ID" prop="createById">
  36. <el-input
  37. v-model="queryParams.createById"
  38. placeholder="请输入创建者ID"
  39. clearable
  40. @keyup.enter.native="handleQuery"
  41. />
  42. </el-form-item>
  43. <el-form-item label="更新者ID" prop="updateById">
  44. <el-input
  45. v-model="queryParams.updateById"
  46. placeholder="请输入更新者ID"
  47. clearable
  48. @keyup.enter.native="handleQuery"
  49. />
  50. </el-form-item>
  51. <el-form-item>
  52. <el-button
  53. type="primary"
  54. icon="el-icon-search"
  55. size="mini"
  56. @click="handleQuery"
  57. >搜索</el-button
  58. >
  59. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
  60. >重置</el-button
  61. >
  62. </el-form-item>
  63. </el-form>
  64. <el-row :gutter="10" class="mb8">
  65. <el-col :span="1.5">
  66. <el-button
  67. type="primary"
  68. plain
  69. icon="el-icon-plus"
  70. size="mini"
  71. @click="handleAdd"
  72. v-hasPermi="['system:style:add']"
  73. >新增</el-button
  74. >
  75. </el-col>
  76. <el-col :span="1.5">
  77. <el-button
  78. type="success"
  79. plain
  80. icon="el-icon-edit"
  81. size="mini"
  82. :disabled="single"
  83. @click="handleUpdate"
  84. v-hasPermi="['system:style:edit']"
  85. >修改</el-button
  86. >
  87. </el-col>
  88. <el-col :span="1.5">
  89. <el-button
  90. type="danger"
  91. plain
  92. icon="el-icon-delete"
  93. size="mini"
  94. :disabled="multiple"
  95. @click="handleDelete"
  96. v-hasPermi="['system:style:remove']"
  97. >删除</el-button
  98. >
  99. </el-col>
  100. <el-col :span="1.5">
  101. <el-button
  102. type="warning"
  103. plain
  104. icon="el-icon-download"
  105. size="mini"
  106. @click="handleExport"
  107. v-hasPermi="['system:style:export']"
  108. >导出</el-button
  109. >
  110. </el-col>
  111. <right-toolbar
  112. :showSearch.sync="showSearch"
  113. @queryTable="getList"
  114. ></right-toolbar>
  115. </el-row>
  116. <el-table
  117. v-loading="loading"
  118. stripe
  119. :data="styleList"
  120. @selection-change="handleSelectionChange"
  121. >
  122. <el-table-column type="selection" width="55" align="center" />
  123. <el-table-column label="编号" align="center" prop="id" />
  124. <!-- <el-table-column label="样式key" align="center" prop="styleKey" /> -->
  125. <el-table-column label="样式名称" align="center" prop="styleName" />
  126. <el-table-column label="样式类型" align="center" prop="styleType">
  127. <template slot-scope="scope">
  128. {{ theGetDictLabel(scope.row.styleType, dict.type.table_style_type) }}
  129. </template>
  130. </el-table-column>
  131. <!-- <el-table-column label="样式代码" align="center" prop="styleCode" /> -->
  132. <el-table-column
  133. label="样式描述"
  134. align="center"
  135. prop="styleDescription"
  136. />
  137. <!-- <el-table-column label="样式状态" align="center" prop="styleStatus" /> -->
  138. <!-- <el-table-column label="创建者ID" align="center" prop="createById" />
  139. <el-table-column label="更新者ID" align="center" prop="updateById" /> -->
  140. <el-table-column
  141. label="操作"
  142. align="center"
  143. class-name="small-padding fixed-width"
  144. >
  145. <template slot-scope="scope">
  146. <el-button
  147. size="mini"
  148. type="text"
  149. icon="el-icon-edit"
  150. @click="handleUpdate(scope.row)"
  151. v-hasPermi="['system:style:edit']"
  152. >修改</el-button
  153. >
  154. <el-button
  155. size="mini"
  156. type="text"
  157. icon="el-icon-delete"
  158. @click="handleDelete(scope.row)"
  159. v-hasPermi="['system:style:remove']"
  160. >删除</el-button
  161. >
  162. </template>
  163. </el-table-column>
  164. </el-table>
  165. <pagination
  166. v-show="total > 0"
  167. :total="total"
  168. :page.sync="queryParams.pageNum"
  169. :limit.sync="queryParams.pageSize"
  170. @pagination="getList"
  171. />
  172. <!-- 添加或修改动态格样式模板对话框 -->
  173. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  174. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  175. <!-- <el-form-item label="样式key" prop="styleKey">
  176. <el-input v-model="form.styleKey" placeholder="请输入样式key" />
  177. </el-form-item> -->
  178. <el-form-item label="样式名称" prop="styleName">
  179. <el-input v-model="form.styleName" placeholder="请输入样式名称" />
  180. </el-form-item>
  181. <el-form-item label="样式类型" prop="styleType">
  182. <el-select
  183. v-model="form.styleType"
  184. placeholder="请选择样式类型"
  185. filterable
  186. >
  187. <el-option
  188. v-for="item in dict.type.table_style_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="styleCode">
  197. <el-input
  198. v-model="form.styleCode"
  199. type="textarea"
  200. placeholder="请输入内容"
  201. />
  202. <!-- <el-button icon="el-icon-edit" @click="drawerOpenHandler"></el-button> -->
  203. </el-form-item>
  204. <el-form-item label="样式描述" prop="styleDescription">
  205. <el-input
  206. v-model="form.styleDescription"
  207. placeholder="请输入样式描述"
  208. />
  209. </el-form-item>
  210. <!-- <el-form-item label="删除标志" prop="delFlag">
  211. <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
  212. </el-form-item>
  213. <el-form-item label="创建者ID" prop="createById">
  214. <el-input v-model="form.createById" placeholder="请输入创建者ID" />
  215. </el-form-item>
  216. <el-form-item label="更新者ID" prop="updateById">
  217. <el-input v-model="form.updateById" placeholder="请输入更新者ID" />
  218. </el-form-item> -->
  219. </el-form>
  220. <div slot="footer" class="dialog-footer">
  221. <el-button type="primary" @click="submitForm">确 定</el-button>
  222. <el-button @click="cancel">取 消</el-button>
  223. </div>
  224. </el-dialog>
  225. <el-drawer
  226. :visible.sync="drawer"
  227. direction="rtl"
  228. :before-close="drawerHandleClose"
  229. :with-header="false"
  230. >
  231. <div ref="container" class="monaco-container"></div>
  232. </el-drawer>
  233. </div>
  234. </template>
  235. <script>
  236. import {
  237. listStyle,
  238. getStyle,
  239. delStyle,
  240. addStyle,
  241. updateStyle,
  242. } from "@/api/system/style";
  243. import { getDictLabel } from "@/utils/other";
  244. import * as monaco from "monaco-editor";
  245. export default {
  246. name: "StyleMange",
  247. dicts: ["table_style_type"],
  248. data() {
  249. return {
  250. // 遮罩层
  251. loading: true,
  252. // 选中数组
  253. ids: [],
  254. // 非单个禁用
  255. single: true,
  256. // 非多个禁用
  257. multiple: true,
  258. // 显示搜索条件
  259. showSearch: true,
  260. // 总条数
  261. total: 0,
  262. // 动态格样式模板表格数据
  263. styleList: [],
  264. // 弹出层标题
  265. title: "",
  266. // 是否显示弹出层
  267. open: false,
  268. // 查询参数
  269. queryParams: {
  270. pageNum: 1,
  271. pageSize: 10,
  272. styleKey: null,
  273. styleName: null,
  274. styleType: null,
  275. styleCode: null,
  276. styleDescription: null,
  277. styleStatus: null,
  278. createById: null,
  279. updateById: null,
  280. },
  281. // 表单参数
  282. form: {},
  283. // 表单校验
  284. rules: {
  285. styleName: [
  286. { required: true, message: "请输入样式名", trigger: "blur" },
  287. ],
  288. styleType: [
  289. { required: true, message: "请选择样式类型", trigger: "change" },
  290. ],
  291. styleCode: [
  292. { required: true, message: "请输入样式代码", trigger: "blur" },
  293. ],
  294. styleDescription: [
  295. { required: true, message: "请输入样式样式描述", trigger: "blur" },
  296. ],
  297. },
  298. // 代码编辑器
  299. monacoEditor: null,
  300. drawer: false,
  301. };
  302. },
  303. created() {
  304. this.getList();
  305. },
  306. methods: {
  307. /** 查询动态格样式模板列表 */
  308. getList() {
  309. this.loading = true;
  310. listStyle(this.queryParams).then((response) => {
  311. this.styleList = response.rows;
  312. this.total = response.total;
  313. this.loading = false;
  314. });
  315. },
  316. // 取消按钮
  317. cancel() {
  318. this.open = false;
  319. this.reset();
  320. },
  321. // 表单重置
  322. reset() {
  323. this.form = {
  324. id: null,
  325. styleKey: null,
  326. styleName: null,
  327. styleType: null,
  328. styleCode: null,
  329. styleDescription: null,
  330. styleStatus: null,
  331. delFlag: null,
  332. createBy: null,
  333. createById: null,
  334. createTime: null,
  335. updateBy: null,
  336. updateById: null,
  337. updateTime: null,
  338. };
  339. this.resetForm("form");
  340. },
  341. /** 搜索按钮操作 */
  342. handleQuery() {
  343. this.queryParams.pageNum = 1;
  344. this.getList();
  345. },
  346. /** 重置按钮操作 */
  347. resetQuery() {
  348. this.resetForm("queryForm");
  349. this.handleQuery();
  350. },
  351. // 多选框选中数据
  352. handleSelectionChange(selection) {
  353. this.ids = selection.map((item) => item.id);
  354. this.single = selection.length !== 1;
  355. this.multiple = !selection.length;
  356. },
  357. /** 新增按钮操作 */
  358. handleAdd() {
  359. this.reset();
  360. this.open = true;
  361. this.title = "添加动态格样式模板";
  362. },
  363. /** 修改按钮操作 */
  364. handleUpdate(row) {
  365. this.reset();
  366. const id = row.id || this.ids;
  367. getStyle(id).then((response) => {
  368. this.form = response.data;
  369. this.open = true;
  370. this.title = "修改动态格样式模板";
  371. });
  372. },
  373. /** 提交按钮 */
  374. submitForm() {
  375. this.$refs["form"].validate((valid) => {
  376. if (valid) {
  377. if (this.form.id != null) {
  378. updateStyle(this.form).then((response) => {
  379. this.$modal.msgSuccess("修改成功");
  380. this.open = false;
  381. this.getList();
  382. });
  383. } else {
  384. addStyle(this.form).then((response) => {
  385. this.$modal.msgSuccess("新增成功");
  386. this.open = false;
  387. this.getList();
  388. });
  389. }
  390. }
  391. });
  392. },
  393. /** 删除按钮操作 */
  394. handleDelete(row) {
  395. const ids = row.id || this.ids;
  396. this.$modal
  397. .confirm('是否确认删除动态格样式模板编号为"' + ids + '"的数据项?')
  398. .then(function () {
  399. return delStyle(ids);
  400. })
  401. .then(() => {
  402. this.getList();
  403. this.$modal.msgSuccess("删除成功");
  404. })
  405. .catch(() => {});
  406. },
  407. /** 导出按钮操作 */
  408. handleExport() {
  409. this.download(
  410. "system/style/export",
  411. {
  412. ...this.queryParams,
  413. },
  414. `style_${new Date().getTime()}.xlsx`
  415. );
  416. },
  417. theGetDictLabel(value, dictList) {
  418. return getDictLabel(value, dictList);
  419. },
  420. // 抽屉打开回调
  421. drawerOpenHandler() {
  422. this.monacoEditor?.dispose();
  423. this.drawer = true;
  424. this.$nextTick(() => {
  425. this.monacoEditor = monaco.editor.create(this.$refs.container, {
  426. value: this.form.styleCode,
  427. language: "css",
  428. theme: "vs-dark", // 编辑器主题:vs, hc-black, or vs-dark,更多选择详见官网
  429. contextmenu: false, // 禁用右键菜单
  430. editorOptions: this.editorOptions, // 同codes
  431. });
  432. });
  433. },
  434. // 抽屉关闭前回调
  435. drawerHandleClose(done) {
  436. this.$confirm("即将关闭编辑器,是否保存代码?")
  437. .then(
  438. (val) => {
  439. this.form.styleCode = this.monacoEditor?.getValue();
  440. // this.drawer = false;
  441. done();
  442. },
  443. (res) => {
  444. // this.drawer = false;
  445. done();
  446. }
  447. )
  448. .catch(() => {});
  449. },
  450. },
  451. };
  452. </script>
  453. <style lang="scss" scoped>
  454. .monaco-container {
  455. width: 100%;
  456. height: 100%;
  457. }
  458. </style>