TemplateManage.vue 8.7 KB

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