最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue-antd?form組件封裝全過程

 更新時間:2023年04月21日 10:24:29   作者:Demo研習社  
這篇文章主要介紹了vue-antd?form組件封裝全過程,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

表單項–公用組件(vue-antd)

1、廢話不多說,先看具體效果

效果圖

具體組件圖

表單校驗圖:

校驗圖

校驗均寫在組件之中,跟當前頁面文件無任何關系,當前頁面只接受組件傳遞過來的參數(shù)…

2、組件代碼如下

在vue項目中,此處采.js文件形式寫組件,并沒用.vue文件去寫…將表單項中的input和change事件暴露出來。。。

export default {
    props: ['value'],
    template: `
    <div>
        <p v-if='typeId == 1' style='width: 60%;display: flex;justify-content: space-between;align-items: center;'>
            <span>預計到達蒸罐地時間:</span>
            <a-date-picker 
                show-time 
                :value='SteamtankTimeVal'
                :allowClear="false"
                placeholder="選擇時間" 
                @change="handleSteamtankTimeInput"
            />
        </p>
        <p v-if='typeId == 1' style='width: 80%;display: flex;justify-content: flex-end;align-items: center;'>
            <span>預計蒸罐所需時間:</span>
            <a-col :span="8">
                <a-input
                    addon-after="小時"
                    :value='tankTime'
                    :disabled='needInput'
                    @change='handleTankTime'
                />
            </a-col>
        </p>
        <p style='width: 60%;display: flex;justify-content: space-between;align-items: center;'>
            <span>預計發(fā)車時間:</span>
            <a-date-picker 
                show-time 
                :value='DepartureTimeVal'
                :allowClear="false"
                placeholder="選擇時間" 
                @change="handleDepartureTimeInput"
            />
        </p>
        <p style='width: 80%;display: flex;justify-content: flex-end;align-items: center;'>
            <span>預計到裝貨地所需時間:</span>
            <a-col :span="8">
                <a-input 
                    addon-after="小時"
                    :disabled='needInput'
                    :value='needLoadAdressTime'
                    @change='handleNeedLoadAdressTime'
                />
            </a-col>
        </p>
        <p style='width: 60%;display: flex;justify-content: space-between;align-items: center;'>
            <span>預計到達裝貨地時間:</span>
            <a-date-picker 
                show-time 
                :value='LoadAddressTimeVal'
                :allowClear="false"
                placeholder="選擇時間" 
                @change="handleLoadAddressTimeInput"
            />
        </p>
        <p style='width: 80%;display: flex;justify-content: flex-end;align-items: center;'>
            <span>預計裝貨所需時間:</span>
            <a-col :span="8">
                <a-input 
                    addon-after="小時"
                    :value='loadTime'
                    :disabled='needInput'
                    @change='handleLoadFinishTime'
                />
            </a-col>
        </p>
        <p style='width: 60%;display: flex;justify-content: space-between;align-items: center;'>
            <span>預計裝貨完成時間:</span>
            <a-date-picker 
                show-time 
                :value='LoadFinishTimeVal'
                :allowClear="false"
                placeholder="選擇時間" 
                @change="handleLoadFinishTimeInput"
            />
        </p>
        <p style='width: 80%;display: flex;justify-content: flex-end;align-items: center;'>
            <span>預計路途所需時間:</span>
            <a-col :span="8">
                <a-input 
                    addon-after="小時"
                    :value='roadTime'
                    :disabled='needInput'
                    @change='handleroadFinishTime'
                />
            </a-col>
        </p>
        <p style='width: 60%;display: flex;justify-content: space-between;align-items: center;'>
            <span>預計到達卸貨地時間:</span>
            <a-date-picker 
                show-time 
                :value='UnloadAddressTimeVal'
                :allowClear="false"
                placeholder="選擇時間" 
                @change="handleUnloadAddressTimeInput"
            />
        </p>
        <p style='width: 80%;display: flex;justify-content: flex-end;align-items: center;'>
            <span>預計卸貨所需時間:</span>
            <a-col :span="8">
                <a-input 
                    addon-after="小時"
                    :value='unLoadTime'
                    :disabled='needInput'
                    @change='handleUnLoadFinishTime'
                />
            </a-col>
        </p>
        <p style='width: 60%;display: flex;justify-content: space-between;align-items: center;'>
            <span>預計卸貨完成時間:</span>
            <a-date-picker 
                show-time 
                :value='UnloadFinishTimeVal'
                :allowClear="false"
                placeholder="選擇時間" 
                @change="handleUnloadFinishTimeInput"
            />
        </p>
    </div>
     `,
    watch: {
        value(val = {}) {
            this.typeId = val.typeId || null
            this.tankTime = val.tankTime || null
            this.loadTime = val.loadTime || null
            this.unLoadTime = val.unLoadTime || null
            this.needLoadAdressTime = val.needLoadAdressTime || null
            this.roadTime = val.roadTime || null
            this.SteamtankTimeVal = val.steamtankTime || null
            this.DepartureTimeVal = val.departureTime || null
            this.LoadAddressTimeVal = val.loadAddressTime || null
            this.LoadFinishTimeVal = val.loadFinishTime || null
            this.UnloadAddressTimeVal = val.unLoadAddressTime || null
            this.UnloadFinishTimeVal = val.unLoadFinishTime || null
        }
    },
    data() {
        let {
            steamtankTime,
            departureTime,
            unLoadFinishTime,
            unLoadAddressTime,
            loadAddressTime,
            loadFinishTime,
            ydccId,
            typeId,
            tankTime,
            loadTime,
            unLoadTime,
            needLoadAdressTime,
            roadTime
        } = this.value
        return {
            moment,
            ydccId: ydccId || null,
            typeId: typeId || null,
            SteamtankTimeVal: steamtankTime || null,
            DepartureTimeVal: departureTime || null,
            LoadAddressTimeVal: loadAddressTime || null,
            LoadFinishTimeVal: loadFinishTime || null,
            UnloadAddressTimeVal: unLoadAddressTime || null,
            UnloadFinishTimeVal: unLoadFinishTime || null,
            tankTime: tankTime || null,
            loadTime: loadTime || null,
            unLoadTime: unLoadTime || null,
            needLoadAdressTime: needLoadAdressTime || null,
            roadTime: roadTime || null,
            minutes30: 1800000,
            hour2: 7200000,
            needInput: true,
        }
    },
    methods: {
        async getLoadTime(steamTankTime) {
            let minutes30 = this.minutes30
            let hour2 = this.hour2
            let params = {
                ydccId: this.ydccId,
                steamTankAddressId: ''
            }
            let result = await predictYdccTime(params)
            if (result.code == 200) {
                let streamAddressToSendAddressTime = Number(result.data.streamAddressToSendAddressTime) * 1.8 //蒸罐地到發(fā)貨地時間(ms)
                let ydccSendToRecTime = Number(result.data.ydccSendToRecTime) * 1.8 //發(fā)貨地到收貨地時間(ms)
                this.needLoadAdressTime = ((streamAddressToSendAddressTime) / 3600000).toFixed(2)
                this.roadTime = ((ydccSendToRecTime - hour2) / 3600000).toFixed(2)

                this.DepartureTimeVal = moment(Number(steamTankTime) + minutes30)
                this.LoadAddressTimeVal = moment(Number(moment(this.DepartureTimeVal).format('x')) + streamAddressToSendAddressTime)
                this.LoadFinishTimeVal = moment(Number(moment(this.LoadAddressTimeVal).format('x')) + hour2)
                this.UnloadAddressTimeVal = moment(Number(moment(this.LoadFinishTimeVal).format('x')) + ydccSendToRecTime)
                this.UnloadFinishTimeVal = moment(Number(moment(this.UnloadAddressTimeVal).format('x')) + hour2)
                let dataTime = {
                    steamtankTime: moment(steamTankTime),
                    departureTime: this.DepartureTimeVal,
                    loadAddressTime: this.LoadAddressTimeVal,
                    loadFinishTime: this.LoadFinishTimeVal,
                    unLoadAddressTime: this.UnloadAddressTimeVal,
                    unLoadFinishTime: this.UnloadFinishTimeVal,
                    typeId: 1,
                    needLoadAdressTime: this.needLoadAdressTime,
                    roadTime: this.roadTime
                }
                this.triggerChange(dataTime)
                this.needInput = false
            } else {
                //.....
            }
        },
        async getDepartureTime(departureTime) {
            let hour2 = this.hour2
            let params = {
                ydccId: this.ydccId,
                steamTankAddressId: ''
            }
            let result = await predictYdccTime(params)
            if (result.code == 200) {
                let streamAddressToSendAddressTime = Number(result.data.streamAddressToSendAddressTime) * 1.8 //發(fā)車到發(fā)貨地時間(ms)
                let ydccSendToRecTime = Number(result.data.ydccSendToRecTime) * 1.8 //發(fā)貨地到收貨地時間(ms)
                this.needLoadAdressTime = (0 * 3600000).toFixed(2)
                this.roadTime = ((ydccSendToRecTime - hour2) / 3600000).toFixed(2)
                this.LoadAddressTimeVal = moment(Number(departureTime) + streamAddressToSendAddressTime)
                this.LoadFinishTimeVal = moment(Number(moment(this.LoadAddressTimeVal).format('x')) + hour2)
                this.UnloadAddressTimeVal = moment(Number(moment(this.LoadFinishTimeVal).format('x')) + ydccSendToRecTime)
                this.UnloadFinishTimeVal = moment(Number(moment(this.UnloadAddressTimeVal).format('x')) + hour2)
                let dataTime = {
                    steamtankTime: moment(departureTime),
                    departureTime: this.DepartureTimeVal,
                    loadAddressTime: this.LoadAddressTimeVal,
                    loadFinishTime: this.LoadFinishTimeVal,
                    unLoadAddressTime: this.UnloadAddressTimeVal,
                    unLoadFinishTime: this.UnloadFinishTimeVal,
                    typeId: 0,
                    needLoadAdressTime: this.needLoadAdressTime,
                    roadTime: this.roadTime
                }
                this.triggerChange(dataTime)
                this.needInput = false
            } else {
                //.....
            }
        },
        // 設置時間間隔
        handleTankTime(e) { //蒸罐所需時間
            const { value } = e.target
            let tankTime = this.changeTime(value)
            this.minutes30 = tankTime
            this.tankTime = value
            this.DepartureTimeVal = moment(Number(moment(this.SteamtankTimeVal).format('x')) + tankTime)
            this.triggerChange({ tankTime: this.tankTime })
            this.triggerChange({ departureTime: this.DepartureTimeVal })
        },
        handleLoadFinishTime(e) { //裝貨所需時間
            const { value } = e.target
            let loadFinishTime = this.changeTime(value)
            this.hour2 = loadFinishTime
            this.loadTime = Number(value)
            this.LoadFinishTimeVal = moment(Number(moment(this.LoadAddressTimeVal).format('x')) + loadFinishTime)
            this.triggerChange({ loadFinishTime: this.LoadFinishTimeVal })
            this.triggerChange({ loadTime: this.loadTime })
        },
        handleUnLoadFinishTime(e) { //卸貨所需時間
            const { value } = e.target
            let unLoadFinishTime = this.changeTime(value)
            this.hour2 = unLoadFinishTime
            this.unLoadTime = Number(value)
            this.UnloadFinishTimeVal = moment(Number(moment(this.UnloadAddressTimeVal).format('x')) + unLoadFinishTime)
            this.triggerChange({ unLoadFinishTime: this.UnloadFinishTimeVal })
            this.triggerChange({ unLoadTime: this.unLoadTime })
        },
        handleNeedLoadAdressTime(e) { //到達裝貨地所需時間
            const { value } = e.target
            let unLoadNeedTime = this.changeTime(value)
            this.needLoadAdressTime = Number(value)
            this.LoadAddressTimeVal = moment(Number(moment(this.DepartureTimeVal).format('x')) + unLoadNeedTime)
            this.triggerChange({ loadAddressTime: this.LoadAddressTimeVal })
            this.triggerChange({ needLoadAdressTime: this.needLoadAdressTime })
        },
        handleroadFinishTime(e) { //路途所需時間
            const { value } = e.target
            let roadNeedTime = this.changeTime(value)
            this.roadTime = Number(value)
            this.UnloadAddressTimeVal = moment(Number(moment(this.LoadFinishTimeVal).format('x')) + roadNeedTime)
            this.triggerChange({ unLoadAddressTime: this.UnloadAddressTimeVal })
            this.triggerChange({ roadTime: this.roadTime })
        },
        changeTime(val) {
            let value = Number(val)
            let oneHour = 3600000
            return value * oneHour
        },
        handleSteamtankTimeInput(_moment, dateString) {
            this.SteamtankTimeVal = _moment
            let steamTankTime = Number(moment(_moment).format('x'))
            this.getLoadTime(steamTankTime)
            this.triggerChange({ steamtankTime: this.SteamtankTimeVal })
        },
        handleDepartureTimeInput(_moment, dateString) {
            this.DepartureTimeVal = _moment
            let departureTime = Number(moment(_moment).format('x'))
            this.getDepartureTime(departureTime);
            this.triggerChange({ departureTime: this.DepartureTimeVal })
        },
        handleLoadAddressTimeInput(_moment, dateString) {
            this.LoadAddressTimeVal = _moment
            this.triggerChange({ loadAddressTime: this.LoadAddressTimeVal })
        },
        handleLoadFinishTimeInput(_moment, dateString) {
            this.LoadFinishTimeVal = _moment
            this.triggerChange({ loadFinishTime: this.LoadFinishTimeVal })
        },
        handleUnloadAddressTimeInput(_moment, dateString) {
            this.UnloadAddressTimeVal = _moment
            this.triggerChange({ unLoadAddressTime: this.UnloadAddressTimeVal })
        },
        handleUnloadFinishTimeInput(_moment, dateString) {
            this.UnloadFinishTimeVal = _moment
            this.triggerChange({ unLoadFinishTime: this.UnloadFinishTimeVal })
        },
        triggerChange(changedValue) {
            let output = Object.assign({
                steamtankTime: this.SteamtankTimeVal,
                departureTime: this.DepartureTimeVal,
                loadAddressTime: this.LoadAddressTimeVal,
                loadFinishTime: this.LoadFinishTimeVal,
                unLoadAddressTime: this.UnloadAddressTimeVal,
                unLoadFinishTime: this.UnloadFinishTimeVal,
                tankTime: this.tankTime,
                loadTime: this.loadTime,
                unLoadTime: this.unLoadTime,
                needLoadAdressTime: this.needLoadAdressTime,
                roadTime: this.roadTime,
                typeId: this.typeId
            }, changedValue)
            this.$emit('input', output)
            this.$emit('change', output)
        }
    }

代碼比較繁瑣,還未進行精簡操作…湊合看吧

3、在相應地方進行引入

剩下的就該怎么玩,就怎么玩咯

總結

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

  • elementPlus表格二次封裝過程

    elementPlus表格二次封裝過程

    我們正常在開發(fā)項目中,表格的風格是一致的,但是表格或多或少會有些不同,有些是需要分頁,有些是按鈕功能不同,有些又需要加Tag,或者對時間進行格式化等,這篇文章主要介紹了elementPlus表格二次封裝過程,需要的朋友可以參考下
    2024-07-07
  • 使用vue的transition完成滑動過渡的示例代碼

    使用vue的transition完成滑動過渡的示例代碼

    這篇文章主要介紹了使用vue的transition完成滑動過渡的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-06-06
  • 源碼分析Vue.js的監(jiān)聽實現(xiàn)教程

    源碼分析Vue.js的監(jiān)聽實現(xiàn)教程

    這篇文章主要通過源碼分析介紹了Vue.js的監(jiān)聽實現(xiàn),文中通過示例代碼介紹的非常詳細,相信對大家具有一定的參考價值,需要的朋友們下面來一起看看吧。
    2017-04-04
  • Vue導入Echarts實現(xiàn)散點圖

    Vue導入Echarts實現(xiàn)散點圖

    這篇文章主要為大家詳細介紹了Vue導入Echarts實現(xiàn)散點圖,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-12-12
  • Vue自定義指令使用方法詳解

    Vue自定義指令使用方法詳解

    這篇文章主要為大家詳細介紹了Vue自定義指令的使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • Vue中的 mixins 和 provide/inject詳解

    Vue中的 mixins 和 provide/inject詳解

    這篇文章主要介紹了Vue中的 mixins 和 provide/inject詳解,本文結合實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-07-07
  • 基于canvas實現(xiàn)手寫簽名(vue)

    基于canvas實現(xiàn)手寫簽名(vue)

    這篇文章主要為大家詳細介紹了基于canvas實現(xiàn)簡易的手寫簽名,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-05-05
  • Vue中ref和$refs的介紹以及使用方法示例

    Vue中ref和$refs的介紹以及使用方法示例

    這篇文章主要給大家介紹了關于Vue中ref和$refs使用方法的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-01-01
  • 記一次用vue做的活動頁的方法步驟

    記一次用vue做的活動頁的方法步驟

    這篇文章主要介紹了記一次用vue做的活動頁的方法步驟,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-04-04
  • vue組件jsx語法的具體使用

    vue組件jsx語法的具體使用

    本篇文章主要介紹了vue組件jsx語法的具體使用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05

最新評論

修文县| 新疆| 离岛区| 潼南县| 宁武县| 永吉县| 广灵县| 出国| 台南市| 陇川县| 荆州市| 滕州市| 海盐县| 寻乌县| 荆门市| 巨野县| 虎林市| 龙泉市| 山阳县| 梁河县| 罗定市| 合江县| 武平县| 莒南县| 民乐县| 即墨市| 武冈市| 乌鲁木齐市| 韶山市| 溆浦县| 庆安县| 新化县| 大连市| 安徽省| 焦作市| 桐梓县| 乐亭县| 内江市| 修水县| 鹤山市| 蒙山县|