index.vue 8.1 KB

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