taskList.vue 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  1. <template>
  2. <div class="table-box">
  3. <div class="card table-search">
  4. <el-form ref="elSearchFormRef" :inline="true" size="small" :model="searchForm" class="demo-form-inline" @keyup.enter="onSubmit">
  5. <el-form-item label="任务名称">
  6. <el-input v-model="searchForm.title" placeholder="任务名称" style="width:150px"></el-input>
  7. </el-form-item>
  8. <el-form-item label="分类">
  9. <el-select v-model="searchForm.category_id" placeholder="分类" clearable style="width:120px">
  10. <el-option v-for="item in categoryOptions" :key="item.id" :label="item.name" :value="item.id" />
  11. </el-select>
  12. </el-form-item>
  13. <el-form-item label="状态">
  14. <el-select v-model="searchForm.status" placeholder="状态" clearable style="width:100px">
  15. <el-option label="启用" :value="1" />
  16. <el-option label="禁用" :value="0" />
  17. </el-select>
  18. </el-form-item>
  19. <div class="operation">
  20. <el-button type="primary" icon="search" @click="onSubmit">查询</el-button>
  21. <el-button icon="refresh" @click="onResetSearch">重置</el-button>
  22. </div>
  23. </el-form>
  24. </div>
  25. <div class="card table-main">
  26. <div class="table-header">
  27. <div class="header-button-lf">
  28. <el-button type="primary" icon="Plus" @click="openDialog()">新增任务</el-button>
  29. </div>
  30. <div class="header-button-ri">
  31. <el-button :icon="Refresh" circle @click="refresh" />
  32. </div>
  33. </div>
  34. <el-table ref="myTable" :data="tableData" border size="small">
  35. <el-table-column prop="id" label="ID" align="center" width="80" />
  36. <el-table-column prop="title" label="任务名称" align="center" min-width="150" />
  37. <el-table-column prop="categoryId" label="分类" align="center" width="100">
  38. <template #default="{ row }">
  39. {{ getCategoryName(row.categoryId) }}
  40. </template>
  41. </el-table-column>
  42. <el-table-column prop="cover" label="图标" align="center" width="80">
  43. <template #default="{ row }">
  44. <el-image v-if="row.cover" :src="row.cover" style="width: 40px; height: 40px" fit="contain" />
  45. </template>
  46. </el-table-column>
  47. <el-table-column prop="rewardAmount" label="奖励金额(USDT)" align="center" min-width="130">
  48. <template #default="{ row }">
  49. <span class="text-success">{{ formatAmount(row.rewardAmount) }}</span>
  50. </template>
  51. </el-table-column>
  52. <el-table-column prop="totalCount" label="任务总量" align="center" width="90" />
  53. <el-table-column prop="remainCount" label="剩余数量" align="center" width="90" />
  54. <el-table-column prop="dailyLimit" label="每日限制" align="center" width="90" />
  55. <el-table-column prop="totalLimit" label="总限制" align="center" width="90" />
  56. <el-table-column prop="completedCount" label="已完成" align="center" width="80" />
  57. <el-table-column prop="minLevel" label="最低等级" align="center" width="80" />
  58. <el-table-column label="完成条件" align="center" min-width="150">
  59. <template #default="{ row }">
  60. <el-tag v-if="row.requirePhone" type="primary" size="small" style="margin: 2px">手机</el-tag>
  61. <el-tag v-if="row.requireRealname" type="success" size="small" style="margin: 2px">实名</el-tag>
  62. <el-tag v-if="row.requireIdcard" type="warning" size="small" style="margin: 2px">身份</el-tag>
  63. <span v-if="!row.requirePhone && !row.requireRealname && !row.requireIdcard" class="text-muted">无</span>
  64. </template>
  65. </el-table-column>
  66. <el-table-column prop="sort" label="排序" align="center" width="70" />
  67. <el-table-column prop="status" label="状态" align="center" width="80">
  68. <template #default="{ row }">
  69. <el-tag :type="row.status === 1 ? 'success' : 'danger'">
  70. {{ row.status === 1 ? '启用' : '禁用' }}
  71. </el-tag>
  72. </template>
  73. </el-table-column>
  74. <el-table-column prop="createdAt" label="创建时间" align="center" min-width="160">
  75. <template #default="{ row }">
  76. <span v-if="row.createdAt">{{ formatUnix(row.createdAt) }}</span>
  77. </template>
  78. </el-table-column>
  79. <el-table-column fixed="right" label="操作" align="center" width="240">
  80. <template #default="scope">
  81. <el-button type="primary" link @click="openDialog(scope.row)">编辑</el-button>
  82. <el-button type="info" link @click="openStepDialog(scope.row)">步骤</el-button>
  83. <el-button type="warning" link @click="openExampleDialog(scope.row)">样例</el-button>
  84. <el-button type="danger" link @click="handleDelete(scope.row)">删除</el-button>
  85. </template>
  86. </el-table-column>
  87. </el-table>
  88. <Pagination :pageable="pageable" @handleCurrent="handleCurrent" />
  89. </div>
  90. </div>
  91. <!-- 编辑任务弹窗 -->
  92. <el-dialog v-model="dialogVisible" :title="isEdit ? '编辑任务' : '新增任务'" width="600px" center destroy-on-close>
  93. <el-form ref="formRef" :model="formData" :rules="formRules" label-width="120px">
  94. <el-form-item label="任务名称" prop="title">
  95. <el-input v-model="formData.title" placeholder="请输入任务名称" />
  96. </el-form-item>
  97. <el-form-item label="分类" prop="category_id">
  98. <el-select v-model="formData.category_id" placeholder="请选择分类" style="width: 100%">
  99. <el-option v-for="item in categoryOptions" :key="item.id" :label="item.name" :value="item.id" />
  100. </el-select>
  101. </el-form-item>
  102. <el-form-item label="图标" prop="icon">
  103. <div class="icon-upload-wrapper">
  104. <el-upload
  105. class="icon-uploader"
  106. action="#"
  107. :show-file-list="false"
  108. :http-request="handleIconUpload"
  109. :before-upload="beforeIconUpload"
  110. accept="image/*"
  111. >
  112. <el-image v-if="formData.icon" :src="formData.icon" class="icon-preview-img" fit="contain" />
  113. <el-icon v-else class="icon-uploader-icon"><Plus /></el-icon>
  114. </el-upload>
  115. <div class="icon-actions">
  116. <el-button type="primary" size="small" @click="openMaterialPicker">从素材库选择</el-button>
  117. <el-button v-if="formData.icon" type="danger" size="small" @click="formData.icon = ''">删除</el-button>
  118. </div>
  119. </div>
  120. <div class="icon-url-input">
  121. <el-input v-model="formData.icon" placeholder="或直接输入图标URL" size="small" clearable />
  122. </div>
  123. <div class="upload-tip">建议尺寸: 100 x 100 px,支持 jpg/png/gif 格式</div>
  124. </el-form-item>
  125. <el-form-item label="描述" prop="description">
  126. <el-input v-model="formData.description" type="textarea" :rows="3" placeholder="请输入描述" />
  127. </el-form-item>
  128. <el-form-item label="任务链接" prop="url">
  129. <el-input v-model="formData.url" placeholder="请输入任务链接" />
  130. </el-form-item>
  131. <el-form-item label="奖励金额(USDT)" prop="reward_amount">
  132. <el-input-number v-model="formData.reward_amount" :min="0" :precision="2" :step="0.1" style="width: 100%" />
  133. </el-form-item>
  134. <el-form-item label="任务总量" prop="total_count">
  135. <el-input-number v-model="formData.total_count" :min="1" style="width: 100%" />
  136. <div class="form-tip">任务可被领取的总次数</div>
  137. </el-form-item>
  138. <el-form-item label="每日限制" prop="daily_limit">
  139. <el-input-number v-model="formData.daily_limit" :min="0" style="width: 100%" />
  140. </el-form-item>
  141. <el-form-item label="总限制" prop="total_limit">
  142. <el-input-number v-model="formData.total_limit" :min="0" style="width: 100%" />
  143. </el-form-item>
  144. <el-form-item label="最低等级" prop="min_level">
  145. <el-input-number v-model="formData.min_level" :min="0" style="width: 100%" />
  146. </el-form-item>
  147. <el-form-item label="排序" prop="sort">
  148. <el-input-number v-model="formData.sort" :min="0" style="width: 100%" />
  149. </el-form-item>
  150. <el-form-item label="完成条件">
  151. <el-checkbox-group v-model="formData.require_conditions">
  152. <el-checkbox label="requirePhone">手机认证</el-checkbox>
  153. <el-checkbox label="requireRealname">实名认证</el-checkbox>
  154. <el-checkbox label="requireIdcard">身份认证</el-checkbox>
  155. </el-checkbox-group>
  156. <div class="form-tip">用户需满足选中的条件才能领取该任务</div>
  157. </el-form-item>
  158. <el-form-item label="状态" prop="status">
  159. <el-radio-group v-model="formData.status">
  160. <el-radio :value="1">启用</el-radio>
  161. <el-radio :value="0">禁用</el-radio>
  162. </el-radio-group>
  163. </el-form-item>
  164. </el-form>
  165. <template #footer>
  166. <el-button @click="dialogVisible = false">取消</el-button>
  167. <el-button type="primary" :loading="submitLoading" @click="handleSubmit">确定</el-button>
  168. </template>
  169. </el-dialog>
  170. <!-- 任务步骤弹窗 -->
  171. <el-dialog v-model="stepDialogVisible" title="任务步骤" width="900px" center destroy-on-close>
  172. <div class="step-header">
  173. <el-button type="primary" size="small" icon="Plus" @click="openStepEditDialog()">新增步骤</el-button>
  174. </div>
  175. <el-table :data="stepList" border size="small">
  176. <el-table-column prop="stepNo" label="步骤序号" align="center" width="80" />
  177. <el-table-column prop="image" label="步骤图片" align="center" width="100">
  178. <template #default="{ row }">
  179. <el-image v-if="row.image" :src="row.image" style="width: 60px; height: 60px" fit="contain" :preview-src-list="[row.image]" />
  180. <span v-else class="text-muted">暂无</span>
  181. </template>
  182. </el-table-column>
  183. <el-table-column prop="title" label="步骤标题" align="center" min-width="120" />
  184. <el-table-column prop="description" label="描述" align="center" min-width="200" show-overflow-tooltip />
  185. <el-table-column prop="requireUpload" label="需上传凭证" align="center" width="100">
  186. <template #default="{ row }">
  187. <el-tag :type="row.requireUpload === 1 ? 'danger' : 'info'" size="small">
  188. {{ row.requireUpload === 1 ? '是' : '否' }}
  189. </el-tag>
  190. </template>
  191. </el-table-column>
  192. <el-table-column fixed="right" label="操作" align="center" width="150">
  193. <template #default="scope">
  194. <el-button type="primary" link @click="openStepEditDialog(scope.row)">编辑</el-button>
  195. <el-button type="danger" link @click="handleDeleteStep(scope.row)">删除</el-button>
  196. </template>
  197. </el-table-column>
  198. </el-table>
  199. </el-dialog>
  200. <!-- 编辑步骤弹窗 -->
  201. <el-dialog v-model="stepEditDialogVisible" :title="isStepEdit ? '编辑步骤' : '新增步骤'" width="600px" center destroy-on-close>
  202. <el-form ref="stepFormRef" :model="stepFormData" :rules="stepFormRules" label-width="100px">
  203. <el-form-item label="步骤序号" prop="stepNo">
  204. <el-input-number v-model="stepFormData.stepNo" :min="1" style="width: 100%" />
  205. </el-form-item>
  206. <el-form-item label="步骤标题" prop="title">
  207. <el-input v-model="stepFormData.title" placeholder="请输入步骤标题" />
  208. </el-form-item>
  209. <el-form-item label="描述" prop="description">
  210. <el-input v-model="stepFormData.description" type="textarea" :rows="4" placeholder="请输入步骤描述,可详细说明该步骤的操作要求" />
  211. </el-form-item>
  212. <el-form-item label="步骤图片" prop="image">
  213. <div class="step-image-wrapper">
  214. <el-input v-model="stepFormData.image" placeholder="请输入图片URL或选择素材" style="flex: 1" />
  215. <el-button type="primary" @click="openStepMaterialPicker">选择素材</el-button>
  216. </div>
  217. <div v-if="stepFormData.image" class="step-image-preview">
  218. <el-image :src="stepFormData.image" style="width: 120px; height: 120px" fit="contain" />
  219. <el-button type="danger" size="small" @click="stepFormData.image = ''">删除</el-button>
  220. </div>
  221. <div class="form-tip">用于展示该步骤的操作截图</div>
  222. </el-form-item>
  223. <el-form-item label="需上传凭证" prop="requireUpload">
  224. <el-radio-group v-model="stepFormData.requireUpload">
  225. <el-radio :value="1">是</el-radio>
  226. <el-radio :value="0">否</el-radio>
  227. </el-radio-group>
  228. <div class="form-tip">开启后,用户需上传完成凭证才能进入下一步</div>
  229. </el-form-item>
  230. </el-form>
  231. <template #footer>
  232. <el-button @click="stepEditDialogVisible = false">取消</el-button>
  233. <el-button type="primary" :loading="stepSubmitLoading" @click="handleStepSubmit">确定</el-button>
  234. </template>
  235. </el-dialog>
  236. <!-- 审核样例弹窗 -->
  237. <el-dialog v-model="exampleDialogVisible" title="审核样例" width="900px" center destroy-on-close>
  238. <div class="example-header">
  239. <el-button type="primary" size="small" icon="Plus" @click="openExampleEditDialog()">新增样例</el-button>
  240. <span class="example-tip">审核样例用于展示任务完成示例,帮助用户了解如何正确完成任务</span>
  241. </div>
  242. <el-table :data="exampleList" border size="small">
  243. <el-table-column prop="id" label="ID" align="center" width="80" />
  244. <el-table-column prop="image" label="样例图片" align="center" width="120">
  245. <template #default="{ row }">
  246. <el-image v-if="row.image" :src="row.image" style="width: 80px; height: 80px" fit="contain" :preview-src-list="[row.image]" />
  247. <span v-else class="text-muted">暂无</span>
  248. </template>
  249. </el-table-column>
  250. <el-table-column prop="description" label="样例描述" align="center" min-width="200" show-overflow-tooltip />
  251. <el-table-column prop="sort" label="排序" align="center" width="80" />
  252. <el-table-column fixed="right" label="操作" align="center" width="150">
  253. <template #default="scope">
  254. <el-button type="primary" link @click="openExampleEditDialog(scope.row)">编辑</el-button>
  255. <el-button type="danger" link @click="handleDeleteExample(scope.row)">删除</el-button>
  256. </template>
  257. </el-table-column>
  258. </el-table>
  259. </el-dialog>
  260. <!-- 编辑审核样例弹窗 -->
  261. <el-dialog v-model="exampleEditDialogVisible" :title="isExampleEdit ? '编辑样例' : '新增样例'" width="600px" center destroy-on-close>
  262. <el-form ref="exampleFormRef" :model="exampleFormData" :rules="exampleFormRules" label-width="100px">
  263. <el-form-item label="样例图片" prop="image">
  264. <div class="step-image-wrapper">
  265. <el-input v-model="exampleFormData.image" placeholder="请输入图片URL或选择素材" style="flex: 1" />
  266. <el-button type="primary" @click="openExampleMaterialPicker">选择素材</el-button>
  267. </div>
  268. <div v-if="exampleFormData.image" class="step-image-preview">
  269. <el-image :src="exampleFormData.image" style="width: 120px; height: 120px" fit="contain" />
  270. <el-button type="danger" size="small" @click="exampleFormData.image = ''">删除</el-button>
  271. </div>
  272. <div class="form-tip">用于展示任务完成后的截图示例</div>
  273. </el-form-item>
  274. <el-form-item label="样例描述" prop="description">
  275. <el-input v-model="exampleFormData.description" type="textarea" :rows="3" placeholder="请输入样例描述,说明该截图展示的内容" />
  276. </el-form-item>
  277. <el-form-item label="排序" prop="sort">
  278. <el-input-number v-model="exampleFormData.sort" :min="0" style="width: 100%" />
  279. <div class="form-tip">数值越小排序越靠前</div>
  280. </el-form-item>
  281. </el-form>
  282. <template #footer>
  283. <el-button @click="exampleEditDialogVisible = false">取消</el-button>
  284. <el-button type="primary" :loading="exampleSubmitLoading" @click="handleExampleSubmit">确定</el-button>
  285. </template>
  286. </el-dialog>
  287. <!-- 步骤素材选择器 -->
  288. <MaterialPicker
  289. v-model="stepMaterialPickerVisible"
  290. :accept-types="['image', 'video']"
  291. @confirm="handleStepMaterialSelect"
  292. />
  293. <!-- 审核样例素材选择器 -->
  294. <MaterialPicker
  295. v-model="exampleMaterialPickerVisible"
  296. :accept-types="['image']"
  297. @confirm="handleExampleMaterialSelect"
  298. />
  299. <!-- 素材选择器 -->
  300. <MaterialPicker
  301. v-model="materialPickerVisible"
  302. :accept-types="['image', 'video']"
  303. @confirm="handleMaterialSelect"
  304. />
  305. </template>
  306. <script setup>
  307. import { ref, reactive, onMounted } from "vue";
  308. import dayjs from "dayjs";
  309. import { Refresh, Plus } from "@element-plus/icons-vue";
  310. import MaterialPicker from "@/components/MaterialPicker/index.vue";
  311. import { ElNotification, ElMessageBox } from "element-plus";
  312. import Pagination from "@/components/Pangination/Pagination.vue";
  313. import {
  314. getTaskList, createTask, updateTask, deleteTask,
  315. getTaskCategoryList, getTaskStepList, createTaskStep, updateTaskStep, deleteTaskStep,
  316. getTaskExampleList, createTaskExample, updateTaskExample, deleteTaskExample,
  317. createMaterial, getMaterialGroupList
  318. } from "@/api/modules/daytask.js";
  319. import { uploadImg } from "@/api/modules/upload.js";
  320. const searchForm = ref({ title: null, category_id: null, status: null });
  321. const tableData = ref([]);
  322. const pageable = reactive({ pageNum: 1, pageSize: 30, total: 0 });
  323. const categoryOptions = ref([]);
  324. const taskIconGroupId = ref(0); // task_icon 分组ID
  325. const dialogVisible = ref(false);
  326. const isEdit = ref(false);
  327. const formRef = ref(null);
  328. const materialPickerVisible = ref(false);
  329. const submitLoading = ref(false);
  330. const formData = ref({
  331. id: null,
  332. title: "",
  333. category_id: null,
  334. icon: "",
  335. description: "",
  336. url: "",
  337. reward_amount: 0,
  338. total_count: 100,
  339. daily_limit: 1,
  340. total_limit: 1,
  341. min_level: 0,
  342. sort: 0,
  343. require_conditions: [], // 完成条件:requirePhone, requireRealname, requireIdcard
  344. status: 1
  345. });
  346. const formRules = ref({
  347. title: [{ required: true, message: "请输入任务名称", trigger: "blur" }],
  348. category_id: [{ required: true, message: "请选择分类", trigger: "change" }],
  349. reward_amount: [{ required: true, message: "请输入奖励金额", trigger: "blur" }],
  350. status: [{ required: true, message: "请选择状态", trigger: "change" }]
  351. });
  352. // 步骤相关
  353. const stepDialogVisible = ref(false);
  354. const currentTaskId = ref(null);
  355. const stepList = ref([]);
  356. const stepEditDialogVisible = ref(false);
  357. const isStepEdit = ref(false);
  358. const stepFormRef = ref(null);
  359. const stepSubmitLoading = ref(false);
  360. const stepFormData = ref({
  361. id: null,
  362. taskId: null,
  363. stepNo: 1,
  364. title: "",
  365. description: "",
  366. image: "",
  367. requireUpload: 1
  368. });
  369. const stepMaterialPickerVisible = ref(false);
  370. const stepFormRules = ref({
  371. stepNo: [{ required: true, message: "请输入步骤序号", trigger: "blur" }],
  372. title: [{ required: true, message: "请输入步骤标题", trigger: "blur" }]
  373. });
  374. // 审核样例相关
  375. const exampleDialogVisible = ref(false);
  376. const exampleList = ref([]);
  377. const exampleEditDialogVisible = ref(false);
  378. const isExampleEdit = ref(false);
  379. const exampleFormRef = ref(null);
  380. const exampleSubmitLoading = ref(false);
  381. const exampleFormData = ref({
  382. id: null,
  383. taskId: null,
  384. image: "",
  385. description: "",
  386. sort: 0
  387. });
  388. const exampleMaterialPickerVisible = ref(false);
  389. const exampleFormRules = ref({
  390. image: [{ required: true, message: "请选择样例图片", trigger: "change" }]
  391. });
  392. const formatUnix = (val) => {
  393. if (!val) return "";
  394. return dayjs.unix(val).format("YYYY-MM-DD HH:mm:ss");
  395. };
  396. const formatAmount = (val) => {
  397. if (val === null || val === undefined) return "0.00";
  398. return (val / 100).toFixed(2);
  399. };
  400. const getCategoryName = (id) => {
  401. const item = categoryOptions.value.find(c => c.id === id);
  402. return item ? item.name : "-";
  403. };
  404. onMounted(() => {
  405. getList();
  406. getCategoryList();
  407. getTaskIconGroupId();
  408. });
  409. // 获取 task_icon 分组ID
  410. const getTaskIconGroupId = async () => {
  411. try {
  412. const res = await getMaterialGroupList({ code: "task_icon", pageSize: 1 });
  413. if (res.code === 200 && res.data.list?.length > 0) {
  414. taskIconGroupId.value = res.data.list[0].id;
  415. }
  416. } catch (e) {
  417. console.error("获取task_icon分组失败", e);
  418. }
  419. };
  420. const getCategoryList = async () => {
  421. try {
  422. const res = await getTaskCategoryList({ pageSize: 100 });
  423. if (res.code === 200) {
  424. categoryOptions.value = res.data.list || [];
  425. }
  426. } catch (error) {
  427. console.error("获取分类列表失败", error);
  428. }
  429. };
  430. const getList = async () => {
  431. tableData.value = [];
  432. const params = {
  433. current: pageable.pageNum,
  434. pageSize: pageable.pageSize,
  435. order: "sort asc, id desc"
  436. };
  437. // 搜索参数映射为后端字段名
  438. if (searchForm.value.title) {
  439. params.title = searchForm.value.title;
  440. }
  441. if (searchForm.value.category_id) {
  442. params.categoryId = searchForm.value.category_id;
  443. }
  444. if (searchForm.value.status !== null && searchForm.value.status !== undefined) {
  445. params.status = searchForm.value.status;
  446. }
  447. try {
  448. const res = await getTaskList(params);
  449. if (res.code === 200) {
  450. tableData.value = res.data.list || [];
  451. pageable.total = res.data.paging?.total || 0;
  452. }
  453. } catch (error) {
  454. console.error("获取列表失败", error);
  455. }
  456. };
  457. const onSubmit = () => {
  458. pageable.pageNum = 1;
  459. getList();
  460. };
  461. const refresh = () => getList();
  462. const onResetSearch = () => {
  463. searchForm.value = { title: null, category_id: null, status: null };
  464. getList();
  465. };
  466. const handleCurrent = (data) => {
  467. pageable.pageNum = data.current;
  468. pageable.pageSize = data.pageSize;
  469. getList();
  470. };
  471. const openDialog = (row) => {
  472. isEdit.value = !!row;
  473. if (row) {
  474. // 后端字段映射到前端表单字段
  475. // 解析完成条件
  476. const conditions = [];
  477. if (row.requirePhone) conditions.push('requirePhone');
  478. if (row.requireRealname) conditions.push('requireRealname');
  479. if (row.requireIdcard) conditions.push('requireIdcard');
  480. formData.value = {
  481. id: row.id,
  482. title: row.title || "",
  483. category_id: row.categoryId || null,
  484. icon: row.cover || "",
  485. description: row.description || "",
  486. url: row.targetUrl || "",
  487. reward_amount: row.rewardAmount || 0,
  488. total_count: row.totalCount || 100,
  489. daily_limit: row.dailyLimit || 1,
  490. total_limit: row.totalLimit || 1,
  491. min_level: row.minLevel || 0,
  492. sort: row.sort || 0,
  493. require_conditions: conditions,
  494. status: row.status ?? 1
  495. };
  496. } else {
  497. formData.value = {
  498. id: null,
  499. title: "",
  500. category_id: null,
  501. icon: "",
  502. description: "",
  503. url: "",
  504. reward_amount: 0,
  505. total_count: 100,
  506. daily_limit: 1,
  507. total_limit: 1,
  508. min_level: 0,
  509. sort: 0,
  510. require_conditions: [],
  511. status: 1
  512. };
  513. }
  514. dialogVisible.value = true;
  515. if (formRef.value) {
  516. formRef.value.clearValidate();
  517. }
  518. };
  519. const handleSubmit = async () => {
  520. if (!formRef.value) return;
  521. await formRef.value.validate(async (valid) => {
  522. if (!valid) return;
  523. submitLoading.value = true;
  524. try {
  525. const api = isEdit.value ? updateTask : createTask;
  526. // 后端期望 { id, data: {...} } 格式,字段名使用camelCase(与后端json tag一致)
  527. const { id } = formData.value;
  528. // 解析完成条件多选框
  529. const conditions = formData.value.require_conditions || [];
  530. const data = {
  531. title: formData.value.title,
  532. categoryId: formData.value.category_id,
  533. cover: formData.value.icon,
  534. description: formData.value.description,
  535. targetUrl: formData.value.url,
  536. rewardAmount: formData.value.reward_amount,
  537. totalCount: formData.value.total_count,
  538. remainCount: isEdit.value ? undefined : formData.value.total_count, // 新建任务时,剩余数量=任务总量
  539. dailyLimit: formData.value.daily_limit,
  540. totalLimit: formData.value.total_limit,
  541. minLevel: formData.value.min_level,
  542. sort: formData.value.sort,
  543. // 完成条件
  544. requirePhone: conditions.includes('requirePhone') ? 1 : 0,
  545. requireRealname: conditions.includes('requireRealname') ? 1 : 0,
  546. requireIdcard: conditions.includes('requireIdcard') ? 1 : 0,
  547. status: formData.value.status
  548. };
  549. const params = isEdit.value ? { id, data } : { data };
  550. const res = await api(params);
  551. if (res.code === 200) {
  552. ElNotification.success(isEdit.value ? "更新成功" : "创建成功");
  553. dialogVisible.value = false;
  554. getList();
  555. } else {
  556. ElNotification.error(res.msg || (isEdit.value ? "更新失败" : "创建失败"));
  557. }
  558. } catch (error) {
  559. ElNotification.error(isEdit.value ? "更新失败" : "创建失败");
  560. } finally {
  561. submitLoading.value = false;
  562. }
  563. });
  564. };
  565. // ==================== 素材选择器 ====================
  566. const openMaterialPicker = () => {
  567. materialPickerVisible.value = true;
  568. };
  569. const handleMaterialSelect = (material) => {
  570. formData.value.icon = material.url;
  571. };
  572. // ==================== 图标上传 ====================
  573. const beforeIconUpload = (file) => {
  574. const isImage = file.type.startsWith("image/");
  575. const isLt5M = file.size / 1024 / 1024 < 5;
  576. if (!isImage) {
  577. ElNotification.warning("只能上传图片文件");
  578. return false;
  579. }
  580. if (!isLt5M) {
  581. ElNotification.warning("图片大小不能超过 5MB");
  582. return false;
  583. }
  584. return true;
  585. };
  586. const handleIconUpload = async (options) => {
  587. const uploadFormData = new FormData();
  588. uploadFormData.append("file", options.file);
  589. uploadFormData.append("autoSave", "false"); // 禁止后端自动保存,由前端控制
  590. try {
  591. const res = await uploadImg(uploadFormData);
  592. if (res.code === 200) {
  593. formData.value.icon = res.data.path;
  594. // 保存到素材库,使用 task_icon 分组ID
  595. const fileName = options.file.name; // 保留完整文件名
  596. const file = options.file;
  597. try {
  598. await createMaterial({
  599. data: {
  600. name: fileName,
  601. type: "image",
  602. url: res.data.path,
  603. size: file.size || 0,
  604. mimeType: file.type || "",
  605. groupId: taskIconGroupId.value || 0,
  606. status: 1
  607. }
  608. });
  609. ElNotification.success("上传成功并已保存到素材库");
  610. } catch (e) {
  611. ElNotification.success("图片上传成功");
  612. }
  613. } else {
  614. ElNotification.error(res.msg || "图片上传失败");
  615. }
  616. } catch (error) {
  617. console.error("上传失败", error);
  618. ElNotification.error("图片上传失败");
  619. }
  620. };
  621. const handleDelete = async (row) => {
  622. try {
  623. await ElMessageBox.confirm("确认删除该任务吗?", "提示", {
  624. type: "warning",
  625. confirmButtonText: "确定",
  626. cancelButtonText: "取消"
  627. });
  628. const res = await deleteTask({ id: row.id });
  629. if (res.code === 200) {
  630. ElNotification.success("删除成功");
  631. getList();
  632. } else {
  633. ElNotification.error(res.msg || "删除失败");
  634. }
  635. } catch (error) {
  636. if (error !== "cancel" && error !== "close") {
  637. ElNotification.error("删除失败");
  638. }
  639. }
  640. };
  641. // 步骤相关方法
  642. const openStepDialog = async (row) => {
  643. currentTaskId.value = row.id;
  644. stepDialogVisible.value = true;
  645. await getStepList();
  646. };
  647. const getStepList = async () => {
  648. try {
  649. const res = await getTaskStepList({ taskId: currentTaskId.value, pageSize: 100, order: "step_no asc" });
  650. if (res.code === 200) {
  651. stepList.value = res.data.list || [];
  652. }
  653. } catch (error) {
  654. console.error("获取步骤列表失败", error);
  655. }
  656. };
  657. const openStepEditDialog = (row) => {
  658. isStepEdit.value = !!row;
  659. if (row) {
  660. stepFormData.value = { ...row };
  661. } else {
  662. stepFormData.value = {
  663. id: null,
  664. taskId: currentTaskId.value,
  665. stepNo: stepList.value.length + 1,
  666. title: "",
  667. description: "",
  668. image: "",
  669. requireUpload: 1
  670. };
  671. }
  672. stepEditDialogVisible.value = true;
  673. if (stepFormRef.value) {
  674. stepFormRef.value.clearValidate();
  675. }
  676. };
  677. // 步骤素材选择器
  678. const openStepMaterialPicker = () => {
  679. stepMaterialPickerVisible.value = true;
  680. };
  681. const handleStepMaterialSelect = (material) => {
  682. stepFormData.value.image = material.url;
  683. };
  684. const handleStepSubmit = async () => {
  685. if (!stepFormRef.value) return;
  686. await stepFormRef.value.validate(async (valid) => {
  687. if (!valid) return;
  688. stepSubmitLoading.value = true;
  689. try {
  690. const api = isStepEdit.value ? updateTaskStep : createTaskStep;
  691. // 后端期望 { id, data: {...} } 格式
  692. const { id } = stepFormData.value;
  693. const data = {
  694. taskId: stepFormData.value.taskId || currentTaskId.value,
  695. stepNo: stepFormData.value.stepNo,
  696. title: stepFormData.value.title,
  697. description: stepFormData.value.description,
  698. image: stepFormData.value.image,
  699. requireUpload: stepFormData.value.requireUpload
  700. };
  701. const params = isStepEdit.value ? { id, data } : { data };
  702. const res = await api(params);
  703. if (res.code === 200) {
  704. ElNotification.success(isStepEdit.value ? "更新成功" : "创建成功");
  705. stepEditDialogVisible.value = false;
  706. getStepList();
  707. } else {
  708. ElNotification.error(res.msg || (isStepEdit.value ? "更新失败" : "创建失败"));
  709. }
  710. } catch (error) {
  711. ElNotification.error(isStepEdit.value ? "更新失败" : "创建失败");
  712. } finally {
  713. stepSubmitLoading.value = false;
  714. }
  715. });
  716. };
  717. const handleDeleteStep = async (row) => {
  718. try {
  719. await ElMessageBox.confirm("确认删除该步骤吗?", "提示", {
  720. type: "warning",
  721. confirmButtonText: "确定",
  722. cancelButtonText: "取消"
  723. });
  724. const res = await deleteTaskStep({ id: row.id });
  725. if (res.code === 200) {
  726. ElNotification.success("删除成功");
  727. getStepList();
  728. } else {
  729. ElNotification.error(res.msg || "删除失败");
  730. }
  731. } catch (error) {
  732. if (error !== "cancel" && error !== "close") {
  733. ElNotification.error("删除失败");
  734. }
  735. }
  736. };
  737. // ==================== 审核样例相关方法 ====================
  738. const openExampleDialog = async (row) => {
  739. currentTaskId.value = row.id;
  740. exampleDialogVisible.value = true;
  741. await getExampleList();
  742. };
  743. const getExampleList = async () => {
  744. try {
  745. const res = await getTaskExampleList({ taskId: currentTaskId.value, pageSize: 100, order: "sort asc, id asc" });
  746. if (res.code === 200) {
  747. exampleList.value = res.data.list || [];
  748. }
  749. } catch (error) {
  750. console.error("获取审核样例列表失败", error);
  751. }
  752. };
  753. const openExampleEditDialog = (row) => {
  754. isExampleEdit.value = !!row;
  755. if (row) {
  756. exampleFormData.value = { ...row };
  757. } else {
  758. exampleFormData.value = {
  759. id: null,
  760. taskId: currentTaskId.value,
  761. image: "",
  762. description: "",
  763. sort: 0
  764. };
  765. }
  766. exampleEditDialogVisible.value = true;
  767. if (exampleFormRef.value) {
  768. exampleFormRef.value.clearValidate();
  769. }
  770. };
  771. // 审核样例素材选择器
  772. const openExampleMaterialPicker = () => {
  773. exampleMaterialPickerVisible.value = true;
  774. };
  775. const handleExampleMaterialSelect = (material) => {
  776. exampleFormData.value.image = material.url;
  777. };
  778. const handleExampleSubmit = async () => {
  779. if (!exampleFormRef.value) return;
  780. await exampleFormRef.value.validate(async (valid) => {
  781. if (!valid) return;
  782. exampleSubmitLoading.value = true;
  783. try {
  784. const api = isExampleEdit.value ? updateTaskExample : createTaskExample;
  785. const { id } = exampleFormData.value;
  786. const data = {
  787. taskId: exampleFormData.value.taskId || currentTaskId.value,
  788. image: exampleFormData.value.image,
  789. description: exampleFormData.value.description,
  790. sort: exampleFormData.value.sort
  791. };
  792. const params = isExampleEdit.value ? { id, data } : { data };
  793. const res = await api(params);
  794. if (res.code === 200) {
  795. ElNotification.success(isExampleEdit.value ? "更新成功" : "创建成功");
  796. exampleEditDialogVisible.value = false;
  797. getExampleList();
  798. } else {
  799. ElNotification.error(res.msg || (isExampleEdit.value ? "更新失败" : "创建失败"));
  800. }
  801. } catch (error) {
  802. ElNotification.error(isExampleEdit.value ? "更新失败" : "创建失败");
  803. } finally {
  804. exampleSubmitLoading.value = false;
  805. }
  806. });
  807. };
  808. const handleDeleteExample = async (row) => {
  809. try {
  810. await ElMessageBox.confirm("确认删除该审核样例吗?", "提示", {
  811. type: "warning",
  812. confirmButtonText: "确定",
  813. cancelButtonText: "取消"
  814. });
  815. const res = await deleteTaskExample({ id: row.id });
  816. if (res.code === 200) {
  817. ElNotification.success("删除成功");
  818. getExampleList();
  819. } else {
  820. ElNotification.error(res.msg || "删除失败");
  821. }
  822. } catch (error) {
  823. if (error !== "cancel" && error !== "close") {
  824. ElNotification.error("删除失败");
  825. }
  826. }
  827. };
  828. </script>
  829. <style scoped>
  830. .operation {
  831. display: inline-block;
  832. vertical-align: middle;
  833. }
  834. .text-success {
  835. color: #67c23a;
  836. font-weight: bold;
  837. }
  838. .step-header {
  839. margin-bottom: 16px;
  840. }
  841. .icon-upload-wrapper {
  842. display: flex;
  843. align-items: flex-start;
  844. gap: 10px;
  845. }
  846. .icon-actions {
  847. display: flex;
  848. flex-direction: column;
  849. gap: 8px;
  850. }
  851. .icon-uploader {
  852. border: 1px dashed #d9d9d9;
  853. border-radius: 6px;
  854. cursor: pointer;
  855. overflow: hidden;
  856. transition: border-color 0.3s;
  857. }
  858. .icon-uploader:hover {
  859. border-color: #409eff;
  860. }
  861. .icon-uploader :deep(.el-upload) {
  862. width: 80px;
  863. height: 80px;
  864. display: flex;
  865. align-items: center;
  866. justify-content: center;
  867. }
  868. .icon-preview-img {
  869. width: 80px;
  870. height: 80px;
  871. }
  872. .icon-uploader-icon {
  873. font-size: 24px;
  874. color: #8c939d;
  875. }
  876. .icon-url-input {
  877. margin-top: 10px;
  878. width: 100%;
  879. }
  880. .upload-tip {
  881. font-size: 12px;
  882. color: #909399;
  883. margin-top: 5px;
  884. }
  885. .step-image-wrapper {
  886. display: flex;
  887. gap: 10px;
  888. width: 100%;
  889. }
  890. .step-image-preview {
  891. display: flex;
  892. align-items: flex-end;
  893. gap: 10px;
  894. margin-top: 10px;
  895. }
  896. .form-tip {
  897. color: #909399;
  898. font-size: 12px;
  899. line-height: 1.5;
  900. margin-top: 4px;
  901. }
  902. .text-muted {
  903. color: #c0c4cc;
  904. font-size: 12px;
  905. }
  906. .example-header {
  907. margin-bottom: 16px;
  908. display: flex;
  909. align-items: center;
  910. gap: 16px;
  911. }
  912. .example-tip {
  913. color: #909399;
  914. font-size: 12px;
  915. }
  916. </style>