index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <div class="app-container">
  3. <el-form :inline="true" label-width="68px">
  4. <el-form-item label="字典名称">
  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="字典类型">
  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="状态">
  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="queryParams.createTime"
  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="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  54. <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['system:dict:add']">新增</el-button>
  55. </el-form-item>
  56. </el-form>
  57. <el-table v-loading="loading" :data="typeList" style="width: 100%;">
  58. <el-table-column label="字典主键" align="center" prop="dictId" />
  59. <el-table-column label="字典名称" align="center" prop="dictName" :show-overflow-tooltip="true" />
  60. <el-table-column label="字典类型" align="center">
  61. <template slot-scope="scope">
  62. <router-link :to="'/dict/type/data/' + scope.row.dictId" class="link-type">
  63. <span>{{ scope.row.dictType }}</span>
  64. </router-link>
  65. </template>
  66. </el-table-column>
  67. <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
  68. <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
  69. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  70. <template slot-scope="scope">
  71. <span>{{ parseTime(scope.row.createTime) }}</span>
  72. </template>
  73. </el-table-column>
  74. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  75. <template slot-scope="scope">
  76. <el-button
  77. size="mini"
  78. type="text"
  79. icon="el-icon-edit"
  80. @click="handleUpdate(scope.row)"
  81. v-hasPermi="['system:dict:edit']"
  82. >修改</el-button>
  83. <el-button
  84. size="mini"
  85. type="text"
  86. icon="el-icon-delete"
  87. @click="handleDelete(scope.row)"
  88. v-hasPermi="['system:dict:remove']"
  89. >删除</el-button>
  90. </template>
  91. </el-table-column>
  92. </el-table>
  93. <pagination
  94. v-show="total>0"
  95. :total="total"
  96. :page.sync="queryParams.pageNum"
  97. :limit.sync="queryParams.pageSize"
  98. @pagination="getList"
  99. />
  100. <!-- 添加或修改参数配置对话框 -->
  101. <el-dialog :title="title" :visible.sync="open" width="500px">
  102. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  103. <el-form-item label="字典名称" prop="dictName">
  104. <el-input v-model="form.dictName" placeholder="请输入字典名称" />
  105. </el-form-item>
  106. <el-form-item label="字典类型" prop="dictType">
  107. <el-input v-model="form.dictType" placeholder="请输入字典类型" />
  108. </el-form-item>
  109. <el-form-item label="状态" prop="status">
  110. <el-radio-group v-model="form.status">
  111. <el-radio
  112. v-for="dict in statusOptions"
  113. :key="dict.dictValue"
  114. :label="dict.dictValue"
  115. >{{dict.dictLabel}}</el-radio>
  116. </el-radio-group>
  117. </el-form-item>
  118. <el-form-item label="备注" prop="remark">
  119. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
  120. </el-form-item>
  121. </el-form>
  122. <div slot="footer" class="dialog-footer">
  123. <el-button type="primary" @click="submitForm">确 定</el-button>
  124. <el-button @click="cancel">取 消</el-button>
  125. </div>
  126. </el-dialog>
  127. </div>
  128. </template>
  129. <script>
  130. import { listType, getType, delType, addType, updateType } from "@/api/system/dict/type";
  131. export default {
  132. data() {
  133. return {
  134. // 遮罩层
  135. loading: true,
  136. // 总条数
  137. total: 0,
  138. // 字典表格数据
  139. typeList: [],
  140. // 弹出层标题
  141. title: "",
  142. // 是否显示弹出层
  143. open: false,
  144. // 状态数据字典
  145. statusOptions: [],
  146. // 日期范围
  147. dateRange: [],
  148. // 查询参数
  149. queryParams: {
  150. pageNum: 1,
  151. pageSize: 10,
  152. dictName: undefined,
  153. dictType: undefined,
  154. status: undefined
  155. },
  156. // 表单参数
  157. form: {},
  158. // 表单校验
  159. rules: {
  160. dictName: [
  161. { required: true, message: "字典名称不能为空", trigger: "blur" }
  162. ],
  163. dictType: [
  164. { required: true, message: "字典类型不能为空", trigger: "blur" }
  165. ]
  166. }
  167. };
  168. },
  169. created() {
  170. this.getList();
  171. this.getDicts("sys_normal_disable").then(response => {
  172. this.statusOptions = response.data;
  173. });
  174. },
  175. methods: {
  176. /** 查询字典类型列表 */
  177. getList() {
  178. this.loading = true;
  179. listType(this.addDateRange(this.queryParams, this.dateRange)).then(
  180. response => {
  181. this.typeList = response.rows;
  182. this.total = response.total;
  183. this.loading = false;
  184. }
  185. );
  186. },
  187. // 字典状态字典翻译
  188. statusFormat(row, column) {
  189. return this.selectDictLabel(this.statusOptions, row.status);
  190. },
  191. // 取消按钮
  192. cancel() {
  193. this.open = false;
  194. this.reset();
  195. },
  196. // 表单重置
  197. reset() {
  198. this.form = {
  199. dictId: undefined,
  200. dictName: undefined,
  201. dictType: undefined,
  202. status: "0",
  203. remark: undefined
  204. };
  205. this.resetForm("form");
  206. },
  207. /** 搜索按钮操作 */
  208. handleQuery() {
  209. this.queryParams.pageNum = 1;
  210. this.getList();
  211. },
  212. /** 新增按钮操作 */
  213. handleAdd() {
  214. this.reset();
  215. this.open = true;
  216. this.title = "添加字典类型";
  217. },
  218. /** 修改按钮操作 */
  219. handleUpdate(row) {
  220. this.reset();
  221. getType(row.dictId).then(response => {
  222. this.form = response.data;
  223. this.open = true;
  224. this.title = "修改字典类型";
  225. });
  226. },
  227. /** 提交按钮 */
  228. submitForm: function() {
  229. this.$refs["form"].validate(valid => {
  230. if (valid) {
  231. if (this.form.dictId != undefined) {
  232. updateType(this.form).then(response => {
  233. if (response.code === 200) {
  234. this.msgSuccess("修改成功");
  235. this.open = false;
  236. this.getList();
  237. } else {
  238. this.msgError(response.msg);
  239. }
  240. });
  241. } else {
  242. addType(this.form).then(response => {
  243. if (response.code === 200) {
  244. this.msgSuccess("新增成功");
  245. this.open = false;
  246. this.getList();
  247. } else {
  248. this.msgError(response.msg);
  249. }
  250. });
  251. }
  252. }
  253. });
  254. },
  255. /** 删除按钮操作 */
  256. handleDelete(row) {
  257. this.$confirm('是否确认删除名称为"' + row.dictName + '"的数据项?', "警告", {
  258. confirmButtonText: "确定",
  259. cancelButtonText: "取消",
  260. type: "warning"
  261. }).then(function() {
  262. return delType(row.dictId);
  263. }).then(() => {
  264. this.getList();
  265. this.msgSuccess("删除成功");
  266. }).catch(function() {});
  267. }
  268. }
  269. };
  270. </script>