index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <view class="container">
  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. export default {
  59. data() {
  60. return {
  61. flowList: [],
  62. loading: false
  63. }
  64. },
  65. onLoad() {
  66. this.loadFlows()
  67. },
  68. onShow() {
  69. if (!this._onLoadFired) {
  70. this.loadFlows()
  71. }
  72. this._onLoadFired = true
  73. },
  74. methods: {
  75. async loadFlows() {
  76. this.loading = true
  77. try {
  78. const res = await getOrchestrationFlowList({ page: 1, pageSize: 50 })
  79. this.flowList = res.data.list || []
  80. } catch (e) {
  81. console.error('加载流程列表失败', e)
  82. uni.showToast({ title: '加载失败', icon: 'none' })
  83. } finally {
  84. this.loading = false
  85. }
  86. },
  87. getKey(flow) {
  88. return flow.id
  89. },
  90. getStatusText(status) {
  91. const map = {
  92. draft: '草稿',
  93. published: '已发布',
  94. archived: '已归档'
  95. }
  96. return map[status] || status
  97. },
  98. getNodeCount(flow) {
  99. try {
  100. const cfg = JSON.parse(flow.configJson || '{}')
  101. return cfg.nodes ? cfg.nodes.length : 0
  102. } catch (e) {
  103. return 0
  104. }
  105. },
  106. formatTime(t) {
  107. if (!t) return '-'
  108. var d = parseDate(t)
  109. if (!d) return t.substring(0, 10)
  110. return formatDateTime(d)
  111. },
  112. handleCreate() {
  113. uni.navigateTo({ url: '/pages/orchestration/editor' })
  114. },
  115. handleEdit(flow) {
  116. uni.navigateTo({ url: '/pages/orchestration/editor?id=' + flow.id })
  117. },
  118. async handlePublish(flow) {
  119. uni.showLoading({ title: '发布中...' })
  120. try {
  121. await publishOrchestrationFlow(flow.id)
  122. uni.showToast({ title: '发布成功', icon: 'success' })
  123. this.loadFlows()
  124. } catch (e) {
  125. uni.hideLoading()
  126. uni.showToast({ title: e.message || '发布失败', icon: 'none' })
  127. }
  128. },
  129. async handleArchive(flow) {
  130. uni.showLoading({ title: '归档中...' })
  131. try {
  132. await archiveOrchestrationFlow(flow.id)
  133. uni.showToast({ title: '归档成功', icon: 'success' })
  134. this.loadFlows()
  135. } catch (e) {
  136. uni.hideLoading()
  137. uni.showToast({ title: e.message || '归档失败', icon: 'none' })
  138. }
  139. },
  140. handleDelete(flow) {
  141. uni.showModal({
  142. title: '确认删除',
  143. content: '删除后无法恢复,确定要删除这个流程吗?',
  144. success: (res) => {
  145. if (res.confirm) {
  146. this.doDelete(flow)
  147. }
  148. }
  149. })
  150. },
  151. async doDelete(flow) {
  152. uni.showLoading({ title: '删除中...' })
  153. try {
  154. await deleteOrchestrationFlow(flow.id)
  155. uni.showToast({ title: '删除成功', icon: 'success' })
  156. this.loadFlows()
  157. } catch (e) {
  158. uni.hideLoading()
  159. uni.showToast({ title: e.message || '删除失败', icon: 'none' })
  160. }
  161. },
  162. handleRun(flow) {
  163. // 弹出家庭成员选择
  164. this.showRunDialog(flow)
  165. },
  166. showRunDialog(flow) {
  167. // 这里简化处理,直接跳转到执行详情页
  168. // 实际项目中应先选择家庭成员
  169. uni.navigateTo({
  170. url: '/pages/orchestration/editor?flowId=' + flow.id + '&action=run'
  171. })
  172. }
  173. }
  174. }
  175. </script>
  176. <style scoped>
  177. .container {
  178. min-height: 100vh;
  179. background: linear-gradient(180deg, #FFF7ED 0%, #F8F8F8 100%);
  180. padding-bottom: 40rpx;
  181. }
  182. .header {
  183. padding: 40rpx 30rpx 30rpx;
  184. background: linear-gradient(135deg, #F97316 0%, #EA580C 100%);
  185. color: #fff;
  186. }
  187. .title {
  188. display: block;
  189. font-size: 40rpx;
  190. font-weight: bold;
  191. margin-bottom: 10rpx;
  192. }
  193. .subtitle {
  194. display: block;
  195. font-size: 26rpx;
  196. opacity: 0.9;
  197. }
  198. .create-btn {
  199. margin: 30rpx;
  200. background: linear-gradient(135deg, #F97316 0%, #EA580C 100%);
  201. color: #fff;
  202. border-radius: 50rpx;
  203. padding: 28rpx 0;
  204. text-align: center;
  205. display: flex;
  206. align-items: center;
  207. justify-content: center;
  208. box-shadow: 0 8rpx 24rpx rgba(249, 115, 22, 0.3);
  209. }
  210. .create-icon {
  211. font-size: 44rpx;
  212. margin-right: 12rpx;
  213. font-weight: 300;
  214. }
  215. .flow-list {
  216. padding: 0 30rpx;
  217. }
  218. .flow-card {
  219. background: #fff;
  220. border-radius: 20rpx;
  221. padding: 30rpx;
  222. margin-bottom: 24rpx;
  223. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
  224. }
  225. .flow-header {
  226. display: flex;
  227. align-items: center;
  228. justify-content: space-between;
  229. margin-bottom: 16rpx;
  230. }
  231. .flow-name {
  232. font-size: 32rpx;
  233. font-weight: bold;
  234. color: #1E293B;
  235. flex: 1;
  236. }
  237. .flow-status {
  238. padding: 6rpx 16rpx;
  239. border-radius: 20rpx;
  240. font-size: 22rpx;
  241. margin-left: 16rpx;
  242. }
  243. .status-draft { background: #F1F5F9; color: #64748B; }
  244. .status-published { background: #DCFCE7; color: #16A34A; }
  245. .status-archived { background: #FEF3C7; color: #D97706; }
  246. .flow-desc {
  247. font-size: 26rpx;
  248. color: #64748B;
  249. margin-bottom: 16rpx;
  250. line-height: 1.5;
  251. }
  252. .empty { color: #94A3B8; }
  253. .flow-meta {
  254. display: flex;
  255. margin-bottom: 20rpx;
  256. }
  257. .meta-item {
  258. font-size: 22rpx;
  259. color: #94A3B8;
  260. margin-right: 24rpx;
  261. }
  262. .flow-actions {
  263. display: flex;
  264. gap: 16rpx;
  265. flex-wrap: wrap;
  266. }
  267. .btn {
  268. padding: 12rpx 24rpx;
  269. border-radius: 8rpx;
  270. font-size: 24rpx;
  271. border: none;
  272. }
  273. .btn::after { border: none; }
  274. .btn-publish { background: #F97316; color: #fff; }
  275. .btn-archive { background: #F59E0B; color: #fff; }
  276. .btn-delete { background: #EF4444; color: #fff; }
  277. .btn-run { background: #10B981; color: #fff; }
  278. .empty-state {
  279. text-align: center;
  280. padding: 100rpx 0;
  281. }
  282. .empty-icon {
  283. display: block;
  284. font-size: 80rpx;
  285. margin-bottom: 20rpx;
  286. }
  287. .empty-text {
  288. display: block;
  289. font-size: 28rpx;
  290. color: #94A3B8;
  291. margin-bottom: 10rpx;
  292. }
  293. .empty-hint {
  294. display: block;
  295. font-size: 24rpx;
  296. color: #CBD5E1;
  297. }
  298. .loading {
  299. text-align: center;
  300. padding: 60rpx;
  301. color: #94A3B8;
  302. }
  303. </style>