Alan
2021-02-16 68e6469516062aa85b7965da10b291bb487cd8a3
岗位管理提交
1个文件已添加
156 ■■■■■ 已修改文件
src/views/febs/system/job/PositionEdit.vue 156 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/febs/system/job/PositionEdit.vue
New file
@@ -0,0 +1,156 @@
<template>
  <el-dialog
    :title="title"
    :width="width"
    top="50px"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    :visible.sync="isVisible"
  >
    <el-form ref="form" :model="position" :rules="rules" label-position="right" label-width="165px">
      <el-form-item label="岗位名称" prop="positionName">
        <el-input v-model="position.positionName" />
      </el-form-item>
      <el-form-item label="岗位编码" prop="positionCode">
        <el-input v-model="position.positionCode" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="warning" plain :loading="buttonLoading" @click="isVisible = false">
        {{ $t('common.cancel') }}
      </el-button>
      <el-button type="primary" plain :loading="buttonLoading" @click="submitForm">
        {{ $t('common.confirm') }}
      </el-button>
    </div>
  </el-dialog>
</template>
<script>
export default {
  name: 'PositionEdit',
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: ''
    },
    type: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      screenWidth: 0,
      buttonLoading: false,
      width: this.initWidth(),
      position: this.initposition(),
      rules: {
        positionName: [
          { required: true, message: this.$t('rules.require'), trigger: 'blur' }
        ],
        positionCode: [
          { required: true, message: this.$t('rules.require'), trigger: 'blur' }
        ],
        authorizedGrantTypes: { required: true, message: this.$t('rules.require'), trigger: 'blur' }
      },
      grantTypes: [
        { type: 'refresh_token' },
        { type: 'authorization_code' },
        { type: 'position_credentials' },
        { type: 'password' },
        { type: 'implicit' }
      ]
    }
  },
  computed: {
    isVisible: {
      get() {
        return this.dialogVisible
      },
      set() {
        this.close()
        this.reset()
      }
    }
  },
  mounted() {
    window.onresize = () => {
      return (() => {
        this.width = this.initWidth()
      })()
    }
  },
  methods: {
    initWidth() {
      this.screenWidth = document.body.positionWidth
      if (this.screenWidth < 991) {
        return '90%'
      } else if (this.screenWidth < 1400) {
        return '45%'
      } else {
        return '800px'
      }
    },
    initposition() {
      return {
        positionId: '',
        resourceIds: '',
        positionSecret: '',
        scope: '',
        authorizedGrantTypes: '',
        webServerRedirectUri: '',
        accessTokenValidity: null,
        refreshTokenValidity: null,
        autoapprove: ''
      }
    },
    setposition(val) {
      this.position = { ...val }
    },
    submitForm() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.buttonLoading = true
          if (this.type === 'add') {
            // create
            this.$post('system/position', { ...this.position }).then(() => {
              this.buttonLoading = false
              this.isVisible = false
              this.$message({
                message: this.$t('tips.createSuccess'),
                type: 'success'
              })
              this.$emit('success')
            })
          } else {
            // update
            this.$put('system/position', { ...this.position }).then(() => {
              this.buttonLoading = false
              this.isVisible = false
              this.$message({
                message: this.$t('tips.updateSuccess'),
                type: 'success'
              })
              this.$emit('success')
            })
          }
        } else {
          return false
        }
      })
    },
    close() {
      this.$emit('close')
    },
    reset() {
      this.$refs.form.clearValidate()
      this.$refs.form.resetFields()
      this.position = this.initposition()
    }
  }
}
</script>