FormPreview.vue 13.9 KB
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 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
<template>
  <div class="form-container" id="flow-form-container">
    <div class="preview-header">
      <ht-h3 inline>表单预览</ht-h3>
      <div class="preview-header__left">
        <ht-switch
          v-model="validate"
          active-text="校验表单"
          inactive-text="不校验表单"
        />
        <el-button type="primary" @click="handleShowData">表单数据</el-button>
        <el-button
          plain
          class="scan-code__btn"
          v-if="isMobile"
          @click="handleScanPreview"
          >扫码预览</el-button
        >
      </div>
      <div class="qrCode-wrap" v-show="isShowCode">
        <div class="code-header">
          <span class="code-title">手机扫码预览</span>
          <i class="el-icon-close close-icon" @click="handleClose"></i>
        </div>
        <div class="mobile-qrCode-container">
          <div class="qr-image__wrap">
            <vue-qr
              :correct-level="3"
              :auto-color="false"
              color-dark="#000000"
              background-color="#ffffff"
              :text="codeUrl"
              :size="238"
              :margin="16"
              :logo-margin="10"
              :logo-corner-radius="0"
              :logo-scale="0.12"
              class="qr-code"
            ></vue-qr>
          </div>
          <span class="code-tip">请扫码在手机查看表单详情</span>
        </div>
      </div>
    </div>
    <ht-divider />
    <div v-if="isMobile" class="mobile-form__container">
      <ht-online-form
        ref="flowOnlineForm"
        :html="innerHtml"
        :data="data"
        :permission="permission"
        :mobile-mode="isMobile"
        :extend-prop="extendProp"
        :def-id="defId"
        isPreview
      />
    </div>
    <div class="preview-form-container" v-else ref="previewForm">
      <ht-online-form
        ref="flowOnlineForm"
        :html="innerHtml"
        :data="data"
        :permission="permission"
        :extend-prop="extendProp"
        :def-id="defId"
      />
    </div>
    <el-dialog
      class="data-show__dialog"
      :visible.sync="dataShow"
      title="表单数据"
    >
      <codemirror v-model="dataStr" :options="dataStyle"></codemirror>
      <el-footer>
        <el-button size="small" @click="dataShow = false">关闭</el-button>
        <el-button type="primary" size="small" @click="handleCopyData"
          >复制</el-button
        >
      </el-footer>
    </el-dialog>
  </div>
</template>
<script>
import form from '@/api/form.js'
import req from '@/utils/req'
import VueQr from 'vue-qr'
import {mapState} from 'vuex'
export default {
  name: 'FormPreview',
  components: {
    VueQr
  },
  props: {
    formId: String
  },
  data() {
    return {
      innerHtml: null,
      data: null,
      permission: null,
      validate: false,
      dataShow: false,
      dataStyle: {
        value: '',
        mode: 'javascript',
        readOnly: true,
        smartIndent: true,
        tabSize: 2,
        theme: 'base16-light',
        lineNumbers: true,
        line: true
      },
      flag: 0,
      extendProp: {
        initFillData: true // 子表默认预览时初始化
      },
      formCss: '',
      defId: '',
      isShowCode: false
    }
  },
  computed: {
    ...mapState('login', ['currentUser']),
    codeUrl() {
      return `${window.context.mobile}/formDetail/${this.formId}?token=${this.currentUser.token}`
    },
    dataStr: {
      get() {
        return JSON.stringify(this.data, null, '\t')
      },
      set(newVal) {
        this.data = typeof newVal === 'string' ? JSON.parse(newVal) : newVal
        return JSON.stringify(this.data, null, '\t')
      }
    },
    isMobile() {
      return (
        this.$route.query.mobile === true || this.$route.query.mobile === 'true'
      )
    }
  },
  mounted() {
    this.$http = req
    this.getFormById()
    this.$nextTick(() => {
      this.$refs.previewForm &&
        this.$refs.previewForm.addEventListener(
          'scroll',
          this.setScrollTop,
          true
        )
    })
  },
  methods: {
    handleScanPreview() {
      this.isShowCode = true
    },
    handleClose() {
      this.isShowCode = false
    },
    setScrollTop() {
      if (this.$refs.previewForm.scrollTop && this.flag < 1) {
        this.$refs.previewForm.scrollTop = 0
      }
      this.flag += 1
    },
    getFormById() {
      if (!this.formId) {
        return
      }
      form[
        this.formId.indexOf('_') > -1 ? 'previewDesignTemp' : 'previewDesignVue'
      ](this.formId).then(resp => {
        const {bpmForm, data, permission} = resp.data
        this.innerHtml = bpmForm.formHtml
        this.formCss = bpmForm.formCss
        this.data = data
        this.permission = permission
        this.defId = bpmForm.defId
        bpmForm.diyJs && this.handlerJs(bpmForm.diyJs)
        this.$nextTick(() => {
          if (this.formCss) {
            let style = document.createElement('style')
            style.id = 'online-form-addStyle'
            style.type = 'text/css'
            style.innerHTML = `div[name='online-form'] ${this.formCss}`
            document.head.appendChild(style)
          }
        })
      })
    },
    handlerJs(diyJs) {
      this.$nextTick(() => {
        const currentUser = this.$store.state.login.currentUser
        let data = this.data
        let _this = this
        const $ = require('jquery')
        eval(diyJs)
      })
    },
    handleShowData() {
      this.$refs.flowOnlineForm.getData(this.validate).then(resp => {
        resp && (this.dataShow = true)
      })
    },
    handleCopyData() {
      this.$copyText(this.dataStr).then(() => {
        this.$message.success('复制成功')
        this.dataShow = false
      })
    }
  },
  beforeDestroy() {
    document
      .getElementsByTagName('head')
      .item(0)
      .removeChild(document.getElementById('online-form-addStyle'))
  }
}
</script>
<style lang="scss" scoped>
//表单中子表孙表顶部信息背景颜色
$base-form-table-header-bg-color: #eef2fb;
//表单中子表孙表标题颜色
$base-form-table-header-title-color: #333;
.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  h3 {
    margin: 0;
  }
  .preview-header__left {
    display: flex;
    align-items: center;
    .scan-code__btn {
      border-color: #409eff;
      color: #409eff;
    }
  }
  .qrCode-wrap {
    position: absolute;
    top: 40px;
    right: 0;
    width: 460px;
    height: 380px;
    background: #ffffff;
    box-shadow: 0px 0px 8px 1px rgba(97, 97, 97, 0.16);
    border-radius: 8px 8px;
    z-index: 9;
    .code-header {
      height: 56px;
      padding: 0 24px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .code-title {
        color: #262626;
        font-size: 16px;
        font-weight: 500;
      }
      .close-icon {
        font-size: 16px;
        color: #8c8c8c;
        cursor: pointer;
      }
    }
    .mobile-qrCode-container {
      display: flex;
      flex-direction: column;
      justify-content: center;
      text-align: center;
      padding-top: 25px;
      .code-tip {
        color: #262626;
        font-size: 14px;
      }
      .qr-image__wrap {
        padding-bottom: 17px;
      }
      .qr-code {
        width: 238px;
        height: 238px;
        border: 1px solid #f5f5f5;
      }
    }
  }
}
.form-container {
  background: #fff;
  padding: 20px;
  height: calc(100% - 40px);
  overflow: auto;

  .mobile-form__container {
    background: url('../../assets/img/mobile-android.png') no-repeat center
      center;
    background-size: calc(100% + 36px) calc(100% + 60px);
    width: 360px;
    height: 720px;
    padding: 16px;
    overflow: auto;
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -180px;
    margin-top: -400px;
    border: 20px solid transparent;
    border-width: 30px 20px 36px 20px;

    scrollbar-width: 0;
    -ms-overflow-style: none;
    &::-webkit-scrollbar {
      width: 0;
    }
    ::v-deep {
      .sub-div-mobile {
        .formT_box {
          .el-collapse-item__content {
            .form-table {
              .el-row {
                // width: calc(100% - 120px);
              }
            }
          }
        }
      }
      .sub-div-title-mobile {
        overflow: hidden;
        width: 200px;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
      .sun-record-title-mobile {
        span {
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          width: 100px;
          display: block;
        }
      }
      .mobile-ht-form-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0;
        border-bottom: 1px solid #ebeef5;

        .el-form-item__label {
          width: 120px;
          position: unset !important;
          transform: unset !important;
          display: flex;
          align-items: center;
        }
        .el-form-item__content {
          flex: 1;
          margin-left: 0 !important;
          .mobile-number-location {
            align-items: center;
          }

          .ht-mobile-relevant__flow {
            .header-btn {
              top: 0px;
            }
          }
          .mobile-field-tail__wrap .el-form-item__error {
            bottom: -3px;
          }
        }
        .mobile-upload {
          top: -84px;
        }
        .has-value-input {
          .mobile-upload {
            top: -60px;
          }
        }
        .mobile-number-wrap {
          .mobile-number-input {
            display: flex;
            align-items: center;
          }
        }
        .ht-mobile-signature-wrap .btn_wrap {
          top: -48px;
        }
      }
      .ht-form-item-top-label {
        flex-direction: column;
      }
      .mobile-map-form-item,
      .mobile-relevant-flow__form-item,
      .mobile-qrcode-form-item,
      .mobile-opinion-form-item,
      .mobile-textarea-form-item {
        display: block;
      }
      .mobile-map-form-item,
      .mobile-relevant-flow__form-item {
        .el-form-item__content {
          margin-left: 120px !important;
        }
      }
      .mobile-step {
        .el-step__head .el-step__line {
          top: 7px;
        }
      }
    }
  }
  ::v-deep {
    .el-row--flex.is-align-top {
      align-items: unset;
    }
    .clear-all-btn,
    .copy-btn,
    .delete-btn,
    .custom-dialog-btn,
    .add-btn {
      font-size: 14px;
      i {
        font-size: 16px;
      }
    }
    .custom-dialog-btn {
      padding: 0 10px;
    }
   
    .form-table__container {
      .sun-table__title {
        height: 40px !important;
        line-height: 40px !important;
        background: $base-form-table-header-bg-color !important;
        font-size: 16px;
        margin: 0 12px;
        padding: 0 16px;
        border: 1px solid #ebebeb;
        color: $base-form-table-header-title-color;
        font-weight: bold;
        text-align: left;
      }
      .sun-table_main {
        padding: 0 12px;
      }
      .form-table-header {
        height: 40px;
        line-height: 40px;
        // background: #f9f9f9;
        font-size: 16px;
        // margin: 0 12px;
        // padding: 0 16px;

        // border: 1px solid #dcdee0;
        .sub-table__title {
          color: $base-form-table-header-title-color;
          font-weight: bold;
        }
      }
      .el-table__footer-wrapper tbody td.el-table__cell{
        background: #f9f9f9;
      }

      .el-table {
        &::before {
          height: 0;
        }
        .el-table__fixed,
        .el-table__fixed-right {
          &::before {
            height: 0;
          }
        }
        .el-table__header-wrapper,
        .el-table__fixed-header-wrapper {
          th {
            background: var(--headerBgColor);
            padding: 12px 0;
            .cell {
              color: #333;
              font-size: 14px;
              font-weight: bold;
            }
          }
        }
        .el-table__empty-block {
          display: none;
        }
      }
      .table-footer {
        height: 56px;
        line-height: 56px;
        border: 1px solid #ebebeb;
        border-top: none;
        padding: 0 20px;
        .add-btn {
          font-weight: 500;
        }
      }
      .pagination-wrap {
        display: flex;
        justify-content: flex-end;
        padding: 16px 36px;
      }
      // 孙表表格样式跟子表统一
      .form-table thead .sub-table-header th {
        background: #f4f4f4;
        padding: 12px 0;
        color: #333;
        font-size: 14px;
        font-weight: bold;
        .table-header__cell,
        .table-header__cell span {
          color: #333;
          font-size: 14px;
          font-weight: bold;
        }
      }
      .sun-div-container {
        .el-header {
          text-align: left;
        }
        .sun-collapse-item-title {
          display: flex;
          padding-right: 16px;
          width: 100%;
          justify-content: space-between;
        }
      }
      .field-tail__wrap {
        .el-form-item__error {
          position: static;
        }
      }
    }
    //子表附件位置
    .el-table {
      .file-list__wrap .file-item {
        width: 100%;
        .file__name {
          text-align: left;
        }
      }
    }
    .el-row {
      .el-col {
        &:last-child {
          margin-right: 0 !important;
        }
      }
    }
  }
  ::v-deep.w-e-toolbar {
    z-index: 2 !important;
  }
}
.data-show__dialog ::v-deep {
  .el-dialog__body {
    padding: 20px;

    .el-footer {
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
}

.preview-form-container{
   ::v-deep {
      .table_layout_wrap {
        .main-table {
          margin-bottom: 0;
          .main-title {
            padding: 0 8px !important;
          }
        }
      }
    }
}
</style>
<style lang="scss">
.van-popup {
  height: 60vh !important;
  .mobile-sunpop-content {
    height: calc(60vh - 120px);
  }
}
</style>