regular-template-list.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. <template>
  2. <view class="page-no-tab">
  3. <uni-nav-bar
  4. fixed="true"
  5. statusBar="true"
  6. left-icon="back"
  7. title="模板管理"
  8. background-color="#157A2C"
  9. color="#fff"
  10. @clickLeft="back"
  11. ></uni-nav-bar>
  12. <view class="tabs">
  13. <view
  14. v-for="item in TEMPLATE_STATUS_FILTERS"
  15. :key="item.value"
  16. class="tab press"
  17. :class="{ active: active === item.value }"
  18. @click="active = item.value"
  19. >{{ item.label }}<text class="tab-count">{{ countStatus(item.value) }}</text></view>
  20. </view>
  21. <view class="filters">
  22. <view class="search-row">
  23. <input
  24. v-model.trim="keyword"
  25. class="search-input"
  26. type="text"
  27. confirm-type="search"
  28. placeholder="模板名称 / 编码"
  29. />
  30. <text class="reset press" @click="resetFilters">重置</text>
  31. </view>
  32. </view>
  33. <view class="summary">
  34. <text>共 {{ list.length }} 个模板</text>
  35. <view class="summary-right">
  36. <text class="muted">{{ summaryTip }}</text>
  37. <text class="link press" @click="loadList">刷新</text>
  38. </view>
  39. </view>
  40. <view v-if="loading" class="empty">加载中…</view>
  41. <view v-else-if="list.length" class="list">
  42. <view
  43. v-for="item in list"
  44. :key="item.id"
  45. class="tpl-card card press"
  46. @click="openEdit(item)"
  47. >
  48. <view class="card-head">
  49. <view class="card-icon" :style="{ color: meta.color, background: meta.color + '18' }">模</view>
  50. <view class="card-title">
  51. <text>{{ item.templateName || '—' }}<text class="muted small"> {{ item.templateCode || '' }}</text></text>
  52. <text>分类 {{ item.categoryId || '—' }} · 当前版本 V{{ item.currentVersionNo || 1 }}</text>
  53. </view>
  54. <text class="status-tag" :class="item.enabled ? 'status-approved' : 'status-pending'">
  55. {{ item.templateStatusLabel }}
  56. </text>
  57. </view>
  58. <view v-if="item.remark" class="card-tip">{{ item.remark }}</view>
  59. <view class="card-meta">
  60. <view><text>变量个数</text><text>{{ variableCount(item) }}</text></view>
  61. <view><text>创建时间</text><text>{{ item.createTime || '—' }}</text></view>
  62. </view>
  63. <view class="card-actions">
  64. <text class="link" @click.stop="openPreview(item)">预览</text>
  65. <text class="link" @click.stop="openEdit(item)">编辑</text>
  66. <text class="link" @click.stop="openVersions(item)">版本历史</text>
  67. <text
  68. class="link"
  69. :class="{ danger: item.enabled }"
  70. @click.stop="onToggle(item)"
  71. >{{ item.enabled ? '停用' : '启用' }}</text>
  72. </view>
  73. </view>
  74. </view>
  75. <view v-else class="empty">
  76. <view>□</view>
  77. <text>{{ active === 'all' ? '暂无线上 Word 模板' : '该状态下暂无模板' }}</text>
  78. </view>
  79. <view class="bottom-action">
  80. <view class="primary-btn press" @click="openCreate">新增模板</view>
  81. </view>
  82. <view v-if="versionVisible" class="mask" @click="versionVisible = false">
  83. <view class="sheet" @click.stop>
  84. <view class="sheet-head">
  85. <text>{{ versionTitle }}</text>
  86. <text class="link" @click="versionVisible = false">关闭</text>
  87. </view>
  88. <view v-if="versionLoading" class="empty">加载中…</view>
  89. <scroll-view v-else scroll-y class="version-list">
  90. <view v-for="item in versions" :key="item.id" class="version-item">
  91. <text class="version-no">V{{ item.versionNo }}</text>
  92. <view class="version-main">
  93. <text>{{ item.changeRemark || '无变更说明' }}</text>
  94. <text class="muted small">{{ item.createTime || '—' }}</text>
  95. </view>
  96. <text class="muted small">{{ item.versionStatus || '' }}</text>
  97. </view>
  98. <view v-if="!versions.length" class="empty">暂无版本记录</view>
  99. </scroll-view>
  100. </view>
  101. </view>
  102. <view v-if="previewVisible" class="mask" @click="previewVisible = false">
  103. <view class="sheet" @click.stop>
  104. <view class="sheet-head">
  105. <text>{{ previewTitle }}</text>
  106. <text class="link" @click="previewVisible = false">关闭</text>
  107. </view>
  108. <view v-if="previewLoading" class="empty">加载中…</view>
  109. <scroll-view v-else scroll-y class="preview-body">
  110. <A4Preview :content="previewContent" />
  111. </scroll-view>
  112. </view>
  113. </view>
  114. </view>
  115. </template>
  116. <script>
  117. import A4Preview from "@/pages/hr/components/A4Preview.vue";
  118. import { applicationTypes } from "@/pages/hr/data/apply-config";
  119. import {
  120. TEMPLATE_STATUS_FILTERS,
  121. loadOnlineTemplateList,
  122. loadOnlineTemplateDetail,
  123. loadOnlineTemplateVersions,
  124. toggleOnlineTemplate,
  125. } from "@/api/hr/onlineDocument";
  126. export default {
  127. components: { A4Preview },
  128. data() {
  129. return {
  130. TEMPLATE_STATUS_FILTERS,
  131. active: "all",
  132. keyword: "",
  133. records: [],
  134. loading: false,
  135. versionVisible: false,
  136. versionLoading: false,
  137. versionTitle: "版本历史",
  138. versions: [],
  139. previewVisible: false,
  140. previewLoading: false,
  141. previewTitle: "画布预览",
  142. previewContent: "",
  143. };
  144. },
  145. computed: {
  146. meta() {
  147. return applicationTypes.regular || { title: "转正申请", color: "#269a99" };
  148. },
  149. list() {
  150. const k = this.keyword.toLowerCase();
  151. return this.records
  152. .filter((row) => this.active === "all" || row.templateStatus === this.active)
  153. .filter((row) => {
  154. if (!this.keyword) return true;
  155. const text = `${row.templateName}${row.templateCode}`.toLowerCase();
  156. return text.indexOf(k) >= 0;
  157. });
  158. },
  159. summaryTip() {
  160. return "数据来自 /hr/online-documents/templates";
  161. },
  162. },
  163. onShow() {
  164. this.loadList();
  165. },
  166. methods: {
  167. countStatus(status) {
  168. if (status === "all") return this.records.length;
  169. return this.records.filter((row) => row.templateStatus === status).length;
  170. },
  171. variableCount(item) {
  172. try {
  173. const parsed = JSON.parse(item.variablesJson || "[]");
  174. return Array.isArray(parsed) ? parsed.length : 0;
  175. } catch (error) {
  176. return 0;
  177. }
  178. },
  179. async loadList() {
  180. this.loading = true;
  181. try {
  182. const page = await loadOnlineTemplateList({});
  183. this.records = (page && page.list) || [];
  184. } catch (error) {
  185. this.records = [];
  186. uni.showToast({ title: (error && error.message) || "模板列表加载失败", icon: "none" });
  187. } finally {
  188. this.loading = false;
  189. }
  190. },
  191. resetFilters() {
  192. this.keyword = "";
  193. this.active = "all";
  194. },
  195. openCreate() {
  196. uni.navigateTo({ url: "/pages/hr/manage/regular-template-form" });
  197. },
  198. openEdit(item) {
  199. if (!item || !item.id) return;
  200. uni.navigateTo({ url: `/pages/hr/manage/regular-template-form?id=${item.id}` });
  201. },
  202. onToggle(item) {
  203. const label = item.enabled ? "停用" : "启用";
  204. uni.showModal({
  205. title: `${label}模板`,
  206. content: `确认${label}「${item.templateName || item.templateCode}」?`,
  207. success: async (r) => {
  208. if (!r.confirm) return;
  209. uni.showLoading({ title: "处理中..." });
  210. try {
  211. await toggleOnlineTemplate(item);
  212. uni.hideLoading();
  213. uni.showToast({ title: `${label}成功`, icon: "success" });
  214. await this.loadList();
  215. } catch (error) {
  216. uni.hideLoading();
  217. uni.showToast({ title: (error && error.message) || `${label}失败`, icon: "none" });
  218. }
  219. },
  220. });
  221. },
  222. async openVersions(item) {
  223. this.versionTitle = `${item.templateName || "模板"} · 版本历史`;
  224. this.versionVisible = true;
  225. this.versionLoading = true;
  226. this.versions = [];
  227. try {
  228. this.versions = await loadOnlineTemplateVersions(item.id);
  229. } catch (error) {
  230. uni.showToast({ title: (error && error.message) || "版本历史加载失败", icon: "none" });
  231. } finally {
  232. this.versionLoading = false;
  233. }
  234. },
  235. async openPreview(item) {
  236. this.previewTitle = `${item.templateName || "模板"} · 画布预览`;
  237. this.previewContent = "";
  238. this.previewVisible = true;
  239. this.previewLoading = true;
  240. try {
  241. // 列表接口不回传长正文,预览需要按主键取详情
  242. const row = await loadOnlineTemplateDetail(item.id, item);
  243. this.previewContent = (row && row.documentContent) || "";
  244. } catch (error) {
  245. uni.showToast({ title: (error && error.message) || "正文加载失败", icon: "none" });
  246. } finally {
  247. this.previewLoading = false;
  248. }
  249. },
  250. },
  251. };
  252. </script>
  253. <style scoped lang="scss">
  254. @import "@/pages/hr/common-style.scss";
  255. .page-no-tab {
  256. padding-bottom: 150rpx;
  257. }
  258. .tabs {
  259. display: flex;
  260. overflow-x: auto;
  261. background: #fff;
  262. border-bottom: 1rpx solid #edf0f2;
  263. }
  264. .tab {
  265. position: relative;
  266. flex: 1;
  267. min-width: 130rpx;
  268. height: 92rpx;
  269. display: flex;
  270. align-items: center;
  271. justify-content: center;
  272. color: #6f7782;
  273. font-size: 26rpx;
  274. white-space: nowrap;
  275. }
  276. .tab.active {
  277. color: #157a2c;
  278. font-weight: 500;
  279. }
  280. .tab.active:after {
  281. content: "";
  282. position: absolute;
  283. bottom: 0;
  284. width: 40rpx;
  285. height: 5rpx;
  286. border-radius: 3rpx;
  287. background: #157a2c;
  288. }
  289. .tab-count {
  290. margin-left: 8rpx;
  291. font-size: 22rpx;
  292. color: #a0a7b0;
  293. }
  294. .filters {
  295. padding: 20rpx 24rpx;
  296. background: #fff;
  297. border-bottom: 1rpx solid #edf0f2;
  298. }
  299. .search-row {
  300. display: flex;
  301. align-items: center;
  302. gap: 20rpx;
  303. }
  304. .search-input {
  305. flex: 1;
  306. min-width: 0;
  307. height: 72rpx;
  308. padding: 0 24rpx;
  309. border-radius: 12rpx;
  310. background: #f5f6f7;
  311. font-size: 26rpx;
  312. }
  313. .reset {
  314. flex-shrink: 0;
  315. color: #6f7782;
  316. font-size: 26rpx;
  317. }
  318. .summary {
  319. padding: 22rpx 28rpx 6rpx;
  320. display: flex;
  321. align-items: center;
  322. justify-content: space-between;
  323. font-size: 24rpx;
  324. }
  325. .summary-right {
  326. display: flex;
  327. align-items: center;
  328. gap: 20rpx;
  329. min-width: 0;
  330. }
  331. .summary-right .muted {
  332. overflow: hidden;
  333. white-space: nowrap;
  334. text-overflow: ellipsis;
  335. }
  336. .list {
  337. padding: 18rpx 24rpx;
  338. }
  339. .tpl-card {
  340. margin-bottom: 20rpx;
  341. padding: 26rpx;
  342. }
  343. .card-head {
  344. display: flex;
  345. align-items: center;
  346. }
  347. .card-icon {
  348. width: 68rpx;
  349. height: 68rpx;
  350. border-radius: 15rpx;
  351. display: flex;
  352. align-items: center;
  353. justify-content: center;
  354. font-size: 28rpx;
  355. font-weight: 600;
  356. flex-shrink: 0;
  357. }
  358. .card-title {
  359. flex: 1;
  360. min-width: 0;
  361. margin-left: 18rpx;
  362. }
  363. .card-title text {
  364. display: block;
  365. font-size: 29rpx;
  366. font-weight: 600;
  367. }
  368. .card-title text + text {
  369. margin-top: 8rpx;
  370. color: #a0a7b0;
  371. font-size: 21rpx;
  372. font-weight: 400;
  373. }
  374. .small {
  375. font-size: 21rpx;
  376. font-weight: 400;
  377. }
  378. .card-tip {
  379. margin-top: 16rpx;
  380. font-size: 23rpx;
  381. color: #6f7782;
  382. }
  383. .card-meta {
  384. display: flex;
  385. gap: 16rpx;
  386. margin-top: 18rpx;
  387. }
  388. .card-meta view {
  389. flex: 1;
  390. padding: 16rpx 18rpx;
  391. border-radius: 12rpx;
  392. background: #fafbfc;
  393. }
  394. .card-meta text {
  395. display: block;
  396. font-size: 22rpx;
  397. color: #a0a7b0;
  398. }
  399. .card-meta text + text {
  400. margin-top: 8rpx;
  401. color: #1f2329;
  402. font-size: 26rpx;
  403. font-weight: 500;
  404. }
  405. .card-actions {
  406. margin-top: 18rpx;
  407. padding-top: 18rpx;
  408. border-top: 1rpx solid #f2f3f5;
  409. display: flex;
  410. justify-content: flex-end;
  411. gap: 30rpx;
  412. }
  413. .link {
  414. color: #157a2c;
  415. font-size: 25rpx;
  416. }
  417. .link.danger {
  418. color: #ee4d4d;
  419. }
  420. .empty {
  421. padding-top: 180rpx;
  422. text-align: center;
  423. color: #a0a7b0;
  424. }
  425. .empty view {
  426. font-size: 80rpx;
  427. color: #cfd4da;
  428. }
  429. .empty text {
  430. display: block;
  431. margin-top: 20rpx;
  432. }
  433. .bottom-action {
  434. position: fixed;
  435. z-index: 10;
  436. left: 0;
  437. right: 0;
  438. bottom: 0;
  439. height: 120rpx;
  440. padding: 16rpx 24rpx;
  441. background: #fff;
  442. border-top: 1rpx solid #e8e9eb;
  443. }
  444. .bottom-action .primary-btn {
  445. height: 84rpx;
  446. font-size: 30rpx;
  447. }
  448. .mask {
  449. position: fixed;
  450. z-index: 20;
  451. left: 0;
  452. right: 0;
  453. top: 0;
  454. bottom: 0;
  455. background: rgba(0, 0, 0, 0.45);
  456. display: flex;
  457. align-items: flex-end;
  458. }
  459. .sheet {
  460. width: 100%;
  461. max-height: 70vh;
  462. padding: 28rpx 28rpx 40rpx;
  463. border-radius: 24rpx 24rpx 0 0;
  464. background: #fff;
  465. box-sizing: border-box;
  466. }
  467. .sheet-head {
  468. display: flex;
  469. align-items: center;
  470. justify-content: space-between;
  471. font-size: 30rpx;
  472. font-weight: 600;
  473. margin-bottom: 12rpx;
  474. }
  475. .version-list {
  476. max-height: 52vh;
  477. }
  478. .preview-body {
  479. max-height: 58vh;
  480. }
  481. .version-item {
  482. display: flex;
  483. align-items: center;
  484. gap: 20rpx;
  485. padding: 22rpx 0;
  486. border-bottom: 1rpx solid #f2f3f5;
  487. }
  488. .version-no {
  489. width: 68rpx;
  490. height: 44rpx;
  491. line-height: 44rpx;
  492. text-align: center;
  493. border-radius: 10rpx;
  494. background: #f0f8f2;
  495. color: #157a2c;
  496. font-size: 24rpx;
  497. flex-shrink: 0;
  498. }
  499. .version-main {
  500. flex: 1;
  501. min-width: 0;
  502. }
  503. .version-main text {
  504. display: block;
  505. font-size: 26rpx;
  506. }
  507. .version-main text + text {
  508. margin-top: 6rpx;
  509. color: #a0a7b0;
  510. }
  511. @media (min-width: 800px) {
  512. .bottom-action {
  513. max-width: 520px;
  514. left: 50%;
  515. transform: translateX(-50%);
  516. }
  517. .mask {
  518. justify-content: center;
  519. }
  520. .sheet {
  521. max-width: 520px;
  522. border-radius: 24rpx;
  523. margin-bottom: 40rpx;
  524. }
  525. }
  526. </style>