TemplateManage.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <div class="template-manage">
  3. <div class="part-box part-box-filter part-box-flex">
  4. <el-form ref="FilterForm" label-position="left" label-width="85px" inline>
  5. <template v-if="checkPrivilege('condition', 'condition')">
  6. <el-form-item label="模板名称:">
  7. <el-input
  8. v-model.trim="filter.name"
  9. placeholder="模板名称"
  10. clearable
  11. ></el-input>
  12. </el-form-item>
  13. <el-form-item label="创建时间:">
  14. <el-date-picker
  15. v-model="createTime"
  16. type="datetimerange"
  17. :picker-options="pickerOptions"
  18. range-separator="至"
  19. start-placeholder="创建开始时间"
  20. end-placeholder="创建结束时间"
  21. value-format="timestamp"
  22. align="right"
  23. unlink-panels
  24. >
  25. </el-date-picker>
  26. </el-form-item>
  27. <el-form-item label="启用/禁用:" label-width="90px">
  28. <el-select
  29. v-model="filter.enable"
  30. style="width: 110px;"
  31. placeholder="启用/禁用"
  32. clearable
  33. >
  34. <el-option
  35. v-for="(val, key) in ABLE_TYPE"
  36. :key="key"
  37. :value="key * 1"
  38. :label="val"
  39. ></el-option>
  40. </el-select>
  41. </el-form-item>
  42. </template>
  43. <el-form-item>
  44. <el-button
  45. v-if="checkPrivilege('button', 'select')"
  46. type="primary"
  47. @click="toPage(1)"
  48. >查询</el-button
  49. >
  50. </el-form-item>
  51. </el-form>
  52. <div class="part-box-action">
  53. <el-button
  54. v-if="checkPrivilege('button', 'add')"
  55. type="primary"
  56. icon="el-icon-circle-plus-outline"
  57. @click="toAdd"
  58. >添加模板</el-button
  59. >
  60. </div>
  61. </div>
  62. <div class="part-box part-box-pad">
  63. <el-table ref="TableList" :data="templates">
  64. <el-table-column
  65. type="index"
  66. label="序号"
  67. width="70"
  68. :index="indexMethod"
  69. ></el-table-column>
  70. <el-table-column prop="name" label="模板名称"></el-table-column>
  71. <el-table-column
  72. prop="classify"
  73. label="分类"
  74. v-if="templateType !== 'GENERIC'"
  75. >
  76. <template slot-scope="scope">
  77. {{ scope.row.classify | templateClassifyFilter }}
  78. </template>
  79. </el-table-column>
  80. <el-table-column prop="orgs" label="适用学院">
  81. <template slot-scope="scope">
  82. {{ scope.row.orgs | orgsFilter }}
  83. </template>
  84. </el-table-column>
  85. <el-table-column prop="remark" label="备注"></el-table-column>
  86. <el-table-column prop="enable" label="启用/禁用" width="100">
  87. <template slot-scope="scope">
  88. {{ scope.row.enable | enableFilter }}
  89. </template>
  90. </el-table-column>
  91. <el-table-column prop="createTime" label="创建时间" width="180">
  92. <span slot-scope="scope">{{
  93. scope.row.createTime | timestampFilter
  94. }}</span>
  95. </el-table-column>
  96. <el-table-column class-name="action-column" label="操作" width="160">
  97. <template slot-scope="scope">
  98. <el-button
  99. v-if="checkPrivilege('link', 'preview')"
  100. class="btn-primary"
  101. type="text"
  102. @click="toDetail(scope.row)"
  103. >查看</el-button
  104. >
  105. <el-button
  106. v-if="checkPrivilege('link', 'edit')"
  107. class="btn-primary"
  108. type="text"
  109. @click="toEdit(scope.row)"
  110. >编辑</el-button
  111. >
  112. <el-button
  113. v-if="checkPrivilege('link', 'enable')"
  114. :class="scope.row.enable ? 'btn-danger' : 'btn-primary'"
  115. type="text"
  116. @click="toEnable(scope.row)"
  117. >{{ scope.row.enable ? "禁用" : "启用" }}</el-button
  118. >
  119. </template>
  120. </el-table-column>
  121. </el-table>
  122. <div class="part-page">
  123. <el-pagination
  124. background
  125. layout="total,prev, pager, next"
  126. :current-page="current"
  127. :total="total"
  128. :page-size="size"
  129. @current-change="toPage"
  130. >
  131. </el-pagination>
  132. </div>
  133. </div>
  134. <!-- ModifyTemplate -->
  135. <modify-template
  136. ref="ModifyTemplate"
  137. :instance="curTemplate"
  138. :edit-type="editType"
  139. :template-type="templateType"
  140. @modified="getList"
  141. ></modify-template>
  142. <!-- template-detail -->
  143. <el-dialog
  144. :visible.sync="templateDetailDialogIsShow"
  145. title="印品模板"
  146. width="1200px"
  147. top="10px"
  148. :close-on-click-modal="false"
  149. :close-on-press-escape="false"
  150. append-to-body
  151. >
  152. <div id="template-frame"></div>
  153. <div slot="footer"></div>
  154. </el-dialog>
  155. </div>
  156. </template>
  157. <script>
  158. import { ABLE_TYPE, TEMPLATE_TYPE } from "@/constants/enumerate";
  159. import pickerOptions from "@/constants/datePickerOptions";
  160. import { templateListPage, ableTemplate, templateContentView } from "../api";
  161. import ModifyTemplate from "../components/ModifyTemplate";
  162. export default {
  163. name: "template-manage",
  164. components: {
  165. ModifyTemplate
  166. },
  167. props: {
  168. templateType: {
  169. type: String,
  170. default: "GENERIC",
  171. validator(val) {
  172. return Object.keys(TEMPLATE_TYPE).indexOf(val) !== -1;
  173. }
  174. }
  175. },
  176. data() {
  177. return {
  178. filter: {
  179. enable: null,
  180. name: "",
  181. startTime: "",
  182. endTime: ""
  183. },
  184. current: 1,
  185. size: this.GLOBAL.pageSize,
  186. total: 0,
  187. templates: [],
  188. curTemplate: {},
  189. editType: "ADD",
  190. ABLE_TYPE,
  191. templateDetailDialogIsShow: false,
  192. // date-picker
  193. createTime: [],
  194. pickerOptions
  195. };
  196. },
  197. mounted() {
  198. this.getList();
  199. },
  200. methods: {
  201. async getList() {
  202. if (!this.checkPrivilege("list", "list")) return;
  203. const datas = {
  204. ...this.filter,
  205. type: this.templateType,
  206. pageNumber: this.current,
  207. pageSize: this.size
  208. };
  209. if (this.createTime) {
  210. datas.startTime = this.createTime[0];
  211. datas.endTime = this.createTime[1];
  212. }
  213. if (datas.enable !== null && datas.enable !== "")
  214. datas.enable = !!datas.enable;
  215. const data = await templateListPage(datas);
  216. this.templates = data.records;
  217. this.total = data.total;
  218. },
  219. toPage(page) {
  220. this.current = page;
  221. this.getList();
  222. },
  223. toAdd() {
  224. this.curTemplate = { type: this.templateType };
  225. this.editType = "ADD";
  226. this.$refs.ModifyTemplate.open();
  227. },
  228. toEdit(row) {
  229. this.curTemplate = { ...row, type: this.templateType };
  230. this.editType = "EDIT";
  231. this.$refs.ModifyTemplate.open();
  232. },
  233. async toDetail(row) {
  234. if (this.templateType === "GENERIC") {
  235. window.open(
  236. this.getRouterPath({
  237. name: "CardPreview",
  238. params: {
  239. cardId: row.cardId,
  240. viewType: "view"
  241. }
  242. })
  243. );
  244. return;
  245. }
  246. const content = await templateContentView(row.attachmentId);
  247. if (!content) return;
  248. this.templateDetailDialogIsShow = true;
  249. this.$nextTick(() => {
  250. this.initFrame(content);
  251. });
  252. },
  253. initFrame(htmlContent) {
  254. // 移除framemark标签
  255. // htmlContent = htmlContent
  256. // .replace(/\$\{.+?\}/g, "")
  257. // .replace(/<#.+?>/g, "")
  258. // .replace(/<\/#.+?>/g, "");
  259. const frameContainerDom = document.getElementById("template-frame");
  260. frameContainerDom.innerHTML = "";
  261. const iframeDom = document.createElement("iframe");
  262. frameContainerDom.appendChild(iframeDom);
  263. console.dir(frameContainerDom);
  264. const wwidth = frameContainerDom.parentNode.clientWidth - 50;
  265. const wheight = window.innerHeight - 130;
  266. iframeDom.style.cssText = `width: ${wwidth}px;height: ${wheight}px;border:none;outline:none;background-color: #fff;`;
  267. const iframeDoc = iframeDom.contentDocument;
  268. iframeDoc.open();
  269. iframeDoc.write(htmlContent);
  270. iframeDoc.close();
  271. },
  272. toEnable(row) {
  273. const action = row.enable ? "禁用" : "启用";
  274. this.$confirm(`确定要${action}模板【${row.name}】吗?`, "提示", {
  275. type: "warning"
  276. })
  277. .then(async () => {
  278. const enable = !row.enable;
  279. await ableTemplate({
  280. id: row.id,
  281. enable
  282. });
  283. row.enable = enable;
  284. this.$message.success("操作成功!");
  285. })
  286. .catch(() => {});
  287. }
  288. }
  289. };
  290. </script>