index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <div class="mainContentBox">
  3. <avue-crud
  4. ref="crudRef"
  5. v-model:search="search"
  6. v-model="form"
  7. :data="data"
  8. :option="option"
  9. v-model:page="page"
  10. @row-save="createRow"
  11. @row-update="updateRow"
  12. @row-del="deleteRow"
  13. @search-change="searchChange"
  14. @search-reset="resetChange"
  15. @size-change="dataList"
  16. @current-change="dataList"
  17. @selection-change="selectionChange"
  18. >
  19. <template #menu="{row}">
  20. <el-button
  21. icon="el-icon-setting"
  22. text
  23. @click="openDialog(row.deviceType)"
  24. type="primary"
  25. size="small">模型</el-button>
  26. </template>
  27. <template #protocolState="{row}">
  28. <el-switch
  29. active-value= '1'
  30. inactive-value= '0'
  31. width="60"
  32. inline-prompt
  33. active-text="启用"
  34. inactive-text="禁用"
  35. v-model="row.protocolState"
  36. @click="changeItem(row)"
  37. class="ml-2"
  38. style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
  39. />
  40. </template>
  41. </avue-crud>
  42. <el-dialog
  43. v-model="dialog.visible"
  44. :title="dialog.title"
  45. width="60%"
  46. @close="dialog.visible = false"
  47. >
  48. <model-page :deviceType="choiceDeviceType"></model-page>
  49. </el-dialog>
  50. </div>
  51. </template>
  52. <script setup>
  53. import { ref, getCurrentInstance } from "vue";
  54. import { useCrud } from "@/hooks/userCrud";
  55. import {updateProtocol} from "@/api/device";
  56. import { useCommonStoreHook } from "@/store";
  57. import dictDataUtil from "@/common/configs/dictDataUtil";
  58. import ModelPage from "./components/model-page.vue";
  59. const { isShowTable, tableType } = toRefs(useCommonStoreHook());
  60. const test = () => {
  61. isShowTable.value = true;
  62. tableType.value = tableType.value == 1 ? 2 : 1;
  63. };
  64. const loading = ref(false); // 加载状态
  65. // 传入一个url,后面不带/
  66. const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  67. useCrud({
  68. dataListUrl: "/api/v1/device/protocolPage",
  69. });
  70. const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } = Methords; //增删改查
  71. const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
  72. const { checkBtnPerm, downloadTemplate, exportData } = Utils; //按钮权限等工具
  73. const crudRef = ref(null); //crudRef.value 获取avue-crud对象
  74. const changeItem =(row) => {
  75. updateProtocol({state: row.protocolState,deviceType: row.deviceType}).then((data)=>{
  76. if(data.code === '200'){
  77. ElMessage.success(data.msg);
  78. dataList()
  79. }else{
  80. ElMessage.error(data.msg);
  81. }
  82. })
  83. }
  84. const choiceDeviceType = ref(null)
  85. const dialog = reactive({
  86. title: "模型",
  87. visible: false,
  88. });
  89. const openDialog = (type) =>{
  90. dialog.visible = true
  91. choiceDeviceType.value = type
  92. }
  93. // 设置表格列或者其他自定义的option
  94. option.value = Object.assign(option.value, {
  95. delBtn: false,
  96. selection: true,
  97. addBtn: false,
  98. editBtn: false,
  99. viewBtn: false,
  100. searchBtn: false,
  101. menuTitle: "模型设置",
  102. column: [
  103. {
  104. label: "设备类型",
  105. prop: "deviceType",
  106. type: "select",
  107. overHidden: true,
  108. dicUrl:
  109. dictDataUtil.request_url +
  110. dictDataUtil.TYPE_CODE.device_type,
  111. props: {
  112. label: "dictLabel",
  113. value: "dictValue",
  114. },
  115. rules: [
  116. {
  117. required: true,
  118. message: "设备类型不能为空",
  119. trigger: "trigger",
  120. },
  121. ],
  122. },
  123. {
  124. label: "协议状态",
  125. prop: "protocolState",
  126. slot: true,
  127. },
  128. {
  129. label: "更新时间",
  130. prop: "updated",
  131. overHidden: true,
  132. },
  133. {
  134. label: "更新人",
  135. prop: "updator",
  136. overHidden: true,
  137. },
  138. ],
  139. });
  140. onMounted(() => {
  141. search.value.protocol = "1"
  142. // console.log("crudRef", crudRef)
  143. dataList();
  144. });
  145. </script>