index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <div class="page">
  3. <el-card shadow="never">
  4. <el-form :model="tableData.param" ref="queryRef" inline label-width="68px">
  5. <!-- 关键字 -->
  6. <el-form-item :label="$t('message.device.formI18nLabel.keyword')" prop="name">
  7. <el-input v-model="tableData.param.name" :placeholder="$t('message.device.formI18nPlaceholder.keyword')" clearable style="width: 150px" @keyup.enter.native="typeList" />
  8. </el-form-item>
  9. <!-- 类型 -->
  10. <el-form-item :label="$t('message.device.formI18nLabel.type')" prop="deviceType" style="width: 180px">
  11. <el-select v-model="tableData.param.deviceType" :placeholder="$t('message.device.formI18nPlaceholder.type')" clearable style="width: 240px" @keyup.enter.native="typeList">
  12. <!-- 网关 -->
  13. <el-option :label="$t('message.device.formI18nOption.gateway')" :value="'网关'" />
  14. <!-- 设备 -->
  15. <el-option :label="$t('message.device.formI18nOption.device')" :value="'设备'" />
  16. <!-- 子设备 -->
  17. <el-option :label="$t('message.device.formI18nOption.subDevice')" :value="'子设备'" />
  18. <!-- <el-option label="直连设备" :value="'设备'" />
  19. <el-option label="网关设备" :value="'网关'" /> -->
  20. </el-select>
  21. </el-form-item>
  22. <!-- 状态 -->
  23. <el-form-item :label="$t('message.device.formI18nLabel.status')" prop="status" style="width: 180px">
  24. <el-select v-model="tableData.param.status" :placeholder="$t('message.device.formI18nPlaceholder.status')" clearable style="width: 240px">
  25. <!-- 已启用 -->
  26. <el-option :label="$t('message.device.formI18nOption.on')" :value="1" />
  27. <!-- 未启用 -->
  28. <el-option :label="$t('message.device.formI18nOption.off')" :value="0" />
  29. </el-select>
  30. </el-form-item>
  31. <!-- <el-form-item label="创建时间" prop="dateRange">-->
  32. <!-- <el-date-picker v-model="tableData.param.dateRange" style="width: 240px" value-format="YYYY-MM-DD" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>-->
  33. <!-- </el-form-item>-->
  34. <el-form-item>
  35. <!-- 查询 -->
  36. <el-button type="primary" class="ml10" @click="typeList">
  37. <el-icon>
  38. <ele-Search />
  39. </el-icon>
  40. {{ $t('message.formI18nButton.query') }}
  41. </el-button>
  42. <!-- 重置 -->
  43. <!-- <el-button @click="resetQuery(queryRef)">
  44. <el-icon>
  45. <ele-Refresh />
  46. </el-icon>
  47. {{ $t('iotmanagerI18n.formI18nButton.reset') }}
  48. </el-button> -->
  49. <!-- 新增产品 -->
  50. <el-button type="primary" class="ml10" @click="onOpenAddDic" v-auth="'add'">
  51. <el-icon>
  52. <ele-FolderAdd />
  53. </el-icon>
  54. {{ $t('message.device.formI18nButton.addProduct') }}
  55. </el-button>
  56. <!-- 删除 -->
  57. <el-button type="info" class="ml10" @click="onRowDel()" v-auth="'del'">
  58. <el-icon>
  59. <ele-Delete />
  60. </el-icon>
  61. {{ $t('message.formI18nButton.delete') }}
  62. </el-button>
  63. </el-form-item>
  64. </el-form>
  65. <el-table :data="tableData.data" style="width: 100%" @selection-change="handleSelectionChange" v-loading="tableData.loading">
  66. <el-table-column type="selection" width="55" align="center" />
  67. <el-table-column label="标识" prop="key" min-width="130" show-overflow-tooltip v-col="'key'">
  68. <template #default="{ row }"><copy :text="row.key"></copy></template>
  69. </el-table-column>
  70. <el-table-column label="名称" prop="name" min-width="160" show-overflow-tooltip v-col="'name'" />
  71. <el-table-column label="分类" prop="categoryName" align="center" width="140" show-overflow-tooltip v-col="'categoryName'" />
  72. <!-- <el-table-column label="消息协议" prop="messageProtocol" align="center" min-width="150" show-overflow-tooltip v-col="'messageProtocol'" />-->
  73. <el-table-column label="接入方式" prop="transportProtocol" min-width="120" align="center" show-overflow-tooltip v-col="'transportProtocol'" />
  74. <el-table-column label="类型" prop="deviceType" min-width="90" align="center" show-overflow-tooltip v-col="'deviceType'" />
  75. <el-table-column prop="status" label="状态" min-width="90" align="center" v-col="'status'">
  76. <template #default="scope">
  77. <el-tag type="success" size="small" v-if="scope.row.status">已启用</el-tag>
  78. <el-tag type="info" size="small" v-else>未启用</el-tag>
  79. </template>
  80. </el-table-column>
  81. <el-table-column label="操作" width="150" align="center" fixed="right">
  82. <template #default="scope">
  83. <router-link :to="'/iotmanager/device/product/detail/' + scope.row.key" class="link-type" style="padding-right: 12px; font-size: 12px; color: #409eff">
  84. <span>详情</span>
  85. </router-link>
  86. <router-link :to="{ path: '/iotmanager/device/instance', query: { productKey: scope.row.key } }" class="link-type" style="padding-right: 12px; font-size: 12px; color: #409eff">设备管理</router-link>
  87. <!-- <el-button size="small" text type="warning" @click="onOpenEditDic(scope.row)" v-auth="'edit'">修改</el-button>-->
  88. <el-button size="small" text type="info" @click="onRowDel(scope.row)" v-auth="'del'">删除</el-button>
  89. </template>
  90. </el-table-column>
  91. </el-table>
  92. <pagination v-show="tableData.total > 0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="typeList" />
  93. </el-card>
  94. <EditDic ref="editDicRef" @typeList="typeList" />
  95. </div>
  96. </template>
  97. <script lang="ts">
  98. import { toRefs, reactive, onMounted, ref, defineComponent } from "vue";
  99. import { ElMessageBox, ElMessage, FormInstance } from "element-plus";
  100. import EditDic from "./component/editPro.vue";
  101. import api from "/@/api/device";
  102. // 定义接口来定义对象的类型
  103. interface TableDataRow {
  104. id: number;
  105. key: string;
  106. name: string;
  107. deviceType: string;
  108. status: number;
  109. desc: string;
  110. createBy: string;
  111. }
  112. interface TableDataState {
  113. keys: string[];
  114. tableData: {
  115. data: Array<TableDataRow>;
  116. total: number;
  117. loading: boolean;
  118. param: {
  119. pageNum: number;
  120. pageSize: number;
  121. name: string;
  122. deviceType: string;
  123. status: string;
  124. dateRange: string[];
  125. };
  126. };
  127. }
  128. export default defineComponent({
  129. name: "deviceproduct",
  130. components: { EditDic },
  131. setup() {
  132. const addDicRef = ref();
  133. const editDicRef = ref();
  134. const queryRef = ref();
  135. const state = reactive<TableDataState>({
  136. keys: [],
  137. tableData: {
  138. data: [],
  139. total: 0,
  140. loading: false,
  141. param: {
  142. pageNum: 1,
  143. pageSize: 20,
  144. status: "",
  145. name: "",
  146. deviceType: "",
  147. dateRange: [],
  148. },
  149. },
  150. });
  151. // 初始化表格数据
  152. const initTableData = () => {
  153. typeList();
  154. };
  155. const typeList = () => {
  156. state.tableData.loading = true;
  157. api.product
  158. .getList(state.tableData.param)
  159. .then((res: any) => {
  160. state.tableData.data = res.product;
  161. state.tableData.total = res.total;
  162. })
  163. .finally(() => (state.tableData.loading = false));
  164. };
  165. // 打开新增产品弹窗
  166. const onOpenAddDic = () => {
  167. editDicRef.value.openDialog();
  168. };
  169. // 打开修改产品弹窗
  170. const onOpenEditDic = (row: TableDataRow) => {
  171. editDicRef.value.openDialog(row);
  172. };
  173. // 删除产品
  174. const onRowDel = (row?: TableDataRow) => {
  175. let msg = "你确定要删除所选数据?";
  176. let keys: string[] = [];
  177. if (row) {
  178. msg = `此操作将永久删除产品:“${row.name}”,是否继续?`;
  179. keys = [row.key];
  180. } else {
  181. keys = state.keys;
  182. }
  183. if (keys.length === 0) {
  184. ElMessage.error("请选择要删除的数据。");
  185. return;
  186. }
  187. ElMessageBox.confirm(msg, "提示", {
  188. confirmButtonText: "确认",
  189. cancelButtonText: "取消",
  190. type: "warning",
  191. })
  192. .then(() => {
  193. api.product.delete(keys).then(() => {
  194. ElMessage.success("删除成功");
  195. typeList();
  196. });
  197. })
  198. .catch(() => {});
  199. };
  200. // 页面加载时
  201. onMounted(() => {
  202. initTableData();
  203. });
  204. /** 重置按钮操作 */
  205. const resetQuery = (formEl: FormInstance | undefined) => {
  206. if (!formEl) return;
  207. formEl.resetFields();
  208. typeList();
  209. };
  210. // 多选框选中数据
  211. const handleSelectionChange = (selection: TableDataRow[]) => {
  212. state.keys = selection.map((item) => item.key);
  213. };
  214. return {
  215. addDicRef,
  216. editDicRef,
  217. queryRef,
  218. onOpenAddDic,
  219. onOpenEditDic,
  220. onRowDel,
  221. typeList,
  222. resetQuery,
  223. handleSelectionChange,
  224. ...toRefs(state),
  225. };
  226. },
  227. });
  228. </script>