index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <template>
  2. <div class="tenant">
  3. <!-- <Banner /> -->
  4. <div class="content">
  5. <byTable
  6. :source="sourceList.data"
  7. :pagination="sourceList.pagination"
  8. :config="config"
  9. :loading="loading"
  10. highlight-current-row
  11. :selectConfig="selectConfig"
  12. :table-events="{
  13. //element talbe事件都能传
  14. select: select,
  15. }"
  16. :action-list="[
  17. {
  18. text: '添加设备',
  19. action: () => openModal('add'),
  20. },
  21. ]"
  22. @get-list="getList"
  23. >
  24. <template #slotName="{ item }">
  25. {{ item.createTime }}
  26. </template>
  27. </byTable>
  28. </div>
  29. <el-dialog
  30. :title="modalType == 'add' ? '添加设备' : '编辑'"
  31. v-model="dialogVisible"
  32. width="800"
  33. v-loading="loading"
  34. >
  35. <byForm
  36. :formConfig="formConfig"
  37. :formOption="formOption"
  38. v-model="formData.data"
  39. :rules="rules"
  40. ref="byform"
  41. >
  42. </byForm>
  43. <template #footer>
  44. <el-button @click="dialogVisible = false" size="large">取 消</el-button>
  45. <el-button
  46. type="primary"
  47. @click="submitForm('byform')"
  48. size="large"
  49. :loading="submitLoading"
  50. >
  51. 确 定
  52. </el-button>
  53. </template>
  54. </el-dialog>
  55. </div>
  56. </template>
  57. <script setup>
  58. /* eslint-disable vue/no-unused-components */
  59. import { ElMessage, ElMessageBox } from "element-plus";
  60. import byTable from "@/components/byTable/index";
  61. import byForm from "@/components/byForm/index";
  62. import { computed, defineComponent, ref } from "vue";
  63. const loading = ref(false);
  64. const submitLoading = ref(false);
  65. const sourceList = ref({
  66. data: [],
  67. pagination: {
  68. total: 3,
  69. pageNum: 1,
  70. pageSize: 10,
  71. },
  72. });
  73. let dialogVisible = ref(false);
  74. let roomDialogVisible = ref(false);
  75. let modalType = ref("add");
  76. let rules = ref({
  77. tdaProductId: [
  78. { required: true, message: "请选择行业名称", trigger: ["blur", "change"] },
  79. ],
  80. productId: [
  81. { required: true, message: "请选择产品名称", trigger: ["blur", "change"] },
  82. ],
  83. deviceName: [
  84. { required: true, message: "请输入设备名称", trigger: ["blur", "change"] },
  85. ],
  86. nodeId: [
  87. { required: true, message: "请输入设备标识", trigger: ["blur", "change"] },
  88. ],
  89. secret: [
  90. { required: true, message: "请输入密钥", trigger: ["blur", "change"] },
  91. ],
  92. });
  93. const { proxy } = getCurrentInstance();
  94. const selectConfig = reactive([
  95. {
  96. label: "行业名称",
  97. prop: "flowStatus",
  98. data: [],
  99. },
  100. {
  101. label: "产品名称",
  102. prop: "flowStatus",
  103. data: [],
  104. },
  105. ]);
  106. const config = computed(() => {
  107. return [
  108. {
  109. attrs: {
  110. label: "行业名称",
  111. prop: "appName",
  112. },
  113. },
  114. {
  115. attrs: {
  116. label: "产品名称",
  117. prop: "productName",
  118. align: "center",
  119. },
  120. },
  121. {
  122. attrs: {
  123. label: "设备名称",
  124. prop: "deviceName",
  125. align: "center",
  126. },
  127. },
  128. {
  129. attrs: {
  130. label: "设备标识",
  131. prop: "nodeId",
  132. align: "center",
  133. },
  134. },
  135. {
  136. attrs: {
  137. label: "密钥",
  138. prop: "secret",
  139. align: "center",
  140. },
  141. },
  142. {
  143. attrs: {
  144. label: "操作",
  145. width: "200",
  146. align: "right",
  147. },
  148. // 渲染 el-button,一般用在最后一列。
  149. renderHTML(row) {
  150. return [
  151. {
  152. attrs: {
  153. label: "删除",
  154. type: "danger",
  155. text: true,
  156. },
  157. el: "button",
  158. click() {
  159. // 弹窗提示是否删除
  160. ElMessageBox.confirm(
  161. "此操作将永久删除该数据, 是否继续?",
  162. "提示",
  163. {
  164. confirmButtonText: "确定",
  165. cancelButtonText: "取消",
  166. type: "warning",
  167. }
  168. ).then(() => {
  169. // 删除
  170. proxy
  171. .post("/tdaDevice/delete", {
  172. id: row.id,
  173. })
  174. .then((res) => {
  175. ElMessage({
  176. message: "删除成功",
  177. type: "success",
  178. });
  179. getList();
  180. });
  181. });
  182. },
  183. },
  184. ];
  185. },
  186. },
  187. ];
  188. });
  189. let formData = reactive({
  190. data: {},
  191. treeData: [],
  192. });
  193. const formOption = reactive({
  194. inline: true,
  195. labelWidth: 100,
  196. itemWidth: 100,
  197. rules: [],
  198. });
  199. const byform = ref(null);
  200. const treeData = ref([]);
  201. const formConfig = reactive([
  202. {
  203. type: "select",
  204. prop: "copyTdaProductId",
  205. label: "行业名称",
  206. required: true,
  207. // isLoad: {
  208. // url: "/tdaApplication/page",
  209. // req: {
  210. // pageNum: 1,
  211. // pageSize: 9999,
  212. // },
  213. // labelKey: "appName",
  214. // labelVal: "id",
  215. // method: "post",
  216. // resUrl: "rows",
  217. // },
  218. },
  219. {
  220. type: "select",
  221. prop: "tdaProductId",
  222. label: "产品名称",
  223. required: true,
  224. data: [],
  225. },
  226. // isLoad: {
  227. // url: "/tdaProduct/page",
  228. // req: {
  229. // pageNum: 1,
  230. // pageSize: 9999,
  231. // },
  232. // labelKey: "name",
  233. // labelVal: "id",
  234. // method: "post",
  235. // resUrl: "rows",
  236. // },
  237. {
  238. type: "input",
  239. prop: "deviceName",
  240. label: "设备名称",
  241. required: true,
  242. },
  243. {
  244. type: "input",
  245. prop: "nodeId",
  246. label: "设备标识",
  247. required: true,
  248. },
  249. {
  250. type: "input",
  251. prop: "secret",
  252. label: "密钥",
  253. required: true,
  254. },
  255. ]);
  256. const getList = async (req) => {
  257. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  258. loading.value = true;
  259. proxy.post("/tdaDevice/page", sourceList.value.pagination).then((message) => {
  260. console.log(message);
  261. sourceList.value.data = message.rows;
  262. sourceList.value.pagination.total = message.total;
  263. setTimeout(() => {
  264. loading.value = false;
  265. }, 200);
  266. });
  267. };
  268. const openModal = () => {
  269. dialogVisible.value = true;
  270. modalType.value = "add";
  271. formData.data = {};
  272. };
  273. const selection = ref({
  274. data: [],
  275. });
  276. const select = (_selection, row) => {
  277. selection.value.data = _selection;
  278. console.log(_selection.length);
  279. };
  280. const openRoomModal = () => {
  281. roomDialogVisible.value = true;
  282. proxy
  283. .get("/tenantInfo/roleMenuTreeSelect/" + selection.value.data[0].tenantId)
  284. .then((res) => {
  285. if (res.code == 200) {
  286. treeData.value = res.menus;
  287. formData.treeData = res.checkedKeys;
  288. tree.value.setCheckedKeys(res.checkedKeys);
  289. }
  290. });
  291. };
  292. const tree = ref(null);
  293. const submitTree = () => {
  294. proxy
  295. .post("/tenantInfo/bindingMenu", {
  296. tenantId: selection.value.data[0].tenantId,
  297. menuIdList: tree.value.getCheckedKeys(),
  298. })
  299. .then((res) => {
  300. ElMessage({
  301. message: "保存成功",
  302. type: "success",
  303. });
  304. roomDialogVisible.value = false;
  305. });
  306. };
  307. const submitForm = () => {
  308. console.log(byform.value);
  309. byform.value.handleSubmit((valid) => {
  310. submitLoading.value = true;
  311. proxy.post("/tdaDevice/" + modalType.value, formData.data).then((res) => {
  312. ElMessage({
  313. message: modalType.value == "add" ? "添加成功" : "编辑成功",
  314. type: "success",
  315. });
  316. dialogVisible.value = false;
  317. submitLoading.value = false;
  318. getList();
  319. });
  320. });
  321. };
  322. const getDtl = (row) => {
  323. modalType = "edit";
  324. proxy.post("/tdaDevice/detail", { id: row.id }).then((res) => {
  325. formData.data = res;
  326. console.log(formData);
  327. dialogVisible.value = true;
  328. });
  329. };
  330. const selectData = reactive({
  331. tradeList: [],
  332. });
  333. const getSelect = () => {
  334. proxy
  335. .post("/tdaApplication/page", { pageNum: 1, pageSize: 9999 })
  336. .then((message) => {
  337. selectData.tradeList = message.rows;
  338. formConfig[0].data = selectData.tradeList.map((x) => ({
  339. title: x.appName,
  340. value: x.id,
  341. }));
  342. // formConfig[1].data = selectData.tradeList.map((x) => ({
  343. // title: x.name,
  344. // value: x.id,
  345. // }));
  346. });
  347. };
  348. watch(
  349. () => formData.data.copyTdaProductId,
  350. (val, old) => {
  351. if (val) {
  352. proxy
  353. .post("/tdaProduct/page", {
  354. pageNum: 1,
  355. pageSize: 9999,
  356. tdaApplicationId: val,
  357. })
  358. .then((res) => {
  359. formConfig[1].data = res.rows.map((x) => ({
  360. title: x.name,
  361. value: x.id,
  362. }));
  363. });
  364. }
  365. }
  366. );
  367. getList();
  368. getSelect();
  369. </script>
  370. <style lang="scss" scoped>
  371. .tenant {
  372. padding: 20px;
  373. }
  374. </style>