TemplateManage.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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: 120px;"
  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="备注">
  86. <span slot-scope="scope">{{
  87. scope.row.remark | defaultFieldFilter
  88. }}</span>
  89. </el-table-column>
  90. <el-table-column prop="enable" label="启用/禁用" width="100">
  91. <template slot-scope="scope">
  92. {{ scope.row.enable | enableFilter }}
  93. </template>
  94. </el-table-column>
  95. <el-table-column prop="createTime" label="创建时间" width="180">
  96. <span slot-scope="scope">{{
  97. scope.row.createTime | timestampFilter
  98. }}</span>
  99. </el-table-column>
  100. <el-table-column class-name="action-column" label="操作" width="160">
  101. <template slot-scope="scope">
  102. <el-button
  103. v-if="checkPrivilege('link', 'preview')"
  104. class="btn-primary"
  105. type="text"
  106. @click="toDetail(scope.row)"
  107. >查看</el-button
  108. >
  109. <el-button
  110. v-if="checkPrivilege('link', 'edit')"
  111. class="btn-primary"
  112. type="text"
  113. @click="toEdit(scope.row)"
  114. >编辑</el-button
  115. >
  116. <el-button
  117. v-if="checkPrivilege('link', 'enable')"
  118. :class="scope.row.enable ? 'btn-danger' : 'btn-primary'"
  119. type="text"
  120. @click="toEnable(scope.row)"
  121. >{{ scope.row.enable ? "禁用" : "启用" }}</el-button
  122. >
  123. </template>
  124. </el-table-column>
  125. </el-table>
  126. <div class="part-page">
  127. <el-pagination
  128. background
  129. layout="total,prev, pager, next"
  130. :current-page="current"
  131. :total="total"
  132. :page-size="size"
  133. @current-change="toPage"
  134. >
  135. </el-pagination>
  136. </div>
  137. </div>
  138. <!-- ModifyTemplate -->
  139. <modify-template
  140. ref="ModifyTemplate"
  141. :instance="curTemplate"
  142. :edit-type="editType"
  143. :template-type="templateType"
  144. @modified="getList"
  145. ></modify-template>
  146. <!-- template-detail -->
  147. <el-dialog
  148. :visible.sync="templateDetailDialogIsShow"
  149. title="印品模板"
  150. width="1200px"
  151. top="10px"
  152. :close-on-click-modal="false"
  153. :close-on-press-escape="false"
  154. append-to-body
  155. >
  156. <div id="template-frame"></div>
  157. <div slot="footer"></div>
  158. </el-dialog>
  159. </div>
  160. </template>
  161. <script>
  162. import { ABLE_TYPE, TEMPLATE_TYPE } from "@/constants/enumerate";
  163. import pickerOptions from "@/constants/datePickerOptions";
  164. import { templateListPage, ableTemplate, templateContentView } from "../api";
  165. import ModifyTemplate from "../components/ModifyTemplate";
  166. export default {
  167. name: "template-manage",
  168. components: {
  169. ModifyTemplate
  170. },
  171. props: {
  172. templateType: {
  173. type: String,
  174. default: "GENERIC",
  175. validator(val) {
  176. return Object.keys(TEMPLATE_TYPE).indexOf(val) !== -1;
  177. }
  178. }
  179. },
  180. data() {
  181. return {
  182. filter: {
  183. enable: null,
  184. name: "",
  185. startTime: "",
  186. endTime: ""
  187. },
  188. current: 1,
  189. size: this.GLOBAL.pageSize,
  190. total: 0,
  191. templates: [],
  192. curTemplate: {},
  193. editType: "ADD",
  194. ABLE_TYPE,
  195. templateDetailDialogIsShow: false,
  196. // date-picker
  197. createTime: [],
  198. pickerOptions
  199. };
  200. },
  201. mounted() {
  202. this.getList();
  203. },
  204. methods: {
  205. async getList() {
  206. if (!this.checkPrivilege("list", "list")) return;
  207. const datas = {
  208. ...this.filter,
  209. type: this.templateType,
  210. pageNumber: this.current,
  211. pageSize: this.size
  212. };
  213. if (this.createTime) {
  214. datas.startTime = this.createTime[0];
  215. datas.endTime = this.createTime[1];
  216. }
  217. if (datas.enable !== null && datas.enable !== "")
  218. datas.enable = !!datas.enable;
  219. const data = await templateListPage(datas);
  220. this.templates = data.records;
  221. this.total = data.total;
  222. },
  223. toPage(page) {
  224. this.current = page;
  225. this.getList();
  226. },
  227. toAdd() {
  228. this.curTemplate = { type: this.templateType };
  229. this.editType = "ADD";
  230. this.$refs.ModifyTemplate.open();
  231. },
  232. toEdit(row) {
  233. this.curTemplate = { ...row, type: this.templateType };
  234. this.editType = "EDIT";
  235. this.$refs.ModifyTemplate.open();
  236. },
  237. async toDetail(row) {
  238. if (this.templateType === "GENERIC") {
  239. window.open(
  240. this.getRouterPath({
  241. name: "CardPreview",
  242. params: {
  243. cardId: row.cardId,
  244. viewType: "view"
  245. }
  246. })
  247. );
  248. return;
  249. }
  250. const content = await templateContentView(row.attachmentId);
  251. if (!content) return;
  252. this.templateDetailDialogIsShow = true;
  253. this.$nextTick(() => {
  254. this.initFrame(content);
  255. });
  256. },
  257. initFrame(htmlContent) {
  258. // 移除framemark标签
  259. // htmlContent = htmlContent
  260. // .replace(/\$\{.+?\}/g, "")
  261. // .replace(/<#.+?>/g, "")
  262. // .replace(/<\/#.+?>/g, "");
  263. const frameContainerDom = document.getElementById("template-frame");
  264. frameContainerDom.innerHTML = "";
  265. const iframeDom = document.createElement("iframe");
  266. frameContainerDom.appendChild(iframeDom);
  267. console.dir(frameContainerDom);
  268. const wwidth = frameContainerDom.parentNode.clientWidth - 50;
  269. const wheight = window.innerHeight - 130;
  270. iframeDom.style.cssText = `width: ${wwidth}px;height: ${wheight}px;border:none;outline:none;background-color: #fff;`;
  271. const iframeDoc = iframeDom.contentDocument;
  272. iframeDoc.open();
  273. iframeDoc.write(htmlContent);
  274. iframeDoc.close();
  275. },
  276. toEnable(row) {
  277. const action = row.enable ? "禁用" : "启用";
  278. this.$confirm(`确定要${action}模板【${row.name}】吗?`, "提示", {
  279. type: "warning"
  280. })
  281. .then(async () => {
  282. const enable = !row.enable;
  283. await ableTemplate({
  284. id: row.id,
  285. enable
  286. });
  287. row.enable = enable;
  288. this.$message.success("操作成功!");
  289. })
  290. .catch(() => {});
  291. }
  292. }
  293. };
  294. </script>