index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  3. <!-- 标题栏 -->
  4. <view class="header">
  5. <text class="title">流程编排</text>
  6. <text class="subtitle">创建和管理你的任务流程</text>
  7. </view>
  8. <!-- 新建按钮 -->
  9. <view class="create-btn" @click="handleCreate">
  10. <text class="create-icon">+</text>
  11. <text>新建流程</text>
  12. </view>
  13. <!-- 流程列表 -->
  14. <view class="flow-list">
  15. <view
  16. v-for="flow in flowList"
  17. :key="getKey(flow)"
  18. class="flow-card"
  19. @click="handleEdit(flow)"
  20. >
  21. <view class="flow-header">
  22. <text class="flow-name">{{ flow.name }}</text>
  23. <view class="flow-status" :class="'status-' + flow.status">
  24. {{ getStatusText(flow.status) }}
  25. </view>
  26. </view>
  27. <view class="flow-desc">
  28. <text v-if="flow.description">{{ flow.description }}</text>
  29. <text v-else class="empty">暂无描述</text>
  30. </view>
  31. <view class="flow-meta">
  32. <text class="meta-item">版本 {{ flow.version }}</text>
  33. <text class="meta-item">节点 {{ getNodeCount(flow) }}个</text>
  34. <text class="meta-item">{{ formatTime(flow.createdAt) }}</text>
  35. </view>
  36. <view class="flow-actions" @click.stop>
  37. <button v-if="flow.status === 'draft'" class="btn btn-publish" @click="handlePublish(flow)">发布</button>
  38. <button v-if="flow.status === 'published'" class="btn btn-archive" @click="handleArchive(flow)">归档</button>
  39. <button v-if="flow.status === 'draft'" class="btn btn-delete" @click="handleDelete(flow)">删除</button>
  40. <button class="btn btn-run" @click="handleRun(flow)">运行</button>
  41. </view>
  42. </view>
  43. <view v-if="!loading && flowList.length === 0" class="empty-state">
  44. <text class="empty-icon">📋</text>
  45. <text class="empty-text">暂无编排流程</text>
  46. <text class="empty-hint">点击新建开始你的第一个流程</text>
  47. </view>
  48. </view>
  49. <!-- 加载状态 -->
  50. <view v-if="loading" class="loading">
  51. <text>加载中...</text>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import { getOrchestrationFlowList, publishOrchestrationFlow, archiveOrchestrationFlow, deleteOrchestrationFlow, startOrchestrationExecution } from '../../utils/api.js'
  57. import { parseDate, formatDateTime } from '../../utils/format.js'
  58. import fontScaleMixin from '@/mixins/font-scale.js'
  59. export default {
  60. mixins: [fontScaleMixin],
  61. data() {
  62. return {
  63. flowList: [],
  64. loading: false
  65. }
  66. },
  67. onLoad() {
  68. this.loadFlows()
  69. },
  70. onShow() {
  71. if (!this._onLoadFired) {
  72. this.loadFlows()
  73. }
  74. this._onLoadFired = true
  75. },
  76. methods: {
  77. async loadFlows() {
  78. this.loading = true
  79. try {
  80. const res = await getOrchestrationFlowList({ page: 1, pageSize: 50 })
  81. this.flowList = res.data.list || []
  82. } catch (e) {
  83. console.error('加载流程列表失败', e)
  84. uni.showToast({ title: '加载失败', icon: 'none' })
  85. } finally {
  86. this.loading = false
  87. }
  88. },
  89. getKey(flow) {
  90. return flow.id
  91. },
  92. getStatusText(status) {
  93. const map = {
  94. draft: '草稿',
  95. published: '已发布',
  96. archived: '已归档'
  97. }
  98. return map[status] || status
  99. },
  100. getNodeCount(flow) {
  101. try {
  102. const cfg = JSON.parse(flow.configJson || '{}')
  103. return cfg.nodes ? cfg.nodes.length : 0
  104. } catch (e) {
  105. return 0
  106. }
  107. },
  108. formatTime(t) {
  109. if (!t) return '-'
  110. var d = parseDate(t)
  111. if (!d) return t.substring(0, 10)
  112. return formatDateTime(d)
  113. },
  114. handleCreate() {
  115. uni.navigateTo({ url: '/pages/orchestration/editor' })
  116. },
  117. handleEdit(flow) {
  118. uni.navigateTo({ url: '/pages/orchestration/editor?id=' + flow.id })
  119. },
  120. async handlePublish(flow) {
  121. uni.showLoading({ title: '发布中...' })
  122. try {
  123. await publishOrchestrationFlow(flow.id)
  124. uni.showToast({ title: '发布成功', icon: 'success' })
  125. this.loadFlows()
  126. } catch (e) {
  127. uni.hideLoading()
  128. uni.showToast({ title: e.message || '发布失败', icon: 'none' })
  129. }
  130. },
  131. async handleArchive(flow) {
  132. uni.showLoading({ title: '归档中...' })
  133. try {
  134. await archiveOrchestrationFlow(flow.id)
  135. uni.showToast({ title: '归档成功', icon: 'success' })
  136. this.loadFlows()
  137. } catch (e) {
  138. uni.hideLoading()
  139. uni.showToast({ title: e.message || '归档失败', icon: 'none' })
  140. }
  141. },
  142. handleDelete(flow) {
  143. uni.showModal({
  144. title: '确认删除',
  145. content: '删除后无法恢复,确定要删除这个流程吗?',
  146. success: (res) => {
  147. if (res.confirm) {
  148. this.doDelete(flow)
  149. }
  150. }
  151. })
  152. },
  153. async doDelete(flow) {
  154. uni.showLoading({ title: '删除中...' })
  155. try {
  156. await deleteOrchestrationFlow(flow.id)
  157. uni.showToast({ title: '删除成功', icon: 'success' })
  158. this.loadFlows()
  159. } catch (e) {
  160. uni.hideLoading()
  161. uni.showToast({ title: e.message || '删除失败', icon: 'none' })
  162. }
  163. },
  164. handleRun(flow) {
  165. // 弹出家庭成员选择
  166. this.showRunDialog(flow)
  167. },
  168. showRunDialog(flow) {
  169. // 这里简化处理,直接跳转到执行详情页
  170. // 实际项目中应先选择家庭成员
  171. uni.navigateTo({
  172. url: '/pages/orchestration/editor?flowId=' + flow.id + '&action=run'
  173. })
  174. }
  175. }
  176. }
  177. </script>
  178. <style scoped lang="scss">
  179. .container {
  180. min-height: 100vh;
  181. background: linear-gradient(180deg, $uni-primary-pale 0%, $facade-fill-page 100%);
  182. padding-bottom: 40rpx;
  183. }
  184. .header {
  185. padding: 40rpx $uni-space-page $uni-space-lg;
  186. background: linear-gradient(135deg, $brand-primary 0%, $brand-primary-dark 100%);
  187. color: $app-surface;
  188. }
  189. .title {
  190. display: block;
  191. font-size: calc(40rpx * var(--font-scale, 1));
  192. font-weight: bold;
  193. margin-bottom: 10rpx;
  194. }
  195. .subtitle {
  196. display: block;
  197. font-size: calc(26rpx * var(--font-scale, 1));
  198. opacity: 0.9;
  199. }
  200. .create-btn {
  201. margin: $uni-space-lg;
  202. background: linear-gradient(135deg, $brand-primary 0%, $brand-primary-dark 100%);
  203. color: $app-surface;
  204. border-radius: 24rpx;
  205. padding: 28rpx 0;
  206. text-align: center;
  207. display: flex;
  208. align-items: center;
  209. justify-content: center;
  210. box-shadow: 0 8rpx 24rpx rgba(249, 115, 22, 0.3);
  211. }
  212. .create-icon {
  213. font-size: calc(44rpx * var(--font-scale, 1));
  214. margin-right: 12rpx;
  215. font-weight: 400;
  216. }
  217. .flow-list {
  218. padding: 0 $uni-space-page;
  219. }
  220. .flow-card {
  221. background: $app-surface;
  222. border-radius: 24rpx;
  223. padding: $uni-space-lg;
  224. margin-bottom: 24rpx;
  225. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
  226. }
  227. .flow-header {
  228. display: flex;
  229. align-items: center;
  230. justify-content: space-between;
  231. margin-bottom: 16rpx;
  232. }
  233. .flow-name {
  234. font-size: calc(32rpx * var(--font-scale, 1));
  235. font-weight: bold;
  236. color: $uni-text-color;
  237. flex: 1;
  238. }
  239. .flow-status {
  240. padding: 6rpx 16rpx;
  241. border-radius: 24rpx;
  242. font-size: calc(22rpx * var(--font-scale, 1));
  243. margin-left: 16rpx;
  244. }
  245. .status-draft { background: $facade-fill-slate; color: $uni-text-color-secondary; }
  246. .status-published { background: $status-success-soft-2; color: $status-success-strong-2; }
  247. .status-archived { background: $status-warning-soft; color: $status-warning-deep; }
  248. .flow-desc {
  249. font-size: calc(26rpx * var(--font-scale, 1));
  250. color: $uni-text-color-secondary;
  251. margin-bottom: 16rpx;
  252. line-height: 1.5;
  253. }
  254. .empty { color: $app-text-subtle; }
  255. .flow-meta {
  256. display: flex;
  257. margin-bottom: 20rpx;
  258. }
  259. .meta-item {
  260. font-size: calc(22rpx * var(--font-scale, 1));
  261. color: $app-text-subtle;
  262. margin-right: 24rpx;
  263. }
  264. .flow-actions {
  265. display: flex;
  266. gap: 16rpx;
  267. flex-wrap: wrap;
  268. }
  269. .btn {
  270. padding: 12rpx 24rpx;
  271. border-radius: 8rpx;
  272. font-size: calc(24rpx * var(--font-scale, 1));
  273. border: none;
  274. }
  275. .btn::after { border: none; }
  276. .btn-publish { background: $brand-primary; color: $app-surface; }
  277. .btn-archive { background: $dim-wealth; color: $app-surface; }
  278. .btn-delete { background: $status-danger; color: $app-surface; }
  279. .btn-run { background: $status-success; color: $app-surface; }
  280. .empty-state {
  281. text-align: center;
  282. padding: 100rpx 0;
  283. }
  284. .empty-icon {
  285. display: block;
  286. font-size: calc($uni-font-size-5xl * var(--font-scale, 1));
  287. margin-bottom: 20rpx;
  288. }
  289. .empty-text {
  290. display: block;
  291. font-size: calc(28rpx * var(--font-scale, 1));
  292. color: $app-text-subtle;
  293. margin-bottom: 10rpx;
  294. }
  295. .empty-hint {
  296. display: block;
  297. font-size: calc(24rpx * var(--font-scale, 1));
  298. color: $uni-border-color;
  299. }
  300. .loading {
  301. text-align: center;
  302. padding: 60rpx;
  303. color: $app-text-subtle;
  304. }
  305. </style>