index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <template>
  2. <!-- 搜索工作栏 -->
  3. <ContentWrap>
  4. <el-form
  5. class="-mb-15px"
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="68px"
  10. >
  11. <el-form-item label="sop名称" prop="sopName">
  12. <el-input
  13. v-model="queryParams.sopName"
  14. placeholder="请输入sop名称"
  15. clearable
  16. @keyup.enter="handleQuery"
  17. class="!w-240px"
  18. />
  19. </el-form-item>
  20. <el-form-item label="sop类型" prop="sopType">
  21. <el-select
  22. v-model="queryParams.sopType"
  23. placeholder="请选择sop类型"
  24. clearable
  25. class="!w-240px"
  26. >
  27. <el-option
  28. v-for="dict in getIntDictOptions(DICT_TYPE.SOP_TYPE)"
  29. :key="dict.value"
  30. :label="dict.label"
  31. :value="dict.value"
  32. />
  33. </el-select>
  34. </el-form-item>
  35. <el-form-item>
  36. <el-button @click="handleQuery">
  37. <Icon icon="ep:search" class="mr-5px" />
  38. 搜索
  39. </el-button>
  40. <el-button @click="resetQuery">
  41. <Icon icon="ep:refresh" class="mr-5px" />
  42. 重置
  43. </el-button>
  44. <el-button
  45. type="primary"
  46. plain
  47. @click="openForm('create')"
  48. v-hasPermi="['iscs:sop:create']"
  49. >
  50. <Icon icon="ep:plus" class="mr-5px" />
  51. 新增
  52. </el-button>
  53. <el-button
  54. type="danger"
  55. plain
  56. :disabled="multiple"
  57. @click="handleDelete()"
  58. v-hasPermi="['iscs:sop:delete']"
  59. >
  60. <Icon icon="ep:delete" class="mr-5px" />
  61. 批量删除
  62. </el-button>
  63. </el-form-item>
  64. </el-form>
  65. </ContentWrap>
  66. <!-- 列表 -->
  67. <ContentWrap>
  68. <el-table
  69. v-loading="loading"
  70. :data="sopList"
  71. @selection-change="handleSelectionChange"
  72. style="width: 100%"
  73. >
  74. <el-table-column type="selection" width="50" align="center" fixed />
  75. <el-table-column label="ID" prop="id" align="center" width="60" fixed />
  76. <el-table-column label="sop名称" prop="sopName" width="300" fixed />
  77. <el-table-column label="sop类型" prop="sopTypeName" width="100" />
  78. <el-table-column
  79. label="所属区域"
  80. prop="workstationName"
  81. :show-overflow-tooltip="true"
  82. width="100"
  83. />
  84. <el-table-column label="设备/工艺" prop="machineryName" align="center" width="200" />
  85. <el-table-column label="启用通知" align="center" width="100">
  86. <template #default="scope">
  87. <el-switch
  88. :model-value="scope.row.enableNotifications"
  89. :active-value="1"
  90. :inactive-value="0"
  91. @update:modelValue="(val) => handleNotificationsChange(scope.row, val)"
  92. />
  93. </template>
  94. </el-table-column>
  95. <el-table-column label="启用执行计划" align="center" width="120">
  96. <template #default="scope">
  97. <el-switch
  98. :model-value="scope.row.enableExecutionPlan"
  99. :active-value="1"
  100. :inactive-value="0"
  101. @update:modelValue="(val) => handleExecutionPlanChange(scope.row, val)"
  102. @click="openForm('executPlan', scope.row.id,scope.row.sopName)"
  103. />
  104. </template>
  105. </el-table-column>
  106. <el-table-column label="下次作业开始时间" prop="nextExecutDate" width="150" />
  107. <!-- <el-table-column label="是否生效" align="center" width="120">-->
  108. <!-- <template #default="scope">-->
  109. <!-- <el-switch-->
  110. <!-- :model-value="scope.row.sopStatus"-->
  111. <!-- active-value="1"-->
  112. <!-- inactive-value="0"-->
  113. <!-- @update:modelValue="val => handleStatusChange(scope.row, val)"-->
  114. <!-- />-->
  115. <!-- </template>-->
  116. <!-- </el-table-column>-->
  117. <!-- <el-table-column label="sop内容" prop="sopContent" />-->
  118. <!-- <el-table-column label="sop状态" prop="sopStatus" align="center" />-->
  119. <!-- <el-table-column label="sop权重序号" prop="sopIndex" />-->
  120. <!-- <el-table-column label="备注" prop="remark" align="center" />-->
  121. <el-table-column label="操作" align="center" width="550" fixed="right">
  122. <template #default="{ row }">
  123. <el-button
  124. link
  125. :icon="Promotion"
  126. type="danger"
  127. @click="openForm('update', row.id)"
  128. v-hasPermi="['iscs:sop:update']"
  129. >
  130. 立即执行
  131. </el-button>
  132. <el-button
  133. link
  134. :icon="Bell"
  135. type="primary"
  136. @click="openForm('update', row.id)"
  137. v-hasPermi="['iscs:sop:update']"
  138. >
  139. 通知规则
  140. </el-button>
  141. <el-button
  142. link
  143. :icon="DocumentChecked"
  144. type="primary"
  145. @click="openForm('executPlan', row.id,row.sopName)"
  146. v-hasPermi="['iscs:sop:update']"
  147. >
  148. 执行计划
  149. </el-button>
  150. <el-button
  151. link
  152. :icon="RefreshLeft"
  153. type="primary"
  154. @click="openForm('update', row.id)"
  155. v-hasPermi="['iscs:sop:update']"
  156. >
  157. 历史作业
  158. </el-button>
  159. <el-button
  160. link
  161. :icon="Edit"
  162. type="primary"
  163. @click="openForm('update', row.id)"
  164. v-hasPermi="['iscs:sop:update']"
  165. >
  166. 修改
  167. </el-button>
  168. <el-button
  169. link
  170. type="danger"
  171. :icon="Delete"
  172. @click="handleDelete(row.id)"
  173. v-hasPermi="['iscs:sop:delete']"
  174. >
  175. 删除
  176. </el-button>
  177. </template>
  178. </el-table-column>
  179. </el-table>
  180. <!-- 分页组件 -->
  181. <Pagination
  182. v-model:limit="queryParams.pageSize"
  183. v-model:page="queryParams.pageNo"
  184. :total="total"
  185. @pagination="getList"
  186. />
  187. </ContentWrap>
  188. </template>
  189. <script lang="ts" setup>
  190. import * as SopApi from '@/api/sop'
  191. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  192. import {Promotion, DocumentChecked,Delete, Edit, Bell,RefreshLeft } from '@element-plus/icons-vue'
  193. import {updateSopEnableExecutionPlan, updateSopEnableNotification} from "@/api/sop";
  194. // 添加初始化标志位
  195. const isInitialized = ref(false)
  196. const router = useRouter()
  197. defineOptions({ name: 'SopManagement' })
  198. const message = useMessage() // 消息弹窗
  199. const { t } = useI18n() // 国际化
  200. const loading = ref(true) // 列表的加载中
  201. const sopList = ref([]) // 列表的数据
  202. const total = ref(0) // 总条数
  203. const ids = ref<number[]>([]) // 选中的数据
  204. const multiple = ref(true) // 非多个禁用
  205. const queryParams = reactive({
  206. pageNo: 1,
  207. pageSize: 10,
  208. sopName: undefined,
  209. sopType: undefined
  210. })
  211. const queryFormRef = ref() // 搜索的表单
  212. // 是否开启通知
  213. const handleNotificationsChange = async (row, val) => {
  214. if (!isInitialized.value) return
  215. const originalValue = row.enableNotifications
  216. try {
  217. // const data = {
  218. // ...row,
  219. // enableNotifications: val
  220. // }
  221. const data = {
  222. id: row.id,
  223. enableNotifications: val
  224. }
  225. console.log(data,'是什么数据')
  226. await SopApi.updateSopEnableNotification(data)
  227. ElMessage.success(val == 1 ? '已开启' : '已关闭')
  228. // 成功后更新值(防止 UI 不更新)
  229. row.enableNotifications = val
  230. } catch (err) {
  231. // 接口失败,回滚原始值
  232. row.enableNotifications = originalValue
  233. // 强制刷新 UI
  234. await nextTick()
  235. // 提示错误
  236. // ElMessage.error('状态更新失败,请重试')
  237. }
  238. }
  239. // 是否打开执行计划
  240. const handleExecutionPlanChange = async (row, val) => {
  241. if (!isInitialized.value) return
  242. const originalValue = row.enableExecutionPlan
  243. try {
  244. const data = {
  245. id:row.id,
  246. enableExecutionPlan: val
  247. }
  248. await SopApi.updateSopEnableExecutionPlan(data)
  249. ElMessage.success(val == 1 ? '已开启' : '已关闭')
  250. // 成功后更新值(防止 UI 不更新)
  251. row.enableExecutionPlan = val
  252. } catch (err) {
  253. // 接口失败,回滚原始值
  254. row.enableExecutionPlan = originalValue
  255. // 强制刷新 UI
  256. await nextTick()
  257. // 提示错误
  258. // ElMessage.error('状态更新失败,请重试')
  259. }
  260. }
  261. /** 多选框选中数据 */
  262. const handleSelectionChange = (selection: any[]) => {
  263. ids.value = selection.map((item) => item.id)
  264. multiple.value = !selection.length
  265. }
  266. /** 查询模式列表 */
  267. const getList = async () => {
  268. loading.value = true
  269. try {
  270. const data = await SopApi.getSopPage(queryParams)
  271. sopList.value = data.list
  272. total.value = data.total
  273. } finally {
  274. loading.value = false
  275. }
  276. }
  277. /** 搜索按钮操作 */
  278. const handleQuery = () => {
  279. queryParams.pageNo = 1
  280. getList()
  281. }
  282. /** 重置按钮操作 */
  283. const resetQuery = () => {
  284. queryParams.pageNo = 1
  285. queryFormRef.value.resetFields()
  286. handleQuery()
  287. }
  288. /** 添加/修改/查看操作 */
  289. const openForm = (type: string, id?: number,sopName?:string) => {
  290. if (type == 'create') {
  291. router.push({
  292. name: 'CreateSop',
  293. query: { id: id, type: 'create' }
  294. })
  295. } else if (type == 'update') {
  296. router.push({
  297. name: 'UpdateSop',
  298. query: { id: id, type: 'update' }
  299. })
  300. } else if (type == 'executPlan') {
  301. // 执行计划
  302. router.push({
  303. name: 'ExecutePlan',
  304. query: {
  305. id: id,
  306. sopName: sopName,
  307. type: 'executPlan'
  308. }
  309. })
  310. }
  311. }
  312. /** 删除按钮操作 */
  313. const handleDelete = async (id: number) => {
  314. const sopId = id || ids.value
  315. try {
  316. // 删除的二次确认
  317. await message.delConfirm()
  318. // 发起删除
  319. await SopApi.deleteSopList(sopId)
  320. message.success(t('common.delSuccess'))
  321. // 刷新列表
  322. await getList()
  323. } catch {}
  324. }
  325. /** 初始化 **/
  326. onMounted(async () => {
  327. await getList()
  328. // 数据加载完成后
  329. isInitialized.value = true
  330. })
  331. </script>
  332. <style scoped></style>