index.vue 11.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
<template>
  <div class="custom-page height100">
    <el-card class="height100">
      <div class="page-content">
        <div class="page-tip">
          <span class="tip-title">页面说明:</span>
          <span>可更换app目录界面及运行界面的背景图,可新增背景图,可预览背景图</span>
        </div>
        <div class="top-content">
          <div class="content-title">
            <div class="title">app目录界面设置</div>
            <div class="btn-group">
qzhxx's avatar
qzhxx committed
13
              <el-upload
liqin's avatar
liqin committed
14
                action="http://111.203.232.175:8088/mall/file/image/upload"
qzhxx's avatar
qzhxx committed
15
                :on-success="uploadPageImg"
乐宝呗666's avatar
乐宝呗666 committed
16
                :before-upload="handleBeforeUpload"
乐宝呗666's avatar
乐宝呗666 committed
17
                :headers ="headers"
qzhxx's avatar
qzhxx committed
18 19 20 21
                :file-list="dirList"
              >
                <el-button type="default">上传背景图</el-button>
              </el-upload>
22 23
            </div>
          </div>
qzhxx's avatar
qzhxx committed
24 25 26 27 28 29 30
          <div class="swiper-content top">
            <swiper class="swiper" data-title="page" :options="swiperOption">
              <swiper-slide v-for="(item, index) in pageList" :key="index">
                <div class="swiper-item">
                  <el-radio v-model="radioPage" :label="item.id"></el-radio>
                  <img :src="item.appDirPic" alt />
                </div>
31
              </swiper-slide>
qzhxx's avatar
qzhxx committed
32 33
              <div class="swiper-button-prev" slot="button-prev">
                <i class="iconfont icon-arrow-left"></i>
34
              </div>
qzhxx's avatar
qzhxx committed
35 36
              <div class="swiper-button-next" slot="button-next">
                <i class="iconfont icon-arrow-right"></i>
37 38
              </div>
            </swiper>
qzhxx's avatar
qzhxx committed
39
          </div>
40 41 42 43 44
        </div>
        <div class="down-content">
          <div class="content-title">
            <div class="title">app运行画面设置</div>
            <div class="btn-group">
qzhxx's avatar
qzhxx committed
45
              <el-upload
liqin's avatar
liqin committed
46
                action="http://111.203.232.175:8088/mall/file/image/upload"
qzhxx's avatar
qzhxx committed
47
                :on-success="uploadRunImg"
乐宝呗666's avatar
乐宝呗666 committed
48
                :before-upload="handleBeforeUpload"
乐宝呗666's avatar
乐宝呗666 committed
49
                :headers ="headers"
乐宝呗666's avatar
乐宝呗666 committed
50 51
                :file-list="fileRunList"
              >
qzhxx's avatar
qzhxx committed
52 53
                <el-button type="default">上传背景图</el-button>
              </el-upload>
54 55
            </div>
          </div>
qzhxx's avatar
qzhxx committed
56 57 58 59 60
          <div class="swiper-content bottom">
            <swiper class="swiper" :options="swiperOption">
              <swiper-slide v-for="(item, index) in runList" :key="index">
                <div class="swiper-item">
                  <el-radio v-model="radioRun" :label="item.id"></el-radio>
乐宝呗666's avatar
乐宝呗666 committed
61
                  <img :src="item.appRunPic" alt />
qzhxx's avatar
qzhxx committed
62 63 64 65 66 67 68 69 70 71
                </div>
              </swiper-slide>
              <div class="swiper-button-prev" slot="button-prev">
                <i class="iconfont icon-arrow-left"></i>
              </div>
              <div class="swiper-button-next" slot="button-next">
                <i class="iconfont icon-arrow-right"></i>
              </div>
            </swiper>
          </div>
72 73 74
        </div>
      </div>
      <div class="btn-group footer-btn">
乐宝呗666's avatar
乐宝呗666 committed
75 76
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="submitForm('editform')"
乐宝呗666's avatar
乐宝呗666 committed
77 78
          >确定</el-button
        >
79 80 81 82 83
      </div>
    </el-card>
  </div>
</template>
<script>
qzhxx's avatar
qzhxx committed
84 85 86
import { Swiper, SwiperSlide } from "vue-awesome-swiper";
import "swiper/css/swiper.css";
var vm = {};
87
export default {
qzhxx's avatar
qzhxx committed
88
  components: { Swiper, SwiperSlide },
89 90
  data() {
    return {
乐宝呗666's avatar
乐宝呗666 committed
91
      headers:{Authorization: localStorage.getItem('backToken')},
乐宝呗666's avatar
乐宝呗666 committed
92 93 94 95
      radioPage: "", // 选中项
      radioRun: "",
      dirList: [], // 上传列表
      fileRunList: [],
96
      swiperOption: {
qzhxx's avatar
qzhxx committed
97 98 99
        slideToClickedSlide: true, //点击后居中展示
        slidesPerView: 5,
        spaceBetween: 30,
100
        centeredSlides: true,
乐宝呗666's avatar
乐宝呗666 committed
101
        observer: true,
qzhxx's avatar
qzhxx committed
102 103 104 105 106
        observerParents: true,
        // centerInsufficientSlides: true, //不够5个时居中显示
        // loop: true, // 不能同上一个属性同用
        navigation: {
          nextEl: ".swiper-button-next",
乐宝呗666's avatar
乐宝呗666 committed
107
          prevEl: ".swiper-button-prev",
108
        },
qzhxx's avatar
qzhxx committed
109
        on: {
乐宝呗666's avatar
乐宝呗666 committed
110
          click: function () {
乐宝呗666's avatar
乐宝呗666 committed
111
            
qzhxx's avatar
qzhxx committed
112 113 114 115 116 117
            if (this.$el[0].parentNode.className.indexOf("top") > 0) {
              vm.radioPage = this.realIndex;
            }
            if (this.$el[0].parentNode.className.indexOf("bottom") > 0) {
              vm.radioRun = this.realIndex;
            }
乐宝呗666's avatar
乐宝呗666 committed
118 119
          },
        },
qzhxx's avatar
qzhxx committed
120
      },
乐宝呗666's avatar
乐宝呗666 committed
121 122
      pageList: [], // 数据列表
      runList: [],
123 124
    };
  },
qzhxx's avatar
qzhxx committed
125 126 127 128 129
  created() {},
  mounted() {
    this.getDirPicList();
    this.getAppRunList();
  },
130
  methods: {
qzhxx's avatar
qzhxx committed
131 132 133
    // 查询目录列表
    getDirPicList() {
      let _this = this;
乐宝呗666's avatar
乐宝呗666 committed
134 135 136 137 138 139 140
      _this
        .$https({
          url: "tAppDirPic/getList",
          method: "get",
          authType: this.backToken,
        })
        .then((res) => {
qzhxx's avatar
qzhxx committed
141 142
          if (res.data.resultCode === "200") {
            _this.pageList = res.data.data;
乐宝呗666's avatar
乐宝呗666 committed
143
            _this.pageList.forEach((item) => {
qzhxx's avatar
qzhxx committed
144 145 146 147 148
              if (item.isCurrent) {
                this.radioPage = item.id;
              }
            });
          } else {
乐宝呗666's avatar
乐宝呗666 committed
149
            this.$message.error(res.data.message);
qzhxx's avatar
qzhxx committed
150 151
          }
        })
乐宝呗666's avatar
乐宝呗666 committed
152
        .catch(function (err) {
qzhxx's avatar
qzhxx committed
153 154 155 156 157 158
          console.log(err);
        });
    },
    // 查询运行列表
    getAppRunList() {
      let _this = this;
乐宝呗666's avatar
乐宝呗666 committed
159 160 161 162 163 164 165
      _this
        .$https({
          url: "tAppRunPic/getList",
          method: "get",
          authType: this.backToken,
        })
        .then((res) => {
qzhxx's avatar
qzhxx committed
166 167
          if (res.data.resultCode === "200") {
            _this.runList = res.data.data;
乐宝呗666's avatar
乐宝呗666 committed
168
            _this.runList.forEach((item) => {
qzhxx's avatar
qzhxx committed
169 170 171 172 173
              if (item.isCurrent) {
                this.radioRun = item.id;
              }
            });
          } else {
乐宝呗666's avatar
乐宝呗666 committed
174
            this.$message.error(res.data.message);
qzhxx's avatar
qzhxx committed
175 176
          }
        })
乐宝呗666's avatar
乐宝呗666 committed
177
        .catch(function (err) {
qzhxx's avatar
qzhxx committed
178 179 180
          console.log(err);
        });
    },
乐宝呗666's avatar
乐宝呗666 committed
181 182 183 184 185 186 187 188 189
    // 上传文件格式限制
    handleBeforeUpload(file) {
      if (file.type !== "image/jpeg" && file.type !== "image/png") {
        this.$message.error("只能上传jpeg、jpg、png格式的文件");
        return false;
      }
      return true;
    },
    // 新增目录图片
qzhxx's avatar
qzhxx committed
190
    uploadPageImg(res, file) {
乐宝呗666's avatar
乐宝呗666 committed
191 192 193 194 195 196 197 198
      if (res.resultCode === "200") {
        this.saveItem(
          { appDirPic: res.data.url, isCurrent: 1 },
          "tAppDirPic/save"
        );
      } else {
        this.$message.error(res.message);
      }
qzhxx's avatar
qzhxx committed
199
    },
乐宝呗666's avatar
乐宝呗666 committed
200
    // 新增运行图片
qzhxx's avatar
qzhxx committed
201
    uploadRunImg(res, file) {
乐宝呗666's avatar
乐宝呗666 committed
202 203 204 205 206 207 208 209
      if (res.resultCode === "200") {
        this.saveItem(
          { appRunPic: res.data.url, isCurrent: 1 },
          "tAppRunPic/save"
        );
      } else {
        this.$message.error(res.message);
      }
qzhxx's avatar
qzhxx committed
210
    },
乐宝呗666's avatar
乐宝呗666 committed
211 212
    // 新增接口
    saveItem(param, url) {
qzhxx's avatar
qzhxx committed
213
      let _this = this;
乐宝呗666's avatar
乐宝呗666 committed
214 215
      _this
        .$https(
qzhxx's avatar
qzhxx committed
216 217 218
          {
            url: url,
            method: "post",
乐宝呗666's avatar
乐宝呗666 committed
219
            authType: this.backToken,
qzhxx's avatar
qzhxx committed
220 221 222 223
          },
          _this.$qs.stringify(param)
        )
        .then(
乐宝呗666's avatar
乐宝呗666 committed
224
          (res) => {
qzhxx's avatar
qzhxx committed
225
            if (res.data.resultCode === "200") {
乐宝呗666's avatar
乐宝呗666 committed
226 227 228
              _this.$message.success(res.data.message);
              this.getDirPicList();
              this.getAppRunList();
qzhxx's avatar
qzhxx committed
229
            } else {
乐宝呗666's avatar
乐宝呗666 committed
230
              _this.$message.error(res.data.message);
qzhxx's avatar
qzhxx committed
231 232
            }
          },
乐宝呗666's avatar
乐宝呗666 committed
233 234
          (error) => {
            console.log(error);
qzhxx's avatar
qzhxx committed
235 236 237
          }
        );
    },
乐宝呗666's avatar
乐宝呗666 committed
238
    // 修改当前项
qzhxx's avatar
qzhxx committed
239
    submitForm() {
240 241 242 243 244 245
      if(vm.radioPage !== undefined){
        this.updateCurrent(this.pageList[vm.radioPage].id, "tAppDirPic/update");
      }
      if(vm.radioRun!== undefined){
        this.updateCurrent(this.runList[vm.radioRun].id, "tAppRunPic/update");
      }
qzhxx's avatar
qzhxx committed
246
    },
乐宝呗666's avatar
乐宝呗666 committed
247
    updateCurrent(id, url) {
qzhxx's avatar
qzhxx committed
248 249 250
      let vm = this;
      let param = {
        id: id,
乐宝呗666's avatar
乐宝呗666 committed
251
        isCurrent: 1,
qzhxx's avatar
qzhxx committed
252 253 254 255 256
      };
      vm.$https(
        {
          url: url,
          method: "put",
乐宝呗666's avatar
乐宝呗666 committed
257
          authType: this.backToken,
qzhxx's avatar
qzhxx committed
258 259 260
        },
        vm.$qs.stringify(param)
      )
乐宝呗666's avatar
乐宝呗666 committed
261 262 263
        .then((res) => {
          if (res.data.resultCode === "200") {
            this.$message.success("操作成功");
qzhxx's avatar
qzhxx committed
264 265
            this.getDirPicList();
            this.getAppRunList();
乐宝呗666's avatar
乐宝呗666 committed
266 267
          } else {
            this.$message.error(res.data.message);
qzhxx's avatar
qzhxx committed
268 269
          }
        })
乐宝呗666's avatar
乐宝呗666 committed
270
        .catch(function (err) {
qzhxx's avatar
qzhxx committed
271 272 273
          console.log(err);
        });
    },
乐宝呗666's avatar
乐宝呗666 committed
274
    // 取消
qzhxx's avatar
qzhxx committed
275 276
    close() {
      this.$router.go(-1);
乐宝呗666's avatar
乐宝呗666 committed
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
};
</script>
<style lang="less" scoped>
.custom-page {
  position: relative;
  .page-title {
    font-size: 20px;
    color: #333333;
    text-align: center;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
  }
  .page-tip {
    background: #f7f5f2;
    border-radius: 8px;
    padding: 16px 20px;
    margin: 20px 0;
    font-size: 14px;
    color: #333333;
    .tip-title {
      font-weight: 700;
      margin-right: 5px;
    }
  }
  .page-content {
    width: 800px;
    margin: 0 auto;
    .content-title {
      display: flex;
      justify-content: space-between;
      padding: 20px;
      .title {
        position: relative;
        font-size: 18px;
        color: #333333;
        &::before {
          content: "";
          position: absolute;
          top: 6px;
          left: -20px;
          width: 4px;
          height: 18px;
          background: #000;
        }
      }
      .el-button {
        padding: 0 20px;
      }
    }
qzhxx's avatar
qzhxx committed
328 329 330 331 332 333 334
    .swiper-content {
      .swiper-item {
        position: relative;
        width: 100%;
        height: 128px;
        background-color: #99a9bf;
        border-radius: 10px;
335

qzhxx's avatar
qzhxx committed
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
        /deep/.el-radio {
          position: absolute;
          right: 12px;
          top: 12px;
          .el-radio__label {
            display: none;
          }
          .el-radio__inner {
            width: 24px;
            height: 24px;
          }
          .el-radio__input.is-checked .el-radio__inner {
            border-color: #ac9374;
            background: #ac9374;
          }
          .el-radio__inner:hover {
            border-color: #ac9374;
          }
        }
        img {
          width: 100%;
          height: 100%;
        }
      }
      .swiper-button-next {
        right: 0;
      }
      .swiper-button-prev {
        left: 0;
      }
      .swiper-button-prev,
      .swiper-button-next {
        background: #ac9374;
        width: 36px;
        height: 36px;
        border-radius: 50%;
      }
      .swiper-button-next:after,
      .swiper-button-prev:after {
        font-size: 14px;
        font-weight: 700;
        color: #fff;
      }
      .swiper-slide {
        text-align: center;
        font-size: 18px;
        background: #fff;
        display: -webkit-box;
        display: -ms-flexbox;
        display: -webkit-flex;
        display: flex;
        -webkit-box-pack: center;
        -ms-flex-pack: center;
        -webkit-justify-content: center;
        justify-content: center;
        -webkit-box-align: center;
        -ms-flex-align: center;
        -webkit-align-items: center;
        align-items: center;
        transition: 300ms;
        transform: scale(0.8);
      }
      .swiper-slide-active,
      .swiper-slide-duplicate-active {
        transform: scale(1);
      }
402 403
    }
  }
qzhxx's avatar
qzhxx committed
404 405 406
  /deep/.el-upload-list {
    display: none;
  }
407 408 409 410 411 412 413 414 415
  .footer-btn {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    text-align: center;
    padding-top: 20px;
    border-top: 1px solid #eee;
    .el-button {
乐宝呗666's avatar
乐宝呗666 committed
416
      width: 160px;
417 418 419
    }
  }
}
liqin's avatar
liqin committed
420
</style>