index.vue 7.5 KB

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