index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="字典名称" prop="dictName">
  5. <el-input
  6. v-model="queryParams.dictName"
  7. placeholder="请输入字典名称"
  8. clearable
  9. size="small"
  10. style="width: 240px"
  11. @keyup.enter.native="handleQuery"
  12. />
  13. </el-form-item>
  14. <el-form-item label="字典类型" prop="dictType">
  15. <el-input
  16. v-model="queryParams.dictType"
  17. placeholder="请输入字典类型"
  18. clearable
  19. size="small"
  20. style="width: 240px"
  21. @keyup.enter.native="handleQuery"
  22. />
  23. </el-form-item>
  24. <el-form-item label="状态" prop="status">
  25. <el-select
  26. v-model="queryParams.status"
  27. placeholder="字典状态"
  28. clearable
  29. size="small"
  30. style="width: 240px"
  31. >
  32. <el-option
  33. v-for="dict in statusOptions"
  34. :key="dict.dictValue"
  35. :label="dict.dictLabel"
  36. :value="dict.dictValue"
  37. />
  38. </el-select>
  39. </el-form-item>
  40. <el-form-item label="创建时间">
  41. <el-date-picker
  42. v-model="dateRange"
  43. size="small"
  44. style="width: 240px"
  45. value-format="yyyy-MM-dd"
  46. type="daterange"
  47. range-separator="-"
  48. start-placeholder="开始日期"
  49. end-placeholder="结束日期"
  50. ></el-date-picker>
  51. </el-form-item>
  52. <el-form-item>
  53. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  54. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  55. </el-form-item>
  56. </el-form>
  57. <el-row :gutter="10" class="mb8">
  58. <el-col :span="1.5">
  59. <el-button
  60. type="primary"
  61. icon="el-icon-plus"
  62. size="mini"
  63. @click="handleAdd"
  64. v-hasPermi="['system:dict:add']"
  65. >新增</el-button>
  66. </el-col>
  67. <el-col :span="1.5">
  68. <el-button
  69. type="success"
  70. icon="el-icon-edit"
  71. size="mini"
  72. :disabled="single"
  73. @click="handleUpdate"
  74. v-hasPermi="['system:dict:edit']"
  75. >修改</el-button>
  76. </el-col>
  77. <el-col :span="1.5">
  78. <el-button
  79. type="danger"
  80. icon="el-icon-delete"
  81. size="mini"
  82. :disabled="multiple"
  83. @click="handleDelete"
  84. v-hasPermi="['system:dict:remove']"
  85. >删除</el-button>
  86. </el-col>
  87. <el-col :span="1.5">
  88. <el-button
  89. type="warning"
  90. icon="el-icon-download"
  91. size="mini"
  92. @click="handleExport"
  93. v-hasPermi="['system:dict:export']"
  94. >导出</el-button>
  95. </el-col>
  96. <el-col :span="1.5">
  97. <el-button
  98. type="danger"
  99. icon="el-icon-refresh"
  100. size="mini"
  101. @click="handleClearCache"
  102. v-hasPermi="['system:dict:remove']"
  103. >清理缓存</el-button>
  104. </el-col>
  105. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  106. </el-row>
  107. <el-table v-loading="loading" :data="typeList" @selection-change="handleSelectionChange">
  108. <el-table-column type="selection" width="55" align="center" />
  109. <el-table-column label="字典编号" align="center" prop="dictId" />
  110. <el-table-column label="字典名称" align="center" prop="dictName" :show-overflow-tooltip="true" />
  111. <el-table-column label="字典类型" align="center" :show-overflow-tooltip="true">
  112. <template slot-scope="scope">
  113. <router-link :to="'/dict/type/data/' + scope.row.dictId" class="link-type">
  114. <span>{{ scope.row.dictType }}</span>
  115. </router-link>
  116. </template>
  117. </el-table-column>
  118. <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
  119. <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
  120. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  121. <template slot-scope="scope">
  122. <span>{{ parseTime(scope.row.createTime) }}</span>
  123. </template>
  124. </el-table-column>
  125. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  126. <template slot-scope="scope">
  127. <el-button
  128. size="mini"
  129. type="text"
  130. icon="el-icon-edit"
  131. @click="handleUpdate(scope.row)"
  132. v-hasPermi="['system:dict:edit']"
  133. >修改</el-button>
  134. <el-button
  135. size="mini"
  136. type="text"
  137. icon="el-icon-delete"
  138. @click="handleDelete(scope.row)"
  139. v-hasPermi="['system:dict:remove']"
  140. >删除</el-button>
  141. </template>
  142. </el-table-column>
  143. </el-table>
  144. <pagination
  145. v-show="total>0"
  146. :total="total"
  147. :page.sync="queryParams.pageNum"
  148. :limit.sync="queryParams.pageSize"
  149. @pagination="getList"
  150. />
  151. <!-- 添加或修改参数配置对话框 -->
  152. <el-dialog
  153. v-dialogDrag
  154. :fullscreen="dialogFull"
  155. :title="title"
  156. :visible.sync="open"
  157. close-on-click-modal="false"
  158. width="500px" append-to-body>
  159. <template slot="title">
  160. <div class="avue-crud__dialog__header">
  161. <span class="el-dialog__title">
  162. <span style="display:inline-block;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px"></span>
  163. 添加字典类型
  164. </span>
  165. <div class="avue-crud__dialog__menu enlarge" @click="full">
  166. <i style="cursor: pointer;display: block;width:12px;height:12px;border:1px solid #909399;border-top:3px solid #909399;margin-top: -3px;"></i>
  167. </div>
  168. </div>
  169. </template>
  170. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  171. <el-form-item label="字典名称" prop="dictName">
  172. <el-input v-model="form.dictName" placeholder="请输入字典名称" />
  173. </el-form-item>
  174. <el-form-item label="字典类型" prop="dictType">
  175. <el-input v-model="form.dictType" placeholder="请输入字典类型" />
  176. </el-form-item>
  177. <el-form-item label="状态" prop="status">
  178. <el-radio-group v-model="form.status">
  179. <el-radio
  180. v-for="dict in statusOptions"
  181. :key="dict.dictValue"
  182. :label="dict.dictValue"
  183. >{{dict.dictLabel}}</el-radio>
  184. </el-radio-group>
  185. </el-form-item>
  186. <el-form-item label="备注" prop="remark">
  187. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
  188. </el-form-item>
  189. </el-form>
  190. <div slot="footer" class="dialog-footer">
  191. <el-button type="primary" @click="submitForm">确 定</el-button>
  192. <el-button @click="cancel">取 消</el-button>
  193. </div>
  194. </el-dialog>
  195. </div>
  196. </template>
  197. <script>
  198. import { listType, getType, delType, addType, updateType, exportType, clearCache } from "@/api/system/dict/type";
  199. import Vue from 'vue'
  200. Vue.directive('dialogDrag', {
  201. bind(el, binding, vnode, oldVnode) {
  202. const dialogHeaderEl = el.querySelector('.el-dialog__header')
  203. const dragDom = el.querySelector('.el-dialog')
  204. const enlarge = el.querySelector('.enlarge')
  205. dialogHeaderEl.style.cursor = 'move'
  206. // 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);
  207. const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null)
  208. if(enlarge){
  209. enlarge.onclick = (e) => {
  210. dragDom.style.top = '0px'
  211. dragDom.style.left = '0px'
  212. }
  213. }
  214. dialogHeaderEl.onmousedown = (e) => {
  215. // 鼠标按下,计算当前元素距离可视区的距离
  216. const disX = e.clientX - dialogHeaderEl.offsetLeft
  217. const disY = e.clientY - dialogHeaderEl.offsetTop
  218. // 获取到的值带px 正则匹配替换
  219. let styL, styT
  220. // 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为px
  221. if (sty.left.includes('%')) {
  222. styL = +document.body.clientWidth * (+sty.left.replace(/\%/g, '') / 100)
  223. styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100)
  224. } else {
  225. styL = +sty.left.replace(/\px/g, '')
  226. styT = +sty.top.replace(/\px/g, '')
  227. }
  228. document.onmousemove = function(e) {
  229. // 通过事件委托,计算移动的距离
  230. const l = e.clientX - disX
  231. const t = e.clientY - disY
  232. // 移动当前元素
  233. if ((t + styT) >= 0){
  234. dragDom.style.top = `${t + styT}px`
  235. }
  236. dragDom.style.left = `${l + styL}px`
  237. // 将此时的位置传出去
  238. // binding.value({x:e.pageX,y:e.pageY})
  239. }
  240. document.onmouseup = function(e) {
  241. document.onmousemove = null
  242. document.onmouseup = null
  243. }
  244. }
  245. }
  246. })
  247. export default {
  248. name: "Dict",
  249. data() {
  250. return {
  251. //全屏放大
  252. dialogFull:false,
  253. // 遮罩层
  254. loading: true,
  255. // 选中数组
  256. ids: [],
  257. // 非单个禁用
  258. single: true,
  259. // 非多个禁用
  260. multiple: true,
  261. // 显示搜索条件
  262. showSearch: true,
  263. // 总条数
  264. total: 0,
  265. // 字典表格数据
  266. typeList: [],
  267. // 弹出层标题
  268. title: "",
  269. // 是否显示弹出层
  270. open: false,
  271. // 状态数据字典
  272. statusOptions: [],
  273. // 日期范围
  274. dateRange: [],
  275. // 查询参数
  276. queryParams: {
  277. pageNum: 1,
  278. pageSize: 10,
  279. dictName: undefined,
  280. dictType: undefined,
  281. status: undefined,
  282. dictAuthority:'T'
  283. },
  284. // 表单参数
  285. form: {
  286. dictAuthority:'T'
  287. },
  288. // 表单校验
  289. rules: {
  290. dictName: [
  291. { required: true, message: "字典名称不能为空", trigger: "blur" }
  292. ],
  293. dictType: [
  294. { required: true, message: "字典类型不能为空", trigger: "blur" }
  295. ]
  296. }
  297. };
  298. },
  299. created() {
  300. this.getList();
  301. this.getDicts("sys_normal_disable").then(response => {
  302. this.statusOptions = response.data;
  303. });
  304. },
  305. methods: {
  306. //全屏放大
  307. full(){
  308. this.dialogFull = !this.dialogFull
  309. },
  310. /** 查询字典类型列表 */
  311. getList() {
  312. this.loading = true;
  313. listType(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
  314. this.typeList = response.rows;
  315. this.total = response.total;
  316. this.loading = false;
  317. }
  318. );
  319. },
  320. // 字典状态字典翻译
  321. statusFormat(row, column) {
  322. return this.selectDictLabel(this.statusOptions, row.status);
  323. },
  324. // 取消按钮
  325. cancel() {
  326. this.open = false;
  327. this.reset();
  328. },
  329. // 表单重置
  330. reset() {
  331. this.form = {
  332. dictAuthority:'T',
  333. dictId: undefined,
  334. dictName: undefined,
  335. dictType: undefined,
  336. status: "0",
  337. remark: undefined
  338. };
  339. this.resetForm("form");
  340. },
  341. /** 搜索按钮操作 */
  342. handleQuery() {
  343. this.queryParams.pageNum = 1;
  344. this.getList();
  345. },
  346. /** 重置按钮操作 */
  347. resetQuery() {
  348. this.dateRange = [];
  349. this.resetForm("queryForm");
  350. this.handleQuery();
  351. },
  352. /** 新增按钮操作 */
  353. handleAdd() {
  354. this.reset();
  355. this.open = true;
  356. this.title = "添加字典类型";
  357. },
  358. // 多选框选中数据
  359. handleSelectionChange(selection) {
  360. this.ids = selection.map(item => item.dictId)
  361. this.single = selection.length!=1
  362. this.multiple = !selection.length
  363. },
  364. /** 修改按钮操作 */
  365. handleUpdate(row) {
  366. this.reset();
  367. const dictId = row.dictId || this.ids
  368. getType(dictId).then(response => {
  369. this.form = response.data;
  370. this.open = true;
  371. this.title = "修改字典类型";
  372. });
  373. },
  374. /** 提交按钮 */
  375. submitForm: function() {
  376. this.$refs["form"].validate(valid => {
  377. if (valid) {
  378. if (this.form.dictId != undefined) {
  379. updateType(this.form).then(response => {
  380. this.msgSuccess("修改成功");
  381. this.open = false;
  382. this.getList();
  383. });
  384. } else {
  385. console.log(this.form)
  386. addType(this.form).then(response => {
  387. this.msgSuccess("新增成功");
  388. this.open = false;
  389. this.getList();
  390. });
  391. }
  392. }
  393. });
  394. },
  395. /** 删除按钮操作 */
  396. handleDelete(row) {
  397. const dictIds = row.dictId || this.ids;
  398. this.$confirm('是否确认删除字典编号为"' + dictIds + '"的数据项?', "警告", {
  399. confirmButtonText: "确定",
  400. cancelButtonText: "取消",
  401. type: "warning"
  402. }).then(function() {
  403. return delType(dictIds);
  404. }).then(() => {
  405. this.getList();
  406. this.msgSuccess("删除成功");
  407. })
  408. },
  409. /** 导出按钮操作 */
  410. handleExport() {
  411. const queryParams = this.queryParams;
  412. this.$confirm('是否确认导出所有类型数据项?', "警告", {
  413. confirmButtonText: "确定",
  414. cancelButtonText: "取消",
  415. type: "warning"
  416. }).then(function() {
  417. return exportType(queryParams);
  418. }).then(response => {
  419. this.download(response.msg);
  420. })
  421. },
  422. /** 清理缓存按钮操作 */
  423. handleClearCache() {
  424. clearCache().then(response => {
  425. this.msgSuccess("清理成功");
  426. });
  427. }
  428. }
  429. };
  430. </script>
  431. <style lang="scss">
  432. .avue-crud__dialog__header {
  433. display: -webkit-box;
  434. display: -ms-flexbox;
  435. display: flex;
  436. -webkit-box-align: center;
  437. -ms-flex-align: center;
  438. align-items: center;
  439. -webkit-box-pack: justify;
  440. -ms-flex-pack: justify;
  441. justify-content: space-between;
  442. }
  443. .el-dialog__title {
  444. color: rgba(0,0,0,.85);
  445. font-weight: 500;
  446. word-wrap: break-word;
  447. }
  448. .avue-crud__dialog__menu {
  449. padding-right: 20px;
  450. float: left;
  451. }
  452. .avue-crud__dialog__menu i {
  453. color: #909399;
  454. font-size: 15px;
  455. }
  456. .el-icon-full-screen{
  457. cursor: pointer;
  458. }
  459. .el-icon-full-screen:before {
  460. content: "\e719";
  461. }
  462. </style>