在使用 vue+element 开发 Dialog 对话框的时候,点击一个按钮后,显示对话框,对话框填写数据使用下拉菜单展示并选择内容后,关闭模态框;再次打开对话框仍显示上次选中的数据。
点击“推送记录“按钮操作,弹出对话框;显示默认下拉为 “全部”,下拉选择 “已安装”,关闭对话框(点击取消或右上角x);重新打开希望对话框中的下拉数据重置为默认 “全部” 状态。
如下代码中:
点击推送应用记录事件时,未初始推送状态的值为0 所导致再次点击打开对话框时还是显示上次下拉的状态;加上以下一段代码即可!this.pushAppRecordModal.pushStatus = 0
<template>
<div class="app-container">
··· ···
<el-table-column
align="center"
fixed="right"
:label="$t('global.text.operation')"
width="220"
>
<template slot-scope="scope">
<el-button type="text" icon="el-icon-mobile-phone" @click.native.prevent="handlePushAppRecord({deviceId: scope.row.id, realName: scope.row.realName, studentCode: scope.row.studentCode, tag: scope.row.tag})">
{{ $t('device.button.pushAppRecord') }}
</el-button>
<el-button type="text" icon="el-icon-connection" @click.native.prevent="handleBindParent(scope.row.id)">
{{ $t('device.button.bindParent') }}
</el-button>
</template>
</el-table-column>
<!-- 应用推送记录模态框 -->
<el-dialog
width="70%"
top="2vh"
class="app-management"
:title="$t('device.text.pushAppRecordModal')"
:visible.sync="pushAppRecordModal.dialogVisible"
:close-on-click-modal="pushAppRecordModal.closeOnClickModal"
custom-class="app-management"
>
<el-row class="device-info">
<el-select v-model="pushAppRecordModal.pushStatus" @change="handleSelectPushStatus">
<el-option
v-for="item in pushStatusList"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
学生姓名:{{ pushAppRecordModal.deviceInfo.realName }} 学号:{{ pushAppRecordModal.deviceInfo.studentCode }} 设备标识: {{ pushAppRecordModal.deviceInfo.tag }}
</el-row>
<el-row class="app-list">
<el-row v-if="pushAppRecordModal.appList && pushAppRecordModal.appList.length > 0" class="panel" :gutter="20">
<el-col v-for="item in pushAppRecordModal.appList" :key="item.id" :span="8">
<AppItem :key="item.id" :oss-url="ossUrl" :w-desc-limit="10" :item="item" @on-delete-push-app-record="handleDeletePushAppRecord" />
</el-col>
</el-row>
<el-row v-else class="app-empty" type="flex" align="middle" justify="center">
暂无推送应用记录
</el-row>
</el-row>
<div slot="footer">
<el-button plain @click="handleClosePushAppRecordModal">{{ $t('global.button.cancel') }}</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import AppItem from './AppItem'
export default {
components: { AppItem },
data() {
return {
pushAppRecordModal: { // 推送应用记录模态框
dialogVisible: false, // 是否展示
pushStatus: 0, // 推送状态全部
deviceInfo: {},
appList: []
}
}
},
computed: {
pushStatusList() {
return [
{ label: this.$t('device.text.pushStatusAll'), value: 0 },
{ label: this.$t('device.text.pushStatus1'), value: 1 },
{ label: this.$t('device.text.pushStatus2'), value: 2 },
{ label: this.$t('device.text.pushStatus3'), value: 3 },
{ label: this.$t('device.text.pushStatus4'), value: 4 },
{ label: this.$t('device.text.pushStatus5'), value: 5 },
{ label: this.$t('device.text.pushStatus6'), value: 6 },
{ label: this.$t('device.text.pushStatus7'), value: 7 }
]
}
},
methods: {
/* 推送记录 */
// 点击推送应用记录事件
handlePushAppRecord(_deviceInfo) {
this.pushAppRecordModal.deviceInfo = _deviceInfo
//this.pushAppRecordModal.title = this.$t('device.text.pushAppRecordModal')
this.pushAppRecordModal.pushStatus = 0
this.queryPushAppRecordList()
},
// 查询推送记录
queryPushAppRecordList() {
const data = {
deviceId: this.pushAppRecordModal.deviceInfo.deviceId,
pushStatus: this.pushAppRecordModal.pushStatus
}
list(data).then(response => {
this.pushAppRecordModal.appList = response.data
this.pushAppRecordModal.dialogVisible = true
})
},
// 点击推送应用选中列表触发事件
handleSelectPushStatus() {
this.queryPushAppRecordList()
},
// 删除推送记录事件
handleDeletePushAppRecord(_id) {
this.$confirm(this.$t('global.message.delete'), this.$t('global.text.tips'), {
confirmButtonText: this.$t('global.button.confirm'),
cancelButtonText: this.$t('global.button.cancel'),
type: 'warning'
}).then(() => {
this.deletePushAppRecord(_id)
}).catch(() => {
this.$message({
type: 'info',
message: this.$t('global.message.cancelDelete')
})
})
},
// 删除推送记录
deletePushAppRecord(_id) {
deleteById(_id).then(response => {
this.$message.success(response.msg)
this.queryPushAppRecordList()
})
}
// 关闭推送应用模态框事件
handleClosePushAppRecordModal() {
this.pushAppRecordModal.dialogVisible = false
},
}
}
</script>
export default {
device: {
text: {
pushAppRecordModal: '推送应用记录',
pushStatusAll: '全部',
pushStatus1: '已推送',
pushStatus2: '已安装',
pushStatus3: '卸载中',
pushStatus4: '已卸载',
pushStatus5: '申请中',
pushStatus6: '已同意',
pushStatus7: '已拒绝'
},
}
<template>
<el-row class="app-item" type="flex" align="middle" justify="space-between">
<el-row type="flex" justify="start">
<el-row type="flex" align="middle">
<el-avatar shape="square" :src="ossUrl + item.iconUrl" />
</el-row>
<el-row class="app-info" type="flex" align="middle">
<el-row>
<el-row class="app-name">
{{ item.name }}
</el-row>
<el-row class="app-wDesc" type="flex" align="middle">
<dev class="push-status" :class="item.pushStatus == 3 ? 'text-blue' : item.pushStatus == 7 ? 'text-red' : 'text-gray' ">{{ item.pushStatus | pushStatusFilter }}</dev>
<div class="file-size">{{ item.fileSize + 'M' }}</div>
</el-row>
</el-row>
</el-row>
</el-row>
<el-row>
<el-button v-if="item.pushStatus == 1 || item.pushStatus == 3" type="primary" size="mini" class="delete-btn" round @click="handleDeletePushAppRecord(item.id)">
{{ $t('global.button.delete') }}
</el-button>
</el-row>
</el-row>
</template>
<script>
export default {
name: 'ResourceTips',
filters: {
pushStatusFilter(pushStatus) {
if (pushStatus === 1) {
return '已推送'
} else if (pushStatus === 2) {
return '已安装'
} else if (pushStatus === 3) {
return '卸载中'
} else if (pushStatus === 4) {
return '已卸载'
} else if (pushStatus === 5) {
return '申请中'
} else if (pushStatus === 6) {
return '已同意'
} else if (pushStatus === 7) {
return '已拒绝'
} else {
return '待推送'
}
}
},
props: {
item: {
type: Object,
default() {
return {}
}
},
ossUrl: {
type: String,
default: ''
},
wDescLimit: {
type: Number,
default: 15
}
},
methods: {
// 删除推送记录
handleDeletePushAppRecord(_id) {
this.$emit('on-delete-push-app-record', _id)
}
}
}
</script>
<style lang="scss" scoped>
.app-item {
height: 64px;
width: 100%;
margin: 10px 0px 10px 0px;
padding: 10px 10px;
border-radius: 13px;
box-shadow: 0px 1px 3px 0 rgba(0, 0, 0, 0.2);
.app-info {
margin-left: 10px;
}
.app-name {
font-size: 15px;
}
.app-wDesc {
margin-top: 3px;
}
.file-size {
font-size: 8px;
color: #aaa;
}
.push-status {
margin-right: 4px;
font-size: 13px!important;
}
.text-gray {
color: #aaaaaa;
}
.text-blue {
color: #4966F5;
}
.text-red {
color: #e54d42;
}
.el-avatar--square {
border-radius: 8px;
}
.delete-btn {
padding: 5px 10px;
}
}
</style>
如上代码在组件 AppItem.vue 中点击删除按钮前需判断即可:
v-if=“item.pushStatus == 1 || item.pushStatus == 3”
首先要从点击对话框入口操作按钮开始:
handlePushAppRecord 点击处理推送应用记录事件后弹出对话框;
queryPushAppRecordList 查询推送记录
handleSelectPushStatus 点击推送应用下拉选中状态列表触发事件
handleDeletePushAppRecord 删除推送记录事件
deletePushAppRecord 删除推送记录
handleClosePushAppRecordModal 关闭推送应用模态框事件
handleDeletePushAppRecord 时需先判断指定的状态自定义显示删除按钮
Note:
欢迎点赞,留言,转载请在文章页面明显位置给出原文链接
知者,感谢您在茫茫人海中阅读了我的文章
没有个性 哪来的签名!
详情请关注点我
持续更新中
© 2022 06 - Guyu.com | 【版权所有 侵权必究】 |