source.vue 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355
  1. <template>
  2. <div class="content-box">
  3. <div class="left">
  4. <!-- <el-icon :size="23" class="camera"><VideoCameraFilled /></el-icon> -->
  5. <span class="cameratxt">我的数据源</span>
  6. </div>
  7. <div class="scroll">
  8. <div class="middle">
  9. <div class="search-manager">
  10. <div class="filter">
  11. <div class="condition">
  12. <el-select v-model="searchInput.dsClassValue" class="sel" placeholder="数据库类型" clearable
  13. @clear="searchBtn">
  14. <el-option v-for="item in dsClass.list" :key="item.value" :label="item.label" :value="item.value" />
  15. </el-select>
  16. <el-select v-model="searchInput.connectStatus" class="sel" placeholder="连接状态" clearable
  17. @clear="searchBtn">
  18. <el-option label="正常" value="1" />
  19. <el-option label="异常" value="0" />
  20. </el-select>
  21. <el-input :clearable="true" @clear="searchBtn" v-model="searchInput.keyWord" class="sel"
  22. placeholder="数据源名称" />
  23. </div>
  24. <el-button color="rgba(0, 97, 255, 1)" type="primary" class="search" @click="searchBtn">
  25. <el-icon>
  26. <Search />
  27. </el-icon>
  28. <span>查询</span>
  29. </el-button>
  30. </div>
  31. <div>
  32. <el-button type="primary" color="rgba(0, 97, 255, 1)" plain @click="managerDSClass">数据源类别管理</el-button>
  33. </div>
  34. </div>
  35. <!-- 按钮列表 -->
  36. <div class="gongneng">
  37. <el-button type="primary" color="rgba(0, 97, 255, 1)" plain @click="addClick">新增</el-button>
  38. <!-- <el-button type="primary" color="rgba(0, 97, 255, 1)" plain @click="editClick">编辑</el-button>
  39. <el-button type="primary" color="rgba(0, 97, 255, 1)" @click="delClick" plain>删除</el-button> -->
  40. </div>
  41. </div>
  42. <div class="footer" v-loading="loading">
  43. <el-table :row-class-name="tableRowClassName" :data="tableData.list" style="width: 100%" :header-cell-style="{
  44. background: 'rgba(240, 243, 247, 1)',
  45. height: '50px',
  46. border: 0,
  47. }">
  48. <!-- <el-table-column align="center" type="selection" width="80" /> -->
  49. <el-table-column align="center" prop="dsClsName" label="类型" />
  50. <el-table-column align="center" prop="dsName" label="名称" />
  51. <el-table-column align="center" prop="dsUrl" width="390" label="连接地址" />
  52. <el-table-column align="center" prop="dsStatus" width="60" label="连接状态">
  53. <template #default="scope">
  54. <span v-if="scope.row.dsStatus == 1" class="normal">正常</span>
  55. <span v-else class="abnormal">异常</span>
  56. </template>
  57. </el-table-column>
  58. <el-table-column align="center" prop="dsDescrition" label="描述">
  59. </el-table-column>
  60. <el-table-column align="center" prop="dsCreateTime" label="创建时间" width="150">
  61. <template #default="{ row }">
  62. <span>{{
  63. dayjs(row.dsCreateTime).format("YYYY-MM-DD HH:mm:ss")
  64. }}</span>
  65. </template>
  66. </el-table-column>
  67. <el-table-column align="center" prop="dsUpdateTime" label="修改时间" width="150"><template #default="{ row }">
  68. <span>{{
  69. dayjs(row.dsUpdateTime).format("YYYY-MM-DD HH:mm:ss")
  70. }}</span>
  71. </template>
  72. </el-table-column>
  73. <el-table-column align="center" label="操作" width="120">
  74. <template #default="scope">
  75. <div class="edit">
  76. <div class="look" @click="editClick(scope.row)">编辑</div>
  77. <el-popconfirm width="220" confirm-button-text="确认" cancel-button-text="取消" icon-color="#f89626"
  78. title="是否删除此数据源?" @confirm="deleteClick(scope.row)">
  79. <template #reference>
  80. <div class="del">删除</div>
  81. </template>
  82. </el-popconfirm>
  83. </div>
  84. </template>
  85. </el-table-column>
  86. </el-table>
  87. </div>
  88. <!-- 分页组件 -->
  89. <div class="pageSize">
  90. <div></div>
  91. <el-pagination background :current-page="tableCurrentPage" :page-size="tablePageSize"
  92. layout="total, prev, pager, next, jumper, slot" :total="tableTotal"
  93. @update:current-page="handleCurrentChange" />
  94. </div>
  95. <!-- 新增/编辑对话框 -->
  96. <el-dialog class="editDialog" v-model="editVisible" :close-on-click-modal="false" :close-on-press-escape="false"
  97. :title="titleDialog" align-center width="900" :before-close="cancelEdit" :show-close="false">
  98. <el-form ref="editRef" :model="editRuleForm" :rules="editRules" label-width="100px" class="demo-ruleForm"
  99. :size="formSize" label-position="right" status-icon v-loading.fullscreen.lock="dialog_loading"
  100. element-loading-text="正在验证数据源有效性,请等待...">
  101. <el-form-item label="类型 :" prop="dsClsId">
  102. <el-select v-model="editRuleForm.dsClsId" placeholder="请选择类型" style="width: 740px" clearable>
  103. <el-option v-for="item in dsClass.list" :key="item.value" :label="item.label" :value="item.value" />
  104. </el-select>
  105. </el-form-item>
  106. <el-form-item label="名称 :" prop="dsName">
  107. <el-input v-model="editRuleForm.dsName" placeholder="数据源名称" clearable style="width: 740px" />
  108. </el-form-item>
  109. <div v-if="titleDialog == '新增'" style="display: flex; justify-content: space-between">
  110. <!-- <span class="typeTitle">使用辅助选项请先选择类型</span> -->
  111. <el-form-item label="辅助选项 :" prop="ip">
  112. <el-input v-model="editRuleForm.ip" placeholder="数据库服务IP地址" clearable @keyup="paramsChange"
  113. @blur="paramsChange" @clear="paramsChange" ref="inputRef" maxlength="15" />
  114. </el-form-item>
  115. <el-form-item label="端口:" prop="port" style="width: 270px">
  116. <el-input v-model="editRuleForm.port" placeholder="数据库服务端口号" clearable @keyup="paramsChange"
  117. @blur="paramsChange" @clear="paramsChange" maxlength="5" />
  118. </el-form-item>
  119. <el-form-item label="数据库名称:" prop="dbname" :label-width="'130px'" style="width: 270px">
  120. <el-input v-model="editRuleForm.dbname" placeholder="数据库名称" clearable @keyup="paramsChange"
  121. @blur="paramsChange" @clear="paramsChange" maxlength="32" />
  122. </el-form-item>
  123. </div>
  124. <el-form-item label="连接地址 :" prop="dsUrl">
  125. <el-input v-model="editRuleForm.dsUrl" placeholder="数据库连接地址" :disabled="isDisabled" clearable
  126. style="width: 740px" />
  127. </el-form-item>
  128. <div class="account">
  129. <el-form-item label="数据库账号 :" prop="dsUser">
  130. <el-input v-model="editRuleForm.dsUser" placeholder="请输入数据库账号" clearable maxlength="32" />
  131. </el-form-item>
  132. <el-form-item label="数据库密码 :" prop="dsPassword">
  133. <el-input v-model="editRuleForm.dsPassword" placeholder="请输入数据库密码" clearable maxlength="32"
  134. type="password" />
  135. </el-form-item>
  136. </div>
  137. <el-form-item label="描述 :" prop="dsDescrition">
  138. <el-input v-model="editRuleForm.dsDescrition" placeholder="请输入该数据库相关简述" clearable type="textarea" :rows="5"
  139. maxlength="150" show-word-limit style="width: 740px" />
  140. </el-form-item>
  141. <el-form-item class="options">
  142. <el-button color="rgba(41, 109, 227, 1)" class="queding" type="primary"
  143. @click="confirmEdit(editRef)">确认</el-button>
  144. <el-button @click="cancelEdit(editRef)">取消</el-button>
  145. </el-form-item>
  146. </el-form>
  147. </el-dialog>
  148. <!-- 数据源类别管理对话框 -->
  149. <el-dialog v-model="managerDialogVisible" :row-class-name="tableRowClassName" align-center width="1000"
  150. title="数据源类别管理" :close-on-click-modal="false" :close-on-press-escape="false" @close="getDsClass"
  151. class="manager">
  152. <div>
  153. <div style="
  154. display: flex;
  155. justify-content: space-between;
  156. margin-bottom: 20px;
  157. ">
  158. <el-button type="primary" color="rgba(0, 97, 255, 1)" @click="dsAddModifyClass">增加</el-button>
  159. <el-input v-model="dsClassSearch" @change="dsClassNameSearch" @keyup.enter="dsClassNameSearch" size="small"
  160. placeholder="搜索数据源类别名称" style="width: 180px" clearable />
  161. </div>
  162. <el-table :data="dsClassTableData.list" stripe style="width: 100%; height: 450px;" v-loading="dsClassLoading"
  163. element-loading-text="加载中..." :header-cell-style="{
  164. background: 'rgba(240, 243, 247, 1)',
  165. height: '50px',
  166. border: 0,
  167. }">
  168. <el-table-column prop="dsClsName" label="数据源类别名称" width="180" align="center" />
  169. <el-table-column prop="dsClsDriver" label="数据源驱动" width="280" align="center" />
  170. <el-table-column prop="dsClsCreateTime" width="180" label="创建时间" align="center">
  171. <template #default="{ row }">
  172. <span>{{
  173. dayjs(row.dsClsCreateTime).format("YYYY-MM-DD HH:mm:ss")
  174. }}</span>
  175. </template>
  176. </el-table-column>
  177. <el-table-column prop="dsClsUpdateTime" width="180" label="修改时间" align="center">
  178. <template #default="{ row }">
  179. <span>{{
  180. dayjs(row.dsClsUpdateTime).format("YYYY-MM-DD HH:mm:ss")
  181. }}</span>
  182. </template>
  183. </el-table-column>
  184. <el-table-column align="center" width="120" label="操作">
  185. <template #default="scope">
  186. <div style="display: flex">
  187. <el-button size="small" @click="dsClassEditRow(scope.row)">编辑</el-button>
  188. <el-popconfirm width="220" confirm-button-text="确认" cancel-button-text="取消" icon-color="#f89626"
  189. title="是否删除此数据源类别?" @confirm="dsClassDeleteRow(scope.row)">
  190. <template #reference>
  191. <el-button size="small" type="danger">删除</el-button>
  192. </template>
  193. </el-popconfirm>
  194. </div>
  195. </template>
  196. </el-table-column>
  197. </el-table>
  198. <div class="pageSize">
  199. <span></span>
  200. <el-pagination background :current-page="dsClassCurrentPage" :page-size="dsClassPageCount"
  201. layout="total, prev, pager, next, jumper, slot" :total="dsClassTableTotal"
  202. @update:current-page="handleCurdsClassCurrentPageChangerentChange" style="margin: 20px 0" />
  203. </div>
  204. </div>
  205. </el-dialog>
  206. <!-- 新增/编辑 数据源类别 -->
  207. <el-dialog v-model="managerAddModifyDialogVisible" :row-class-name="tableRowClassName" :title="dsAddModifyTitle"
  208. :close-on-click-modal="false" :close-on-press-escape="false" width="30%" top="18vh" class="editDialog">
  209. <el-form ref="dsClassForm" :model="dsAddModifyRuleForm" :rules="dsAddModifyRules" label-width="100px"
  210. class="demo-ruleForm" :size="formSize" label-position="right" status-icon>
  211. <el-form-item label="名称 :" prop="dsClsName">
  212. <el-input v-model="dsAddModifyRuleForm.dsClsName" maxlength="64" placeholder="数据源类别名称" clearable
  213. style="width: 740px" />
  214. </el-form-item>
  215. <el-form-item label="驱动 :" prop="dsClsDriver">
  216. <el-input v-model="dsAddModifyRuleForm.dsClsDriver" maxlength="128" placeholder="数据源驱动" clearable
  217. style="width: 740px" />
  218. </el-form-item>
  219. <el-form-item class="options">
  220. <el-button color="rgba(41, 109, 227, 1)" class="queding" type="primary"
  221. @click="dsAddModifyConfirmEdit(dsClassForm)">确认</el-button>
  222. <el-button @click="dsAddModifyCancelEdit(dsClassForm)">取消</el-button>
  223. </el-form-item>
  224. </el-form>
  225. </el-dialog>
  226. </div>
  227. </div>
  228. </template>
  229. <script setup>
  230. import {
  231. ref,
  232. reactive,
  233. watch,
  234. nextTick,
  235. onBeforeMount,
  236. onUnmounted,
  237. } from "vue";
  238. // import { useRouter } from "vue-router";
  239. import { ElMessage } from "element-plus";
  240. import eds from "@/utils/eds.js";
  241. // import { Calendar } from "@element-plus/icons-vue";
  242. // import vidiconsApi from "@/api/vidicons.js";
  243. import { dayjs } from "element-plus";
  244. import lodash from "lodash";
  245. import axios from "axios";
  246. import { useStore } from "vuex";
  247. // 数据================================
  248. const store = useStore();
  249. const api = ref("");
  250. // const router = useRouter();
  251. const loading = ref(false);
  252. // 页面中数据源类别下拉列表参数
  253. const dsClass = reactive({
  254. list: [],
  255. });
  256. const dsClassTableData = reactive({
  257. list: [],
  258. });
  259. const searchInput = reactive({
  260. dsClassValue: "",
  261. connectStatus: "", // 是否数据源连接状态
  262. keyWord: "",
  263. }); // 搜索按钮数据
  264. // 编辑功能
  265. const titleDialog = ref("");
  266. const editVisible = ref(false);
  267. const isDisabled = ref(true);
  268. const editRef = ref();
  269. const editRuleForm = reactive({
  270. dsId: "", // 数据源id
  271. dsClsId: "", // 数据源类型id
  272. dsName: "", // 数据源名称
  273. dsUrl: "", // 数据库连接地址
  274. dsUser: "", // 数据库账号
  275. dsPassword: "", // 数据库密码
  276. dsDescrition: "", // 描述
  277. ip: "", // 数据库服务IP地址
  278. port: "", // 数据库服务端口号
  279. dbname: "", // 数据库名称
  280. });
  281. const inputRef = ref(null);
  282. // 表单验证
  283. const editRules = reactive({
  284. dsClsId: [
  285. {
  286. required: true,
  287. message: "类型不能为空",
  288. trigger: "blur",
  289. },
  290. ],
  291. dsName: [
  292. {
  293. required: true,
  294. message: "数据源名称不能为空",
  295. trigger: "blur",
  296. },
  297. ],
  298. dsUrl: [
  299. {
  300. required: true,
  301. message: "数据库连接地址不能为空",
  302. trigger: "blur",
  303. },
  304. ],
  305. dsUser: [
  306. {
  307. required: true,
  308. message: "数据库账号不能为空",
  309. trigger: "blur",
  310. },
  311. ],
  312. dsPassword: [
  313. {
  314. required: true,
  315. message: "数据库密码不能为空",
  316. trigger: "blur",
  317. },
  318. ],
  319. dsDescrition: [
  320. {
  321. required: true,
  322. message: "描述不能为空",
  323. trigger: "blur",
  324. },
  325. ],
  326. ip: [
  327. {
  328. required: true,
  329. message: "ip不能为空",
  330. trigger: "blur",
  331. },
  332. {
  333. // pattern: /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/,
  334. pattern:
  335. /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
  336. message: "请输入正确的IP地址",
  337. trigger: "blur",
  338. },
  339. ],
  340. port: [
  341. {
  342. required: true,
  343. message: "端口不能为空",
  344. trigger: "blur",
  345. },
  346. {
  347. pattern:
  348. /^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-3][0-9]|6553[0-5])$/,
  349. message: "端口号只能是:0到65535",
  350. trigger: "blur",
  351. },
  352. {
  353. pattern:
  354. /^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-3][0-9]|6553[0-5])$/,
  355. message: "端口号只能是:0到65535",
  356. trigger: "change",
  357. },
  358. ],
  359. dbname: [
  360. {
  361. required: true,
  362. message: "数据库名称不能为空",
  363. trigger: "blur",
  364. },
  365. {
  366. pattern: /^[a-zA-Z0-9_]+$/,
  367. message: "数据库名称只能包含字母、数字和下划线",
  368. trigger: "blur",
  369. },
  370. ],
  371. });
  372. // 编辑数据库类别对话框
  373. const dsClassLoading = ref(false);
  374. const dsClassSearch = ref("");
  375. const managerDialogVisible = ref(false); // 数据源类别对话框的显示隐藏
  376. const managerAddModifyDialogVisible = ref(false); // 新增数据源类别对话框的显示隐藏
  377. const dsClassForm = ref();
  378. const dsAddModifyTitle = ref("");
  379. const dsAddModifyRuleForm = reactive({
  380. dsClsName: "", // 数据源类别名称
  381. dsClsDriver: "", // 数据源类别驱动
  382. });
  383. const dsAddModifyRules = reactive({
  384. dsClsName: [
  385. {
  386. required: true,
  387. message: "数据源类别名称不能为空",
  388. trigger: "blur",
  389. },
  390. ],
  391. dsClsDriver: [
  392. {
  393. required: true,
  394. message: "数据库类别驱动不能为空",
  395. trigger: "blur",
  396. },
  397. {
  398. pattern: /^[a-zA-Z\.]+$/,
  399. message: "数据库名称只能包含字母和点(.)",
  400. trigger: "blur",
  401. },
  402. ],
  403. });
  404. const dsClassTableTotal = ref(0);
  405. const dsClassCurrentPage = ref(1);
  406. const dsClassPageCount = ref(10);
  407. // 查询数据源类别
  408. const managerDSClass = async () => {
  409. managerDialogVisible.value = true;
  410. dsClassLoading.value = true;
  411. let data = {
  412. currentPage: dsClassCurrentPage.value,
  413. pageCount: dsClassPageCount.value,
  414. name: dsClassSearch.value, // 数据源类别名称
  415. managerId: sessionStorage.getItem("token"),
  416. };
  417. let res = await axios({
  418. method: "get",
  419. url: api.value + "/wanzai/api/smartDataClass/queryPageSmartDataClass",
  420. headers: {
  421. token: sessionStorage.getItem("token"),
  422. user_head: sessionStorage.getItem("userhead"),
  423. },
  424. params: data,
  425. });
  426. // console.log(res, "数据源类别");
  427. if (res.data.code == 200) {
  428. dsClassLoading.value = false;
  429. dsClassTableData.list = JSON.parse(eds.decryptDes(res.data.data)).list;
  430. dsClassTableTotal.value = JSON.parse(
  431. eds.decryptDes(res.data.data)
  432. ).totalCount;
  433. } else {
  434. dsClassLoading.value = false;
  435. ElMessage({
  436. type: "error",
  437. showClose: true,
  438. message: res.data.message,
  439. center: true,
  440. });
  441. }
  442. };
  443. // 数据源类别分页
  444. const dsClassCurrentPageChange = (val) => {
  445. dsClassCurrentPage.value = val;
  446. managerDSClass();
  447. };
  448. // 编辑数据源类别
  449. const dsClassEditRow = (row) => {
  450. dsAddModifyTitle.value = "编辑数据源类别";
  451. managerAddModifyDialogVisible.value = true;
  452. dsAddModifyRuleForm.dsClsId = row.dsClsId;
  453. dsAddModifyRuleForm.dsClsName = row.dsClsName;
  454. dsAddModifyRuleForm.dsClsDriver = row.dsClsDriver;
  455. };
  456. // 删除数据源类别
  457. const dsClassDeleteRow = async (row) => {
  458. let data = {
  459. id: row.dsClsId, // 需要删除的id
  460. };
  461. let res = await axios({
  462. method: "get",
  463. url: api.value + "/wanzai/api/smartDataClass/deleteSmartDataClassById",
  464. headers: {
  465. token: sessionStorage.getItem("token"),
  466. user_head: sessionStorage.getItem("userhead"),
  467. },
  468. params: data,
  469. });
  470. // console.log(res, "删除数据源类别");
  471. if (res.data.code == 200) {
  472. managerDSClass();
  473. } else {
  474. dsClassLoading.value = false;
  475. ElMessage({
  476. type: "error",
  477. showClose: true,
  478. message: res.data.message,
  479. center: true,
  480. });
  481. }
  482. };
  483. // 数据源类别填充下拉列表
  484. const getDsClass = async () => {
  485. let data = {
  486. currentPage: 1,
  487. pageCount: 100,
  488. managerId: sessionStorage.getItem("token"),
  489. };
  490. let res = await axios({
  491. method: "get",
  492. url: api.value + "/wanzai/api/smartDataClass/queryPageSmartDataClass",
  493. headers: {
  494. token: sessionStorage.getItem("token"),
  495. user_head: sessionStorage.getItem("userhead"),
  496. },
  497. params: data,
  498. });
  499. // console.log(res, "数据源类别");
  500. if (res.data.code == 200) {
  501. dsClass.list = [];
  502. JSON.parse(eds.decryptDes(res.data.data)).list.forEach((item) => {
  503. dsClass.list.push({
  504. label: item.dsClsName,
  505. value: item.dsClsId,
  506. });
  507. });
  508. } else {
  509. ElMessage({
  510. type: "error",
  511. showClose: true,
  512. message: res.data.message,
  513. center: true,
  514. });
  515. }
  516. };
  517. // 新增/编辑 数据源类别操作
  518. const dsAddModifyConfirmEdit = (dsClassFormEl) => {
  519. if (!dsClassFormEl) return;
  520. dsClassFormEl.validate(async (valid, fields) => {
  521. if (valid) {
  522. let data = {
  523. dsClsName: dsAddModifyRuleForm.dsClsName,
  524. dsClsDriver: dsAddModifyRuleForm.dsClsDriver,
  525. managerId: sessionStorage.getItem("token"),
  526. };
  527. let url = "insertSmartDataClass";
  528. if (dsAddModifyTitle.value == "编辑数据源类别") {
  529. url = "updateSmartDataClassById";
  530. data.dsClsId = dsAddModifyRuleForm.dsClsId;
  531. }
  532. let res = await axios({
  533. method: "post",
  534. url: api.value + "/wanzai/api/smartDataClass/" + url,
  535. headers: {
  536. token: sessionStorage.getItem("token"),
  537. user_head: sessionStorage.getItem("userhead"),
  538. },
  539. data,
  540. });
  541. // console.log(res, "数据源类别");
  542. if (res.data.code == 200) {
  543. ElMessage({
  544. type: "success",
  545. showClose: true,
  546. message: res.data.message,
  547. center: true,
  548. });
  549. dsAddModifyCancelEdit();
  550. managerDSClass();
  551. // getDsClass();
  552. } else {
  553. ElMessage({
  554. type: "error",
  555. showClose: true,
  556. message: res.data.message,
  557. center: true,
  558. });
  559. }
  560. }
  561. });
  562. };
  563. // 新增数据源类别对话框按钮的点击事件
  564. const dsAddModifyClass = () => {
  565. managerAddModifyDialogVisible.value = true;
  566. dsAddModifyTitle.value = "新增数据源类别";
  567. dsClassForm.dsClsName = "";
  568. dsClassForm.dsClsDesc = "";
  569. };
  570. // 查询数据源类别
  571. const dsClassNameSearch = () => {
  572. dsClassCurrentPage.value = 1;
  573. managerDSClass();
  574. };
  575. // 新增数据源类别取消按钮
  576. const dsAddModifyCancelEdit = () => {
  577. managerAddModifyDialogVisible.value = false;
  578. dsAddModifyClearEditFormData();
  579. };
  580. // 数据源类别添加成功了,清理数据
  581. const dsAddModifyClearEditFormData = () => {
  582. dsAddModifyRuleForm.dsClsName = "";
  583. dsAddModifyRuleForm.dsClsDriver = "";
  584. };
  585. // 数据源类别分页
  586. const handleCurdsClassCurrentPageChangerentChange = (value) => {
  587. // console.log(value);
  588. dsClassCurrentPage.value = value;
  589. managerDSClass();
  590. };
  591. // 数据源参数发生变化
  592. const paramsChange = () => {
  593. if (editRuleForm.dsClsId == "") {
  594. ElMessage({
  595. type: "error",
  596. showClose: true,
  597. message: "请先选择数据库类型",
  598. center: true,
  599. });
  600. editRuleForm.ip = "";
  601. editRuleForm.port = "";
  602. editRuleForm.dbname = "";
  603. return;
  604. }
  605. if (
  606. editRuleForm.ip == "" &&
  607. editRuleForm.port == "" &&
  608. editRuleForm.dbname == ""
  609. ) {
  610. editRuleForm.dsUrl = "";
  611. return;
  612. }
  613. dsClass.list.forEach((item) => {
  614. if (item.value == editRuleForm.dsClsId) {
  615. if (item.label.toLowerCase().includes("mysql")) {
  616. editRuleForm.dsUrl =
  617. "jdbc:mysql://" +
  618. editRuleForm.ip +
  619. ":" +
  620. editRuleForm.port +
  621. "/" +
  622. editRuleForm.dbname;
  623. }
  624. }
  625. });
  626. };
  627. // 删除弹窗
  628. const selDelVisible = ref(false);
  629. // 表格数据
  630. const tableData = reactive({
  631. list: [],
  632. });
  633. const tableCurrentPage = ref(1); // 当前页
  634. const tablePageSize = ref(10); // 每页显示条数
  635. const tableTotal = ref(0); // 当前总数
  636. // 数据源列表
  637. const getList = async () => {
  638. loading.value = true;
  639. let data = {
  640. currentPage: tableCurrentPage.value,
  641. pageCount: tablePageSize.value,
  642. dsClsId: searchInput.dsClassValue,
  643. dsName: searchInput.keyWord, // 数据源名称
  644. dsStatus: searchInput.connectStatus, // 数据源状态
  645. managerId: sessionStorage.getItem("token"),
  646. };
  647. let res = await axios({
  648. method: "get",
  649. url: api.value + "/wanzai/api/smartDataClass/queryPageSmartDataSource",
  650. headers: {
  651. token: sessionStorage.getItem("token"),
  652. user_head: sessionStorage.getItem("userhead"),
  653. },
  654. params: data,
  655. });
  656. // console.log(res, "数据源");
  657. if (res.data.code == 200) {
  658. loading.value = false;
  659. tableData.list = JSON.parse(eds.decryptDes(res.data.data)).list;
  660. tableTotal.value = JSON.parse(eds.decryptDes(res.data.data)).total || 0;
  661. } else {
  662. loading.value = false;
  663. ElMessage({
  664. type: "error",
  665. showClose: true,
  666. message: res.data.message,
  667. center: true,
  668. });
  669. }
  670. };
  671. // 数据源搜索功能
  672. const searchBtn = lodash.debounce(async () => {
  673. getList();
  674. }, 300);
  675. // 添加(新增)按钮 (-------------------------------------------)
  676. const addClick = async () => {
  677. titleDialog.value = "新增";
  678. editVisible.value = true;
  679. isDisabled.value = true;
  680. clearEditFormData();
  681. };
  682. const clearEditFormData = () => {
  683. editRuleForm.dsId = "";
  684. editRuleForm.dsClsId = "";
  685. editRuleForm.dsName = "";
  686. editRuleForm.dsUrl = "";
  687. editRuleForm.dsUser = "";
  688. editRuleForm.dsPassword = "";
  689. editRuleForm.dsDescrition = "";
  690. editRuleForm.ip = "";
  691. editRuleForm.port = "";
  692. editRuleForm.dbname = "";
  693. };
  694. // 编辑按钮 (-------------------------------------------)
  695. const editClick = async (row) => {
  696. // console.log(row);
  697. titleDialog.value = "编辑";
  698. editVisible.value = true;
  699. isDisabled.value = false;
  700. // 表单赋值
  701. editRuleForm.dsId = row.dsId;
  702. editRuleForm.dsClsId = row.dsClsId;
  703. editRuleForm.dsName = row.dsName;
  704. editRuleForm.dsUrl = row.dsUrl;
  705. editRuleForm.dsUser = row.dsUser;
  706. editRuleForm.dsPassword = row.dsPassword;
  707. editRuleForm.dsDescrition = row.dsDescrition;
  708. editRuleForm.ip = row.ip;
  709. editRuleForm.port = row.port;
  710. editRuleForm.dbname = row.dbname;
  711. };
  712. // 删除按钮
  713. const deleteClick = async (row) => {
  714. // console.log(row);
  715. loading.value = true;
  716. let data = {
  717. id: row.dsId,
  718. };
  719. let res = await axios({
  720. method: "get",
  721. url: api.value + "/wanzai/api/smartDataClass/deleteSmartDataSourceById",
  722. headers: {
  723. token: sessionStorage.getItem("token"),
  724. user_head: sessionStorage.getItem("userhead"),
  725. },
  726. params: data,
  727. });
  728. // console.log(res, "删除数据源");
  729. if (res.data.code == 200) {
  730. loading.value = false;
  731. editVisible.value = false;
  732. getList();
  733. ElMessage({
  734. type: "success",
  735. showClose: true,
  736. message: res.data.message,
  737. center: true,
  738. });
  739. cancelEdit();
  740. } else {
  741. loading.value = false;
  742. ElMessage({
  743. type: "error",
  744. showClose: true,
  745. message: res.data.message,
  746. center: true,
  747. });
  748. cancelEdit();
  749. }
  750. };
  751. // 新增数据源取消按钮
  752. const cancelEdit = () => {
  753. editVisible.value = false;
  754. editRef.value.resetFields();
  755. clearEditFormData();
  756. };
  757. // 添加(新增)、编辑窗口的确定按钮事件
  758. const dialog_loading = ref(false);
  759. const confirmEdit = (formEl) => {
  760. if (!formEl) return;
  761. formEl.validate(async (valid, fields) => {
  762. dialog_loading.value = true;
  763. if (valid) {
  764. let data = {
  765. dsClsId: editRuleForm.dsClsId,
  766. dsName: editRuleForm.dsName,
  767. dsUrl: editRuleForm.dsUrl,
  768. dsUser: editRuleForm.dsUser,
  769. dsPassword: editRuleForm.dsPassword,
  770. dsDescrition: editRuleForm.dsDescrition,
  771. };
  772. let url = "insertSmartDataSource";
  773. if (titleDialog.value == "编辑") {
  774. url = "updateSmartDataSourceById";
  775. data.dsId = editRuleForm.dsId;
  776. }
  777. let res = await axios({
  778. method: "post",
  779. url: api.value + "/wanzai/api/smartDataClass/" + url,
  780. headers: {
  781. token: sessionStorage.getItem("token"),
  782. user_head: sessionStorage.getItem("userhead"),
  783. },
  784. data,
  785. });
  786. // console.log(res, "添加/修改数据源");
  787. if (res.data.code == 200) {
  788. dialog_loading.value = false;
  789. getList();
  790. ElMessage({
  791. type: "success",
  792. showClose: true,
  793. message: res.data.data,
  794. center: true,
  795. });
  796. cancelEdit();
  797. } else {
  798. dialog_loading.value = false;
  799. ElMessage({
  800. type: "error",
  801. showClose: true,
  802. message: res.data.message,
  803. center: true,
  804. });
  805. }
  806. }
  807. });
  808. };
  809. //删除按钮
  810. const delClick = async () => {
  811. selDelVisible.value = true;
  812. };
  813. // const cancelSelDel = () => {
  814. // selDelVisible.value = false;
  815. // };
  816. // 表格斑马纹颜色修改
  817. const tableRowClassName = ({ row, rowIndex }) => {
  818. if (rowIndex % 2 === 0) {
  819. return "even";
  820. } else if (rowIndex % 2 !== 0) {
  821. return "odd";
  822. }
  823. return "";
  824. };
  825. // 数据源分页
  826. const handleCurrentChange = (value) => {
  827. // console.log(value);
  828. tableCurrentPage.value = value;
  829. getList();
  830. };
  831. // 挂载前钩子
  832. onBeforeMount(async () => {
  833. api.value = store.state.user.api;
  834. getList();
  835. getDsClass();
  836. });
  837. // 卸载钩子
  838. onUnmounted(() => {
  839. // document.removeEventListener("keyup", Enters);
  840. });
  841. </script>
  842. <style scoped lang="scss">
  843. .content-box {
  844. min-width: 1000px;
  845. width: calc(100vw - 260px);
  846. height: calc(100vh - 105px);
  847. margin: 20px auto;
  848. background-color: #fff;
  849. color: #fff;
  850. display: flex;
  851. flex-direction: column;
  852. box-shadow: 0px 3px 10px rgba(0, 97, 255, 0.2);
  853. .left {
  854. // width: calc(100wh - 40px);
  855. display: flex;
  856. align-items: center;
  857. height: 60px;
  858. margin: 0 30px;
  859. border-bottom: 1px solid #ccc;
  860. color: rgb(0, 0, 0);
  861. font-size: 18px;
  862. font-weight: 600;
  863. .cameratxt {
  864. display: block;
  865. height: 60px;
  866. line-height: 60px;
  867. }
  868. .is_active {
  869. color: rgba(111, 182, 184, 1);
  870. }
  871. }
  872. .scroll {
  873. height: calc(100% - 61px);
  874. overflow: auto;
  875. }
  876. .middle {
  877. width: 96%;
  878. margin: 0 auto;
  879. color: #000;
  880. .search-manager {
  881. display: flex;
  882. justify-content: space-between;
  883. align-items: center;
  884. margin: 10px 0 0 0;
  885. // border-bottom: 1px solid rgb(231, 231, 231);
  886. .filter {
  887. display: flex;
  888. flex-wrap: wrap;
  889. align-items: center;
  890. margin: 10px 0 0 0;
  891. .search {
  892. color: #fff;
  893. }
  894. .condition {
  895. display: flex;
  896. align-items: center;
  897. margin: 10px 30px 10px 0;
  898. .sel {
  899. margin-right: 10px;
  900. width: 220px;
  901. }
  902. :deep(.el-input .el-input__inner) {
  903. font-size: 14px;
  904. }
  905. }
  906. }
  907. }
  908. .gongneng {
  909. margin: 10px 0 20px 0;
  910. span {
  911. color: #fff;
  912. }
  913. .el-button {
  914. margin-right: 10px;
  915. }
  916. }
  917. :deep(.cont) {
  918. width: 60%;
  919. margin: 20px auto;
  920. }
  921. :deep(.download) {
  922. display: flex;
  923. align-items: center;
  924. margin: 10px;
  925. }
  926. :deep(.download span) {
  927. font-size: 16px;
  928. margin-left: 20px;
  929. }
  930. :deep(.cont .el-button) {
  931. margin-left: 60px;
  932. margin-bottom: 30px;
  933. }
  934. :deep(.cont .accomplish) {
  935. width: 100%;
  936. display: flex;
  937. justify-content: center;
  938. }
  939. :deep(.cont .accomplish .el-button) {
  940. width: 50%;
  941. margin: 0;
  942. }
  943. }
  944. .footer {
  945. width: 96%;
  946. height: calc(100% - 210px);
  947. // min-height: 300px;
  948. margin: 10px auto 20px;
  949. .el-table--fit {
  950. height: 100%;
  951. :deep(.el-table__header-wrapper) {
  952. background-color: #000;
  953. font-size: 14px;
  954. tr {
  955. // color: #000;
  956. }
  957. }
  958. :deep(.el-table__row) {
  959. height: 50px;
  960. font-size: 14px;
  961. // color: #000;
  962. &:hover {
  963. td {
  964. background-color: rgba(223, 236, 254, 1);
  965. }
  966. }
  967. }
  968. :deep(.el-table__row td) {
  969. padding: 0;
  970. // border: 0;
  971. .normal {
  972. background-color: rgba(139, 195, 74, 1);
  973. color: #fff;
  974. padding: 4px;
  975. }
  976. .abnormal {
  977. background-color: rgba(212, 48, 48, 1);
  978. color: #fff;
  979. padding: 4px;
  980. }
  981. }
  982. .el-button--primary {
  983. margin-left: 5px;
  984. }
  985. :deep(.el-table__body .even) {
  986. background-color: #fff;
  987. }
  988. :deep(.el-table__body .odd) {
  989. background-color: rgba(240, 243, 247, 1);
  990. }
  991. :deep(.edit) {
  992. display: flex;
  993. align-items: center;
  994. justify-content: center;
  995. color: rgba(111, 182, 184, 1);
  996. }
  997. :deep(.look) {
  998. padding: 0 10px;
  999. cursor: pointer;
  1000. color: rgba(30, 125, 251, 1);
  1001. }
  1002. .del {
  1003. padding: 0 10px;
  1004. color: rgba(212, 48, 48, 1);
  1005. cursor: pointer;
  1006. }
  1007. // :deep(.look):hover {
  1008. // color: red;
  1009. // }
  1010. // :deep(.del):hover {
  1011. // color: red;
  1012. // }
  1013. }
  1014. }
  1015. // 编辑按钮
  1016. :deep(.editDialog) {
  1017. // height: 420px;
  1018. border-radius: 11px;
  1019. .el-dialog__header {
  1020. border-radius: 11px 11px 0 0;
  1021. background: rgba(237, 241, 245, 1);
  1022. font-weight: 600;
  1023. margin: 0;
  1024. .el-dialog__headerbtn {
  1025. outline: none;
  1026. }
  1027. }
  1028. .el-dialog__body {
  1029. padding: 30px 30px 10px 30px;
  1030. .el-form-item__content {
  1031. width: 200px;
  1032. .el-input-group__append {
  1033. background-color: rgba(222, 234, 252, 1);
  1034. color: rgba(0, 97, 255, 1);
  1035. cursor: pointer;
  1036. user-select: none;
  1037. }
  1038. }
  1039. .el-form {
  1040. .typeTitle {
  1041. display: block;
  1042. color: red;
  1043. margin: 0 0 6px 100px;
  1044. }
  1045. .el-form-item {
  1046. margin-bottom: 28px;
  1047. }
  1048. .account {
  1049. display: flex;
  1050. justify-content: space-between;
  1051. .el-form-item {
  1052. .el-form-item__content {
  1053. width: 300px;
  1054. }
  1055. .el-input {
  1056. width: 300px;
  1057. }
  1058. }
  1059. }
  1060. }
  1061. .options {
  1062. margin: 50px 20px 20px 0;
  1063. width: 100%;
  1064. .el-form-item__content {
  1065. display: flex;
  1066. flex-direction: row-reverse;
  1067. }
  1068. .queding {
  1069. color: #fff;
  1070. margin-left: 15px;
  1071. }
  1072. }
  1073. }
  1074. }
  1075. // 删除数据库
  1076. :deep(.closeAccount) {
  1077. // height: 600px;
  1078. overflow: hidden;
  1079. border-radius: 11px;
  1080. .el-dialog__header {
  1081. border-radius: 11px 11px 0 0;
  1082. background: rgba(245, 249, 255, 1);
  1083. font-weight: 600;
  1084. height: 60px;
  1085. padding: 0 20px;
  1086. line-height: 60px;
  1087. margin: 0;
  1088. border-bottom: 1px solid rgba(230, 230, 230, 1);
  1089. .el-dialog__headerbtn {
  1090. outline: none;
  1091. }
  1092. }
  1093. .el-dialog__body {
  1094. padding: 0px 20px 20px 20px;
  1095. // height: 200px;
  1096. // display: flex;
  1097. // flex-direction: column-reverse;
  1098. .content {
  1099. height: 80px;
  1100. font-size: 16px;
  1101. padding: 20px 30px;
  1102. display: flex;
  1103. img {
  1104. width: 25px;
  1105. height: 25px;
  1106. margin: 0 8px 0 0;
  1107. }
  1108. }
  1109. .option {
  1110. display: flex;
  1111. flex-direction: row-reverse;
  1112. align-items: center;
  1113. margin: 10px 0;
  1114. .queding {
  1115. margin-left: 20px;
  1116. }
  1117. }
  1118. }
  1119. }
  1120. :deep(.manager) {
  1121. // height: 420px;
  1122. border-radius: 11px;
  1123. .el-dialog__header {
  1124. border-radius: 11px 11px 0 0;
  1125. background: rgba(237, 241, 245, 1);
  1126. font-weight: 600;
  1127. margin: 0;
  1128. .el-dialog__headerbtn {
  1129. outline: none;
  1130. }
  1131. }
  1132. .el-dialog__body {
  1133. padding: 30px 30px 10px 30px;
  1134. .el-table--fit {
  1135. height: 100%;
  1136. :deep(.el-table__header-wrapper) {
  1137. background-color: #000;
  1138. font-size: 14px;
  1139. }
  1140. .el-table__row {
  1141. height: 50px;
  1142. font-size: 14px;
  1143. // color: #000;
  1144. &:hover {
  1145. td {
  1146. background-color: rgba(223, 236, 254, 1);
  1147. }
  1148. }
  1149. }
  1150. :deep(.el-table__row td) {
  1151. padding: 0;
  1152. // border: 0;
  1153. .normal {
  1154. background-color: rgba(139, 195, 74, 1);
  1155. color: #fff;
  1156. padding: 4px;
  1157. }
  1158. .abnormal {
  1159. background-color: rgba(212, 48, 48, 1);
  1160. color: #fff;
  1161. padding: 4px;
  1162. }
  1163. }
  1164. .el-button--primary {
  1165. margin-left: 5px;
  1166. }
  1167. :deep(.el-table__body .even) {
  1168. background-color: #fff;
  1169. }
  1170. :deep(.el-table__body .odd) {
  1171. background-color: rgba(240, 243, 247, 1);
  1172. }
  1173. }
  1174. }
  1175. }
  1176. .pageSize {
  1177. display: flex;
  1178. align-items: center;
  1179. justify-content: space-between;
  1180. margin: 0 30px;
  1181. span {
  1182. color: #000;
  1183. }
  1184. .el-pagination {
  1185. // width: 1600px;
  1186. :deep(.el-pagination__total) {
  1187. color: #000;
  1188. }
  1189. :deep(.el-pagination__goto) {
  1190. color: #000;
  1191. }
  1192. :deep(.el-pagination__classifier) {
  1193. color: #000;
  1194. }
  1195. :deep(.el-input__wrapper) {
  1196. border: 1px solid rgba(0, 0, 0, 1);
  1197. border-radius: 5px;
  1198. box-shadow: none;
  1199. }
  1200. :deep(.el-pager li) {
  1201. margin: 0 5px;
  1202. border: 1px solid rgba(0, 0, 0, 1);
  1203. border-radius: 5px;
  1204. background-color: transparent;
  1205. }
  1206. :deep(.el-pager li.is-active) {
  1207. // background-color: rgba(0, 97, 255, 0.8);
  1208. border: 1px solid rgba(0, 97, 255, 1);
  1209. color: rgba(0, 97, 255, 1);
  1210. }
  1211. :deep(.btn-prev) {
  1212. margin-right: 5px;
  1213. border: 1px solid rgba(0, 0, 0, 1);
  1214. border-radius: 5px;
  1215. background-color: transparent;
  1216. }
  1217. :deep(.btn-next) {
  1218. margin-left: 5px;
  1219. border: 1px solid rgba(0, 0, 0, 1);
  1220. border-radius: 5px;
  1221. background-color: transparent;
  1222. }
  1223. }
  1224. }
  1225. }
  1226. .el-input {
  1227. width: 192px;
  1228. }
  1229. </style>