jeecg-boot 開原始碼 讀碼
阿新 • • 發佈:2020-10-21
前端
TableExpandeSub.vue 是當前內嵌table 主頁 裡邊的create 還有匯入 匯出 增加是在jeecglistminxin.js 內 官網說為了簡便程式碼
先看主頁新增功能
<div class="table-operator"> <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
點選進入
handleAdd 函式 在本頁未定義 在
D:\demo\jeecg-boot\ant-design-vue-jeecg\src\mixins\JeecgListMixin.js
JeecgListMixin.js 中定義了
handleAdd: function () { this.$refs.modalForm.add(); // this.$refs.modalForm.title = "新增"; this.$refs.modalForm.disableSubmit = false; },
this.$refs 是什麼鬼?
ref 有三種用法: 1、ref 加在普通的元素上,用this.ref.name 獲取到的是dom元素 2、ref 加在子元件上,用this.ref.name 獲取到的是元件例項,可以使用元件的所有方法。3、如何利用 v-for 和 ref 獲取一組陣列或者dom 節點
主頁下 那個ref 標籤 意思是頁面載入完之後就可以用這個表單區域內代表頁面的內定義的值了 如下邊則是
JeecgOrderDMainModal.vue 這個編輯 新增頁的
<!-- 表單區域 --> <jeecgOrderDMain-modal ref="modalForm" @ok="modalFormOk"></jeecgOrderDMain-modal>
回到上邊
add() 實際呼叫的
JeecgOrderDMainModal.vue 這個 增加 修改 跳出框的頁面的內容
add()內容為空 給edit函式傳空
methods: { add() { this.edit({}); }, edit(record) { this.form.resetFields(); // 最終在是框架庫中的方法 this.orderMainModel = Object.assign({}, record); //初始化明細表資料 console.log(this.orderMainModel.id) this.visible = true; this.$nextTick(() => { this.form.setFieldsValue(pick(this.orderMainModel, 'orderCode', 'ctype', 'orderMoney', 'content')) this.form.setFieldsValue({orderDate: this.orderMainModel.orderDate ? moment(this.orderMainModel.orderDate) : null}) //時間格式化 }); console.log(this.orderMainModel) },
上邊 this.form.resetFields(); // 是如何呼叫的呢
JeecgOrderDMainModal.vue 內data 中定義的變數綁定了
form: this.$form.createForm(this), 算是新生成物件賦值給form 了
我們看一下
this.$form.createForm(this)
這個是ant-design-vue UI元件裡面的form元件,建立form例項的方法
https://www.antdv.com/components/form-cn/
方法 | 說明 | 型別 |
---|---|---|
getFieldDecorator | 用於和表單進行雙向繫結,單檔案 template 可以使用指令v-decorator 進行繫結,詳見下方描述 |
|
getFieldError | 獲取某個輸入控制元件的 Error | Function(name) |
getFieldsError | 獲取一組輸入控制元件的 Error ,如不傳入引數,則獲取全部元件的 Error | Function([names: string[]]) |
getFieldsValue | 獲取一組輸入控制元件的值,如不傳入引數,則獲取全部元件的值 | Function([fieldNames: string[]]) |
getFieldValue | 獲取一個輸入控制元件的值 | Function(fieldName: string) |
isFieldsTouched | 判斷是否任一輸入控制元件經歷過getFieldDecorator 或v-decorator 的值收集時機options.trigger |
(names?: string[]) => boolean |
isFieldTouched | 判斷一個輸入控制元件是否經歷過getFieldDecorator 或v-decorator 的值收集時機options.trigger |
(name: string) => boolean |
isFieldValidating | 判斷一個輸入控制元件是否在校驗狀態 | Function(name) |
resetFields | 重置一組輸入控制元件的值(為initialValue )與狀態,如不傳入引數,則重置所有元件 |
Function([names: string[]]) |
setFields | 設定一組輸入控制元件的值與錯誤狀態。 | Function({ [fieldName]: { value: any, errors: [Error] } }) |
setFieldsValue | 設定一組輸入控制元件的值 | Function({ [fieldName]: value }) |
validateFields | 校驗並獲取一組輸入域的值與 Error,若 fieldNames 引數為空,則校驗全部元件 | Function([fieldNames: string[]], [options: object], callback: Function(errors, values)) |
validateFieldsAndScroll | 與validateFields 相似,但校驗完後,如果校驗不通過的選單域不在可見範圍內,則自動滾動進可見範圍 |
參考validateFields |
this.$nextTick(() => { this.form.setFieldsValue(pick(this.orderMainModel, 'orderCode', 'ctype', 'orderMoney', 'content')) this.form.setFieldsValue({orderDate: this.orderMainModel.orderDate ? moment(this.orderMainModel.orderDate) : null}) //時間格式化 });