doum
2026-06-18 93de43267e1663031fe5dc2f5ae40d128a182a76
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<template>
  <GlobalWindow
    :title="title"
    :visible.sync="visible"
    :confirm-working="isWorking"
    width="640px"
    @confirm="confirm"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="96px" class="banner-edit-form">
      <el-form-item label="标题" prop="title">
        <el-input v-model="form.title" placeholder="选填,用于后台识别" maxlength="200" clearable v-trim />
      </el-form-item>
      <el-form-item label="轮播图片" prop="imageUrl">
        <UploadAvatarImage
          :file="imageFile"
          tips-label="上传图片"
          custom-style="width: 320px; height: 120px;"
          :upload-data="{ folder: 'ywH5Banner' }"
          @uploadSuccess="onUploadSuccess"
          @uploadBegin="isUploading = true"
          @uploadEnd="isUploading = false"
        />
        <p class="form-tip">建议尺寸 750×320 左右,支持 jpg/png</p>
      </el-form-item>
      <el-form-item label="跳转链接" prop="linkUrl">
        <el-input v-model="form.linkUrl" placeholder="选填,H5 内链或外链" clearable v-trim />
      </el-form-item>
      <el-form-item label="排序" prop="sortnum">
        <el-input-number v-model="form.sortnum" :min="0" :max="9999" controls-position="right" />
        <span class="inline-tip">数值越小越靠前</span>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-radio-group v-model="form.status">
          <el-radio :label="0">启用</el-radio>
          <el-radio :label="1">禁用</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form.remark" type="textarea" :rows="2" placeholder="选填" maxlength="500" show-word-limit />
      </el-form-item>
    </el-form>
  </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import UploadAvatarImage from '@/components/common/UploadAvatarImage'
 
const defaultForm = () => ({
  id: null,
  title: '',
  imageUrl: '',
  linkUrl: '',
  sortnum: 0,
  status: 0,
  remark: ''
})
 
export default {
  name: 'YwH5BannerEdit',
  extends: BaseOpera,
  components: { GlobalWindow, UploadAvatarImage },
  data () {
    return {
      form: defaultForm(),
      imageFile: { imgurl: '', imgurlfull: '' },
      isUploading: false,
      rules: {
        imageUrl: [{ required: true, message: '请上传轮播图片', trigger: 'change' }],
        sortnum: [{ required: true, message: '请输入排序', trigger: 'change' }]
      }
    }
  },
  created () {
    this.config({
      api: '/business/ywh5banner',
      'field.id': 'id'
    })
  },
  methods: {
    open (title, target) {
      this.title = title
      this.visible = true
      this.isUploading = false
      if (target == null) {
        this.$nextTick(() => {
          this.form = defaultForm()
          this.imageFile = { imgurl: '', imgurlfull: '' }
          this.$refs.form && this.$refs.form.clearValidate()
        })
        return
      }
      this.$nextTick(() => {
        this.form = Object.assign(defaultForm(), target)
        this.imageFile = {
          imgurl: target.imageUrl || '',
          imgurlfull: target.imageUrl || ''
        }
        this.$refs.form && this.$refs.form.clearValidate()
      })
    },
    onUploadSuccess ({ imgurlfull, imgurl }) {
      this.form.imageUrl = imgurlfull || imgurl || ''
      this.imageFile.imgurl = imgurl || this.form.imageUrl
      this.imageFile.imgurlfull = imgurlfull || this.form.imageUrl
      this.$refs.form && this.$refs.form.validateField('imageUrl')
    },
    confirm () {
      if (this.isUploading) {
        this.$message.warning('图片上传中,请稍候')
        return
      }
      if (this.form.id == null || this.form.id === '') {
        this.__confirmCreate()
        return
      }
      this.__confirmEdit()
    }
  }
}
</script>
 
<style scoped lang="scss">
.banner-edit-form {
  padding: 8px 0 12px;
}
 
.banner-edit-form ::v-deep .avatar-uploader-icon {
  line-height: 120px;
}
 
.form-tip,
.inline-tip {
  margin: 6px 0 0;
  font-size: 12px;
  color: #909399;
  line-height: 1.5;
}
 
.inline-tip {
  display: inline-block;
  margin-left: 10px;
  margin-top: 0;
  vertical-align: middle;
}
</style>