123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- <template>
- <div class="template-manage">
- <div class="part-box part-box-filter part-box-flex">
- <el-form ref="FilterForm" label-position="left" label-width="85px" inline>
- <template v-if="checkPrivilege('condition', 'condition')">
- <el-form-item label="模板名称:">
- <el-input
- v-model.trim="filter.name"
- placeholder="模板名称"
- clearable
- ></el-input>
- </el-form-item>
- <el-form-item label="创建时间:">
- <el-date-picker
- v-model="createTime"
- type="datetimerange"
- :picker-options="pickerOptions"
- range-separator="至"
- start-placeholder="创建开始时间"
- end-placeholder="创建结束时间"
- value-format="timestamp"
- align="right"
- unlink-panels
- >
- </el-date-picker>
- </el-form-item>
- <el-form-item label="启用/禁用:" label-width="90px">
- <el-select
- v-model="filter.enable"
- style="width: 110px;"
- placeholder="启用/禁用"
- clearable
- >
- <el-option
- v-for="(val, key) in ABLE_TYPE"
- :key="key"
- :value="key * 1"
- :label="val"
- ></el-option>
- </el-select>
- </el-form-item>
- </template>
- <el-form-item>
- <el-button
- v-if="checkPrivilege('button', 'select')"
- type="primary"
- @click="toPage(1)"
- >查询</el-button
- >
- </el-form-item>
- </el-form>
- <div class="part-box-action">
- <el-button
- v-if="checkPrivilege('button', 'add')"
- type="primary"
- icon="el-icon-circle-plus-outline"
- @click="toAdd"
- >添加模板</el-button
- >
- </div>
- </div>
- <div class="part-box part-box-pad">
- <el-table ref="TableList" :data="templates">
- <el-table-column
- type="index"
- label="序号"
- width="70"
- :index="indexMethod"
- ></el-table-column>
- <el-table-column prop="name" label="模板名称"></el-table-column>
- <el-table-column
- prop="classify"
- label="分类"
- v-if="templateType !== 'GENERIC'"
- >
- <template slot-scope="scope">
- {{ scope.row.classify | templateClassifyFilter }}
- </template>
- </el-table-column>
- <el-table-column prop="orgs" label="适用学院">
- <template slot-scope="scope">
- {{ scope.row.orgs | orgsFilter }}
- </template>
- </el-table-column>
- <el-table-column prop="remark" label="备注"></el-table-column>
- <el-table-column prop="enable" label="启用/禁用" width="100">
- <template slot-scope="scope">
- {{ scope.row.enable | enableFilter }}
- </template>
- </el-table-column>
- <el-table-column prop="createTime" label="创建时间" width="180">
- <span slot-scope="scope">{{
- scope.row.createTime | timestampFilter
- }}</span>
- </el-table-column>
- <el-table-column class-name="action-column" label="操作" width="160">
- <template slot-scope="scope">
- <el-button
- v-if="checkPrivilege('link', 'preview')"
- class="btn-primary"
- type="text"
- @click="toDetail(scope.row)"
- >查看</el-button
- >
- <el-button
- v-if="checkPrivilege('link', 'edit')"
- class="btn-primary"
- type="text"
- @click="toEdit(scope.row)"
- >编辑</el-button
- >
- <el-button
- v-if="checkPrivilege('link', 'enable')"
- :class="scope.row.enable ? 'btn-danger' : 'btn-primary'"
- type="text"
- @click="toEnable(scope.row)"
- >{{ scope.row.enable ? "禁用" : "启用" }}</el-button
- >
- </template>
- </el-table-column>
- </el-table>
- <div class="part-page">
- <el-pagination
- background
- layout="total,prev, pager, next"
- :current-page="current"
- :total="total"
- :page-size="size"
- @current-change="toPage"
- >
- </el-pagination>
- </div>
- </div>
- <!-- ModifyTemplate -->
- <modify-template
- ref="ModifyTemplate"
- :instance="curTemplate"
- :edit-type="editType"
- :template-type="templateType"
- @modified="getList"
- ></modify-template>
- <!-- template-detail -->
- <el-dialog
- :visible.sync="templateDetailDialogIsShow"
- title="印品模板"
- width="1200px"
- top="10px"
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- append-to-body
- >
- <div id="template-frame"></div>
- <div slot="footer"></div>
- </el-dialog>
- </div>
- </template>
- <script>
- import { ABLE_TYPE, TEMPLATE_TYPE } from "@/constants/enumerate";
- import pickerOptions from "@/constants/datePickerOptions";
- import { templateListPage, ableTemplate, templateContentView } from "../api";
- import ModifyTemplate from "../components/ModifyTemplate";
- export default {
- name: "template-manage",
- components: {
- ModifyTemplate
- },
- props: {
- templateType: {
- type: String,
- default: "GENERIC",
- validator(val) {
- return Object.keys(TEMPLATE_TYPE).indexOf(val) !== -1;
- }
- }
- },
- data() {
- return {
- filter: {
- enable: null,
- name: "",
- startTime: "",
- endTime: ""
- },
- current: 1,
- size: this.GLOBAL.pageSize,
- total: 0,
- templates: [],
- curTemplate: {},
- editType: "ADD",
- ABLE_TYPE,
- templateDetailDialogIsShow: false,
- // date-picker
- createTime: [],
- pickerOptions
- };
- },
- mounted() {
- this.getList();
- },
- methods: {
- async getList() {
- if (!this.checkPrivilege("list", "list")) return;
- const datas = {
- ...this.filter,
- type: this.templateType,
- pageNumber: this.current,
- pageSize: this.size
- };
- if (this.createTime) {
- datas.startTime = this.createTime[0];
- datas.endTime = this.createTime[1];
- }
- if (datas.enable !== null && datas.enable !== "")
- datas.enable = !!datas.enable;
- const data = await templateListPage(datas);
- this.templates = data.records;
- this.total = data.total;
- },
- toPage(page) {
- this.current = page;
- this.getList();
- },
- toAdd() {
- this.curTemplate = { type: this.templateType };
- this.editType = "ADD";
- this.$refs.ModifyTemplate.open();
- },
- toEdit(row) {
- this.curTemplate = { ...row, type: this.templateType };
- this.editType = "EDIT";
- this.$refs.ModifyTemplate.open();
- },
- async toDetail(row) {
- if (this.templateType === "GENERIC") {
- window.open(
- this.getRouterPath({
- name: "CardPreview",
- params: {
- cardId: row.cardId,
- viewType: "view"
- }
- })
- );
- return;
- }
- const content = await templateContentView(row.attachmentId);
- if (!content) return;
- this.templateDetailDialogIsShow = true;
- this.$nextTick(() => {
- this.initFrame(content);
- });
- },
- initFrame(htmlContent) {
- // 移除framemark标签
- // htmlContent = htmlContent
- // .replace(/\$\{.+?\}/g, "")
- // .replace(/<#.+?>/g, "")
- // .replace(/<\/#.+?>/g, "");
- const frameContainerDom = document.getElementById("template-frame");
- frameContainerDom.innerHTML = "";
- const iframeDom = document.createElement("iframe");
- frameContainerDom.appendChild(iframeDom);
- console.dir(frameContainerDom);
- const wwidth = frameContainerDom.parentNode.clientWidth - 50;
- const wheight = window.innerHeight - 130;
- iframeDom.style.cssText = `width: ${wwidth}px;height: ${wheight}px;border:none;outline:none;background-color: #fff;`;
- const iframeDoc = iframeDom.contentDocument;
- iframeDoc.open();
- iframeDoc.write(htmlContent);
- iframeDoc.close();
- },
- toEnable(row) {
- const action = row.enable ? "禁用" : "启用";
- this.$confirm(`确定要${action}模板【${row.name}】吗?`, "提示", {
- type: "warning"
- })
- .then(async () => {
- const enable = !row.enable;
- await ableTemplate({
- id: row.id,
- enable
- });
- row.enable = enable;
- this.$message.success("操作成功!");
- })
- .catch(() => {});
- }
- }
- };
- </script>
|