You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 3.2 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /** Copyright 2020 Zhejiang Lab. All Rights Reserved.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. * =============================================================
  15. */
  16. import { isNil } from 'lodash';
  17. import { reactive, watch, ref } from '@vue/composition-api';
  18. const BaseModal = {
  19. name: 'BaseModal',
  20. inheritAttrs: false,
  21. model: {
  22. prop: 'visible',
  23. event: 'change',
  24. },
  25. props: {
  26. visible: {
  27. type: Boolean,
  28. default: false,
  29. },
  30. width: {
  31. type: String,
  32. default: '600px',
  33. },
  34. okText: {
  35. type: String,
  36. default: '确定',
  37. },
  38. cancelText: {
  39. type: String,
  40. default: '取消',
  41. },
  42. footer: Function,
  43. showCancel: {
  44. type: Boolean,
  45. default: true,
  46. },
  47. loading: {
  48. type: Boolean,
  49. default: false,
  50. },
  51. disabled: {
  52. type: Boolean,
  53. default: false,
  54. },
  55. },
  56. setup(props, ctx) {
  57. const dialogRef = ref(null);
  58. const state = reactive({
  59. sVisible: !isNil(props.visible) ? props.visible : false,
  60. });
  61. const handleCancel = (e) => {
  62. ctx.emit('cancel', e);
  63. ctx.emit('change', false);
  64. };
  65. const handleOk = (e) => {
  66. ctx.emit('ok', e);
  67. };
  68. const handleClose = e => {
  69. // 这里只针对状态变更进行控制,只转发 element close 事件
  70. ctx.emit('close', e);
  71. ctx.emit('change', false);
  72. };
  73. watch(() => props.visible, (next) => {
  74. Object.assign(state, {
  75. sVisible: next,
  76. });
  77. }, {
  78. lazy: true,
  79. });
  80. return {
  81. state,
  82. dialogRef,
  83. handleCancel,
  84. handleClose,
  85. handleOk,
  86. };
  87. },
  88. render() {
  89. const renderFooter = () => {
  90. return (
  91. <div class='modal-footer'>
  92. { this.showCancel && (
  93. <el-button id="cancel" onClick={this.handleCancel}>{this.cancelText}</el-button>
  94. )
  95. }
  96. <el-button id="ok" type='primary' disabled={this.disabled} onClick={this.handleOk} loading={this.loading}>{this.okText}</el-button>
  97. </div>
  98. );
  99. };
  100. // footer
  101. const footer = this.$slots.footer || renderFooter();
  102. const dialogProps = {
  103. props: {
  104. closeOnClickModal: false,
  105. appendToBody: true,
  106. visible: this.state.sVisible,
  107. ...this.$props,
  108. ...this.$attrs,
  109. },
  110. on: {
  111. close: this.handleClose,
  112. // 转发 el-dialog 事件
  113. ...this.$listeners,
  114. },
  115. };
  116. return (
  117. <el-dialog {...dialogProps} ref='dialogRef'>
  118. {this.$slots.default}
  119. <div slot='footer'>{footer}</div>
  120. </el-dialog>
  121. );
  122. },
  123. };
  124. export default BaseModal;

一站式算法开发平台、高性能分布式深度学习框架、先进算法模型库、视觉模型炼知平台、数据可视化分析平台等一系列平台及工具,在模型高效分布式训练、数据处理和可视分析、模型炼知和轻量化等技术上形成独特优势,目前已在产学研等各领域近千家单位及个人提供AI应用赋能

Contributors (1)