sysDictionary.vue 8.0 KB
Newer Older
Mr.奇淼('s avatar
Mr.奇淼( 已提交
1 2 3 4 5 6
<template>
  <div>
    <div class="search-term">
      <el-form :inline="true" :model="searchInfo" class="demo-form-inline">
        <el-form-item label="字典名(中)">
          <el-input placeholder="搜索条件" v-model="searchInfo.name"></el-input>
7
        </el-form-item>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
8 9
        <el-form-item label="字典名(英)">
          <el-input placeholder="搜索条件" v-model="searchInfo.type"></el-input>
10 11 12 13 14 15 16
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="searchInfo.status" clear placeholder="请选择">
            <el-option key="true" label="是" value="true"></el-option>
            <el-option key="false" label="否" value="false"></el-option>
          </el-select>
        </el-form-item>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
17 18
        <el-form-item label="描述">
          <el-input placeholder="搜索条件" v-model="searchInfo.desc"></el-input>
19
        </el-form-item>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
        <el-form-item>
          <el-button @click="onSubmit" type="primary">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button @click="openDialog" type="primary">新增字典</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      :data="tableData"
      border
      ref="multipleTable"
      stripe
      style="width: 100%"
      tooltip-effect="dark"
    >
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column label="日期" width="180">
        <template slot-scope="scope">{{scope.row.CreatedAt|formatDate}}</template>
      </el-table-column>

      <el-table-column label="字典名(中)" prop="name" width="120"></el-table-column>

      <el-table-column label="字典名(英)" prop="type" width="120"></el-table-column>

      <el-table-column label="状态" prop="status" width="120">
        <template slot-scope="scope">{{scope.row.status|formatBoolean}}</template>
      </el-table-column>

      <el-table-column label="描述" prop="desc" width="280"></el-table-column>

Mr.奇淼('s avatar
Mr.奇淼( 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
      <el-table-column label="按钮组">
        <template slot-scope="scope">
          <el-button @click="toDetile(scope.row)" size="small" type="success">详情</el-button>
          <el-button @click="updateSysDictionary(scope.row)" size="small" type="primary">变更</el-button>
          <el-popover placement="top" width="160" v-model="scope.row.visible">
            <p>确定要删除吗?</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="scope.row.visible = false">取消</el-button>
              <el-button type="primary" size="mini" @click="deleteSysDictionary(scope.row)">确定</el-button>
            </div>
            <el-button type="danger" icon="el-icon-delete" size="mini" slot="reference">删除</el-button>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      :current-page="page"
      :page-size="pageSize"
      :page-sizes="[10, 30, 50, 100]"
      :style="{float:'right',padding:'20px'}"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>

    <el-dialog :before-close="closeDialog" :visible.sync="dialogFormVisible" title="弹窗操作">
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="110px">
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
        <el-form-item label="字典名(中)" prop="name">
          <el-input
            v-model="formData.name"
            placeholder="请输入字典名(中)"
            clearable
            :style="{width: '100%'}"
          ></el-input>
        </el-form-item>
        <el-form-item label="字典名(英)" prop="type">
          <el-input
            v-model="formData.type"
            placeholder="请输入字典名(英)"
            clearable
            :style="{width: '100%'}"
          ></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="status" required>
          <el-switch v-model="formData.status" active-text="开启" inactive-text="停用"></el-switch>
        </el-form-item>
        <el-form-item label="描述" prop="desc">
          <el-input v-model="formData.desc" placeholder="请输入描述" clearable :style="{width: '100%'}"></el-input>
        </el-form-item>
      </el-form>

Mr.奇淼('s avatar
Mr.奇淼( 已提交
104 105 106 107 108
      <div class="dialog-footer" slot="footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button @click="enterDialog" type="primary">确 定</el-button>
      </div>
    </el-dialog>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
109 110

    <div style="margin-top:40px;color:red">获取字典且缓存方法已在前端utils/dictionary 已经封装完成 不必自己书写 使用方法查看文件内注释</div>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
111 112 113 114 115
  </div>
</template>

<script>
import {
116 117 118 119 120 121
  createSysDictionary,
  deleteSysDictionary,
  updateSysDictionary,
  findSysDictionary,
  getSysDictionaryList
} from "@/api/sysDictionary"; //  此处请自行替换地址
Mr.奇淼('s avatar
Mr.奇淼( 已提交
122
import { formatTimeToStr } from "@/utils/date";
123
import infoList from "@/mixins/infoList";
Mr.奇淼('s avatar
Mr.奇淼( 已提交
124 125 126 127 128 129 130 131 132
export default {
  name: "SysDictionary",
  mixins: [infoList],
  data() {
    return {
      listApi: getSysDictionaryList,
      dialogFormVisible: false,
      type: "",
      formData: {
133 134 135 136
        name: null,
        type: null,
        status: true,
        desc: null
Mr.奇淼('s avatar
Mr.奇淼( 已提交
137 138
      },
      rules: {
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
        name: [
          {
            required: true,
            message: "请输入字典名(中)",
            trigger: "blur"
          }
        ],
        type: [
          {
            required: true,
            message: "请输入字典名(英)",
            trigger: "blur"
          }
        ],
        desc: [
          {
            required: true,
            message: "请输入描述",
            trigger: "blur"
          }
        ]
      }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
161 162 163 164 165 166 167 168 169 170 171 172 173
    };
  },
  filters: {
    formatDate: function(time) {
      if (time != null && time != "") {
        var date = new Date(time);
        return formatTimeToStr(date, "yyyy-MM-dd hh:mm:ss");
      } else {
        return "";
      }
    },
    formatBoolean: function(bool) {
      if (bool != null) {
174
        return bool ? "" : "";
Mr.奇淼('s avatar
Mr.奇淼( 已提交
175 176 177 178 179 180
      } else {
        return "";
      }
    }
  },
  methods: {
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
    toDetile(row) {
      this.$router.push({
        name: "dictionaryDetail",
        params: {
          id: row.ID
        }
      });
    },
    //条件搜索前端看此方法
    onSubmit() {
      this.page = 1;
      this.pageSize = 10;
      if (this.searchInfo.status == "") {
        this.searchInfo.status = null;
      }
      this.getTableData();
    },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
198 199 200 201 202 203 204 205 206 207 208
    async updateSysDictionary(row) {
      const res = await findSysDictionary({ ID: row.ID });
      this.type = "update";
      if (res.code == 0) {
        this.formData = res.data.resysDictionary;
        this.dialogFormVisible = true;
      }
    },
    closeDialog() {
      this.dialogFormVisible = false;
      this.formData = {
209 210 211 212
        name: null,
        type: null,
        status: true,
        desc: null
Mr.奇淼('s avatar
Mr.奇淼( 已提交
213 214 215
      };
    },
    async deleteSysDictionary(row) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
216
      row.visible = false;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
217 218 219 220 221 222
      const res = await deleteSysDictionary({ ID: row.ID });
      if (res.code == 0) {
        this.$message({
          type: "success",
          message: "删除成功"
        });
223 224 225
        if (this.tableData.length == 1) {
          this.page--;
        }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
226 227 228 229
        this.getTableData();
      }
    },
    async enterDialog() {
230 231
      this.$refs["elForm"].validate(async valid => {
        if (!valid) return;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
232 233 234 235 236 237 238 239 240 241 242 243
        let res;
        switch (this.type) {
          case "create":
            res = await createSysDictionary(this.formData);
            break;
          case "update":
            res = await updateSysDictionary(this.formData);
            break;
          default:
            res = await createSysDictionary(this.formData);
            break;
        }
244 245 246 247 248
        if (res.code == 0) {
          this.closeDialog();
          this.getTableData();
        }
      });
Mr.奇淼('s avatar
Mr.奇淼( 已提交
249 250 251 252 253 254
    },
    openDialog() {
      this.type = "create";
      this.dialogFormVisible = true;
    }
  },
255
  async created() {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
256 257 258 259 260 261 262
    this.getTableData();
  }
};
</script>

<style>
</style>