新版交易所前段管理后台
1
PC-20250623MANY\Administrator
2025-07-06 0363875eb333c67529c8b27221a6da45d1a50bfa
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
<template>
  <el-dialog
    :title="!dataForm.id ? '新增横幅' : '修改横幅'"
    :close-on-click-modal="false"
    :visible.sync="visible"
    @close="handClose"
  >
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="100px"
    >
      <el-form-item v-if="!this.row" label="业务代码" prop="contentCode">
        <el-input
          v-model="dataForm.contentCode"
          placeholder="业务代码(同种内容不同语言代码相同)"
        ></el-input>
      </el-form-item>
      <el-form-item label="资金密码" prop="loginSafeword">
        <el-input
          v-model="dataForm.loginSafeword"
          type="password"
          placeholder="资金密码"
        ></el-input>
      </el-form-item>
      <el-form-item label="图片" prop="methodImg">
        <el-upload
          class="avatar-uploader"
          :action="$http.adornUrl('/api/uploadFile')"
          :headers="{ Authorization: $cookie.get('Authorization') }"
          :show-file-list="true"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload"
        >
          <img v-if="dataForm.image" :src="dataForm.image" class="avatar" />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </el-form-item>
 
      <el-form-item v-if="!this.row" label="路径">
        <el-input v-model="dataForm.url" placeholder="路径"></el-input>
      </el-form-item>
      <el-form-item>
        <div class="green">排序索引,数字越小越靠前</div>
      </el-form-item>
      <el-form-item label="排序索引" prop="sortIndex">
        <el-input
          v-model="dataForm.sortIndex"
          placeholder="排序索引,数字越小越靠前"
        ></el-input>
      </el-form-item>
 
      <el-form-item v-if="!this.row" label="模块">
        <el-select
          v-model="model.value"
          placeholder="请选择"
          @change="changeVal()"
        >
          <el-option
            v-for="item in model"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
 
      <el-form-item v-if="!this.row" label="语言">
        <el-select
          v-model="langug.value"
          clearable
          placeholder="请选择"
          @change="changeVal()"
        >
          <el-option
            v-for="item in langug"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
 
      <el-form-item label="是否可点击">
        <el-select
          v-model="click.value"
          placeholder="请选择"
          @change="changeVal()"
        >
          <el-option
            v-for="item in click"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
 
      <el-form-item label="是否展示">
        <el-select
          v-model="onShow.value"
          placeholder="请选择"
          @change="changeVal()"
        >
          <el-option
            v-for="item in onShow"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>
 
<script>
import { treeDataTranslate } from "@/utils";
import { Debounce } from "@/utils/debounce";
import { encrypt } from "@/utils/crypto";
export default {
  data() {
    var validateindex = (rule, value, callback) => {
      if (this.dataForm.sortIndex < 0) {
        callback(new Error("排序不能小于0"));
      } else {
        callback();
      }
    };
    return {
      imageUrl: "",
      dialogImageUrl: "",
      dialogVisible: false,
      visible: false,
      row: "",
      langug: [], // 语言
      menuList: [],
      menuListTreeProps: {
        label: "name",
        children: "children",
      },
      model: [
        {
          label: "顶部展示",
          value: "top",
        },
        {
          label: "其他地方展示",
          value: "other",
        },
        {
          label: "弹窗海报",
          value: "poster",
        },
      ],
      onShow: [
        {
          label: "是",
          value: 1,
        },
        {
          label: "否",
          value: 0,
        },
      ],
      click: [
        {
          label: "是",
          value: 1,
        },
        {
          label: "否",
          value: 0,
        },
      ],
      dataForm: {
        id: "",
        contentCode: "",
        image: "",
        loginSafeword: "",
        sortIndex: "",
        url: "",
      },
      dataRule: {
        roleName: [
          { required: true, message: "角色名称不能为空", trigger: "blur" },
          {
            pattern: /\s\S+|S+\s|\S/,
            message: "请输入正确的角色名称",
            trigger: "blur",
          },
        ],
        sortIndex: [
          { validator: validateindex, trigger: "blur" },
          { required: true, message: "排序不能为空", trigger: "blur" },
        ],
        contentCode: [
          { required: true, message: "业务代码不能为空", trigger: "blur" },
        ],
        loginSafeword: [
          { required: true, message: "资金密码不能为空", trigger: "blur" },
        ],
        image: [{ required: true, message: "图片不能为空", trigger: "blur" }],
        remark: [
          {
            required: false,
            pattern: /\s\S+|S+\s|\S/,
            message: "输入格式有误",
            trigger: "blur",
          },
        ],
      },
      tempKey: -666666, // 临时key, 用于解决tree半选中状态项不能传给后台接口问题. # 待优化
    };
  },
  methods: {
    init(arr, row) {
      this.langug = arr;
      this.row = row || "";
      if (this.row) {
        this.click.value = row.click;
        this.onShow.value = row.onShow;
        this.dataForm.sortIndex = row.sortIndex;
        this.dataForm.image = row.image;
        this.dataForm.id = row.uuid;
      } else {
        this.click.value = this.click[0].value;
        this.onShow.value = this.onShow[0].value;
        this.model.value = this.model[0].value;
        this.langug.value = this.langug[0].value;
      }
      this.$nextTick(() => {
        //this.$refs.dataForm.resetFields()
      });
      this.visible = true;
    },
    // 表单提交
    handClose() {
      this.$data.dataForm = JSON.parse(
        JSON.stringify(this.$options.data().dataForm)
      ); //清除表单数据 拷贝数据
      this.$nextTick(() => {
        this.$refs["dataForm"].clearValidate(); // 清除表单验证
      });
    },
    dataFormSubmit: Debounce(function () {
      if (!this.dataForm.image) {
        this.$message({
          message: "上传图片不能为空",
          type: "error",
          duration: 1500,
          onClose: () => {},
        });
        return;
      }
 
      if (this.row) {
        //start
        this.$refs["dataForm"].validate((valid) => {
          // 修改
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/banner/update`),
              method: "post",
              data: this.$http.adornData({
                click: this.click.value, //是否可以点击
                //contentCode: this.dataForm.contentCode, //业务代码, 同种内容 不同语言下的code相同
                id: this.dataForm.id, //修改传id 新增不传
                image: this.dataForm.image, //展示图片
                //language: this.langug.value, //语言
                loginSafeword: encrypt(this.dataForm.loginSafeword), //资金密码
                //model: this.model.value, //类型,top:顶部展示,other:其他地方展示,poster:弹窗海报
                onShow: this.onShow.value, //是否展示
                sortIndex: this.dataForm.sortIndex, //    排列顺序(数字相同按时间排,越小排越前)
                //url: this.dataForm.url, //访问路径
              }),
            }).then(({ data }) => {
              if (data.code == 0) {
                this.$message({
                  message: "操作成功",
                  type: "success",
                  duration: 1500,
                  onClose: () => {
                    this.visible = false;
                    this.$emit("refreshDataList");
                  },
                });
              } else {
                this.$message({
                  message: data.msg,
                  type: "error",
                  duration: 1500,
                  onClose: () => {
                    this.visible = false;
                  },
                });
              }
            });
          }
        });
      } else {
        //start
        this.$refs["dataForm"].validate((valid) => {
          // 新增
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/banner/add`),
              method: "post",
              data: this.$http.adornData({
                click: this.click.value, //是否可以点击
                contentCode: this.dataForm.contentCode, //业务代码, 同种内容 不同语言下的code相同
                image: this.dataForm.image, //展示图片
                language: this.langug.value, //语言
                loginSafeword: encrypt(this.dataForm.loginSafeword), //资金密码
                model: this.model.value, //类型,top:顶部展示,other:其他地方展示,poster:弹窗海报
                onShow: this.onShow.value, //是否展示
                sortIndex: this.dataForm.sortIndex, //    排列顺序(数字相同按时间排,越小排越前)
                url: this.dataForm.url, //访问路径
              }),
            }).then(({ data }) => {
              if (data.code == 0) {
                this.$message({
                  message: "操作成功",
                  type: "success",
                  duration: 1500,
                  onClose: () => {
                    this.visible = false;
                    this.$emit("refreshDataList");
                  },
                });
              } else {
                this.$message({
                  message: data.msg,
                  type: "error",
                  duration: 1500,
                  onClose: () => {
                    //this.visible = false;
                  },
                });
              }
            });
          }
        });
      }
    }),
    changeVal(val) {
      this.$forceUpdate();
    },
    handleAvatarSuccess(res, file) {
      // this.dataForm.methodImg = res.data.path
      //{"data":{"path":"null/2023-04-29/d3f084ea-391f-4ec9-a2dd-f9393221f58f.png",
      //"httpUrl":"https://trading-order-test.s3.amazonaws.com/null/2023-04-29/d3f084ea-391f-4ec9-a2dd-f9393221f58f.png"},"code":0,"msg":"","succeed":false}
      console.log(res);
      console.log(file);
      this.imageUrl = URL.createObjectURL(file.raw); //显示地址
      this.dataForm.image = res.data.path; //接口传递
      console.log(this.imageUrl);
      if (res.code == 0) {
        this.dataForm.image = res.data.httpUrl;
      }
    },
    beforeAvatarUpload(file) {
      // const isJPG = file.type === 'image/jpeg';
      const isLt2M = file.size / 1024 / 1024 < 10;
      if (!isLt2M) {
        this.$message.error("上传图片大小不能超过 10MB!");
      }
      return isLt2M;
    },
  },
};
</script>
 
<style scoped>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>