| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- <!-- -->
- <template>
- <div class="tab6Add">
- <i class="el-icon-arrow-left" title="返回" @click="$router.go(-1)"></i>
- <div class="title">数据{{ ruleForm.id ? "编辑" : "新增" }}</div>
- <div class="from">
- <div class="row" v-for="item in data" :key="item.name">
- <div>{{ item.name }}:</div>
- <el-input
- v-if="item.type === 'varchar'"
- v-model="ruleForm[item.name]"
- :maxlength="item.length"
- show-word-limit
- ></el-input>
- <el-input
- @input="changeInput(item.name)"
- v-else-if="item.type === 'int'"
- v-model="ruleForm[item.name]"
- :maxlength="item.length"
- show-word-limit
- ></el-input>
- <el-date-picker
- format="yyyy 年 MM 月 dd 日"
- value-format="yyyy-MM-dd"
- v-else-if="item.type === 'datetime'"
- v-model="ruleForm[item.name]"
- type="date"
- placeholder="选择日期"
- >
- </el-date-picker>
- </div>
- </div>
- <!-- 底部按钮 -->
- <div class="btn">
- <el-button @click="$router.go(-1)">返 回</el-button>
- <el-button type="primary" @click="save">保 存</el-button>
- </div>
- </div>
- </template>
- <script>
- import {
- getInfoById,
- recordInsert,
- recordDetail,
- recordUpdate,
- } from "@/utils/api";
- export default {
- name: "tab6Add",
- components: {},
- data() {
- //这里存放数据
- return {
- tableId: null,
- ruleForm: {},
- data: [],
- };
- },
- //监听属性 类似于data概念
- computed: {},
- //监控data中的数据变化
- watch: {},
- //方法集合
- methods: {
- // 点击保存
- async save() {
- if (this.ruleForm.id) {
- // 是编辑
- let res = await recordUpdate({
- id: this.ruleForm.id,
- record: this.ruleForm,
- tableId: this.tableId,
- });
- if (res.code === 0) {
- this.$message.success("新增成功");
- this.$router.go(-1);
- } else this.$message.warning(res.msg);
- } else {
- let res = await recordInsert({
- record: this.ruleForm,
- tableId: this.tableId,
- });
- if (res.code === 0) {
- this.$message.success("新增成功");
- this.$router.go(-1);
- } else this.$message.warning(res.msg);
- }
- },
- //数字类型只能输入正整数
- changeInput(val) {
- let pattern = /^[1-9][0-9]*$/; //正整数的正则表达式
- //不符合正整数时
- if (!pattern.test(this.ruleForm[val])) {
- //input框绑定的内容非数字的全部置为空
- this.ruleForm[val] = this.ruleForm[val].replace(/[^\d]/g, "");
- }
- this.ruleForm[val] = Number(this.ruleForm[val]);
- },
- },
- //生命周期 - 创建完成(可以访问当前this实例)
- created() {},
- //生命周期 - 挂载完成(可以访问DOM元素)
- async mounted() {
- // 表格id
- let id = Number(this.$route.params.id);
- this.tableId = id;
- // 数据id,用来编辑
- let k = this.$route.query.k;
- if (k) {
- // 如果是编辑
- k = Number(k);
- let res1 = await recordDetail(id, k);
- this.ruleForm = res1.data;
- }
- let res = await getInfoById(id, {
- pageNum: 1,
- pageSize: 1,
- });
- let temp = res.data.fieldNames;
- this.data = temp.filter((v) => {
- return v.name !== "id" && v.name !== "update_time" && v.name !== "uuid" ;
- });
- },
- beforeCreate() {}, //生命周期 - 创建之前
- beforeMount() {}, //生命周期 - 挂载之前
- beforeUpdate() {}, //生命周期 - 更新之前
- updated() {}, //生命周期 - 更新之后
- beforeDestroy() {}, //生命周期 - 销毁之前
- destroyed() {}, //生命周期 - 销毁完成
- activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
- };
- </script>
- <style lang='less' scoped>
- .tab6Add {
- position: relative;
- width: 100%;
- height: 100%;
- /deep/.el-input__inner {
- padding-right: 70px;
- }
- /deep/.el-icon-arrow-left {
- position: absolute;
- left: 10px;
- top: 0;
- font-size: 30px;
- display: block;
- cursor: pointer;
- }
- .title {
- font-weight: 700;
- padding-left: 60px;
- height: 30px;
- line-height: 30px;
- }
- .from {
- height: 650px;
- overflow-y: auto;
- width: 1200px;
- margin: 20px 0 0 100px;
- .row {
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 10px;
- & > div {
- width: calc(100% - 910px);
- text-align: right;
- }
- /deep/.el-input {
- width: 900px;
- }
- }
- }
- .btn {
- width: 160px;
- height: 40px;
- position: absolute;
- bottom: 40px;
- left: 50%;
- transform: translateX(-50%);
- }
- }
- </style>
|