欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue-antd?form組件封裝全過(guò)程

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

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

1、廢話(huà)不多說(shuō),先看具體效果

效果圖

具體組件圖

表單校驗(yàn)圖:

校驗(yàn)圖

校驗(yàn)均寫(xiě)在組件之中,跟當(dāng)前頁(yè)面文件無(wú)任何關(guān)系,當(dāng)前頁(yè)面只接受組件傳遞過(guò)來(lái)的參數(shù)…

2、組件代碼如下

在vue項(xiàng)目中,此處采.js文件形式寫(xiě)組件,并沒(méi)用.vue文件去寫(xiě)…將表單項(xiàng)中的input和change事件暴露出來(lái)。。。

export default {
    props: ['value'],
    template: `
    <div>
        <p v-if='typeId == 1' style='width: 60%;display: flex;justify-content: space-between;align-items: center;'>
            <span>預(yù)計(jì)到達(dá)蒸罐地時(shí)間:</span>
            <a-date-picker 
                show-time 
                :value='SteamtankTimeVal'
                :allowClear="false"
                placeholder="選擇時(shí)間" 
                @change="handleSteamtankTimeInput"
            />
        </p>
        <p v-if='typeId == 1' style='width: 80%;display: flex;justify-content: flex-end;align-items: center;'>
            <span>預(yù)計(jì)蒸罐所需時(shí)間:</span>
            <a-col :span="8">
                <a-input
                    addon-after="小時(shí)"
                    :value='tankTime'
                    :disabled='needInput'
                    @change='handleTankTime'
                />
            </a-col>
        </p>
        <p style='width: 60%;display: flex;justify-content: space-between;align-items: center;'>
            <span>預(yù)計(jì)發(fā)車(chē)時(shí)間:</span>
            <a-date-picker 
                show-time 
                :value='DepartureTimeVal'
                :allowClear="false"
                placeholder="選擇時(shí)間" 
                @change="handleDepartureTimeInput"
            />
        </p>
        <p style='width: 80%;display: flex;justify-content: flex-end;align-items: center;'>
            <span>預(yù)計(jì)到裝貨地所需時(shí)間:</span>
            <a-col :span="8">
                <a-input 
                    addon-after="小時(shí)"
                    :disabled='needInput'
                    :value='needLoadAdressTime'
                    @change='handleNeedLoadAdressTime'
                />
            </a-col>
        </p>
        <p style='width: 60%;display: flex;justify-content: space-between;align-items: center;'>
            <span>預(yù)計(jì)到達(dá)裝貨地時(shí)間:</span>
            <a-date-picker 
                show-time 
                :value='LoadAddressTimeVal'
                :allowClear="false"
                placeholder="選擇時(shí)間" 
                @change="handleLoadAddressTimeInput"
            />
        </p>
        <p style='width: 80%;display: flex;justify-content: flex-end;align-items: center;'>
            <span>預(yù)計(jì)裝貨所需時(shí)間:</span>
            <a-col :span="8">
                <a-input 
                    addon-after="小時(shí)"
                    :value='loadTime'
                    :disabled='needInput'
                    @change='handleLoadFinishTime'
                />
            </a-col>
        </p>
        <p style='width: 60%;display: flex;justify-content: space-between;align-items: center;'>
            <span>預(yù)計(jì)裝貨完成時(shí)間:</span>
            <a-date-picker 
                show-time 
                :value='LoadFinishTimeVal'
                :allowClear="false"
                placeholder="選擇時(shí)間" 
                @change="handleLoadFinishTimeInput"
            />
        </p>
        <p style='width: 80%;display: flex;justify-content: flex-end;align-items: center;'>
            <span>預(yù)計(jì)路途所需時(shí)間:</span>
            <a-col :span="8">
                <a-input 
                    addon-after="小時(shí)"
                    :value='roadTime'
                    :disabled='needInput'
                    @change='handleroadFinishTime'
                />
            </a-col>
        </p>
        <p style='width: 60%;display: flex;justify-content: space-between;align-items: center;'>
            <span>預(yù)計(jì)到達(dá)卸貨地時(shí)間:</span>
            <a-date-picker 
                show-time 
                :value='UnloadAddressTimeVal'
                :allowClear="false"
                placeholder="選擇時(shí)間" 
                @change="handleUnloadAddressTimeInput"
            />
        </p>
        <p style='width: 80%;display: flex;justify-content: flex-end;align-items: center;'>
            <span>預(yù)計(jì)卸貨所需時(shí)間:</span>
            <a-col :span="8">
                <a-input 
                    addon-after="小時(shí)"
                    :value='unLoadTime'
                    :disabled='needInput'
                    @change='handleUnLoadFinishTime'
                />
            </a-col>
        </p>
        <p style='width: 60%;display: flex;justify-content: space-between;align-items: center;'>
            <span>預(yù)計(jì)卸貨完成時(shí)間:</span>
            <a-date-picker 
                show-time 
                :value='UnloadFinishTimeVal'
                :allowClear="false"
                placeholder="選擇時(shí)間" 
                @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ā)貨地時(shí)間(ms)
                let ydccSendToRecTime = Number(result.data.ydccSendToRecTime) * 1.8 //發(fā)貨地到收貨地時(shí)間(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ā)車(chē)到發(fā)貨地時(shí)間(ms)
                let ydccSendToRecTime = Number(result.data.ydccSendToRecTime) * 1.8 //發(fā)貨地到收貨地時(shí)間(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 {
                //.....
            }
        },
        // 設(shè)置時(shí)間間隔
        handleTankTime(e) { //蒸罐所需時(shí)間
            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) { //裝貨所需時(shí)間
            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) { //卸貨所需時(shí)間
            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) { //到達(dá)裝貨地所需時(shí)間
            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) { //路途所需時(shí)間
            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)
        }
    }

代碼比較繁瑣,還未進(jìn)行精簡(jiǎn)操作…湊合看吧

3、在相應(yīng)地方進(jìn)行引入

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

總結(jié)

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

相關(guān)文章

最新評(píng)論