index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <template>
  2. <div class="project-page">
  3. <img class="background-image" :src="bgback" alt="背景图">
  4. <el-header>
  5. <myheader />
  6. </el-header>
  7. <el-main class="project-container">
  8. <div class="project-content" id="projectContent">
  9. <div class="newproject" v-show="isnew">
  10. <div class="newproject-header">
  11. {{ titlename }}
  12. <el-icon class="close-icon" @click="isnew = false">
  13. <Close />
  14. </el-icon>
  15. </div>
  16. <div class="newproject-body">
  17. <el-form>
  18. <el-row :gutter="20">
  19. <el-col :span="10">
  20. <el-form-item label="项目名称:">
  21. <el-input v-model="newproject.name" maxlength="100"></el-input>
  22. </el-form-item>
  23. </el-col>
  24. <el-col :span="11">
  25. <el-form-item label="备注:">
  26. <el-input v-model="newproject.remark" maxlength="500"></el-input>
  27. </el-form-item>
  28. </el-col>
  29. <el-col :span="3">
  30. <el-form-item>
  31. <el-button @click="opProject">确定</el-button>
  32. </el-form-item>
  33. </el-col>
  34. </el-row>
  35. </el-form>
  36. </div>
  37. </div>
  38. <div class="project-table">
  39. <div class="project-table-header">
  40. 项目集
  41. </div>
  42. <div class="table-container custom-table">
  43. <el-table border
  44. :data="projectlists"
  45. style="width: 100%;height: 100%; overflow: auto;"
  46. highlight-current-row
  47. @current-change="handleRowChange"
  48. >
  49. <el-table-column prop="name" label="项目名称"></el-table-column>
  50. <el-table-column prop="remark" label="备注"></el-table-column>
  51. <el-table-column prop="updateTime" label="修改时间" min-width="100"></el-table-column>
  52. <el-table-column prop="createTime" label="创建时间" min-width="100"></el-table-column>
  53. </el-table>
  54. </div>
  55. <div class="project-footer">
  56. <div class="project-main-pagination">
  57. <div class="custom-pagination">
  58. <el-pagination v-model:current-page="gd.currentPage" v-model:page-size="gd.pageSize"
  59. :page-sizes="[5, 10, 20, 50]" background size="default" layout="prev, slot, sizes, pager, next"
  60. :total="parseInt(gd.total)" class="mt-4" @size-change="handleSizeChange"
  61. @current-change="handleCurrentChange">
  62. <template #default>
  63. <span style="color: #FFFFFF;">总计 {{ gd.total }}</span>
  64. </template>
  65. </el-pagination>
  66. </div>
  67. </div>
  68. <div class="custom-btn">
  69. <el-button @click="addone">新增</el-button>
  70. <el-button @click="editSelected">编辑</el-button>
  71. <el-button @click="deleteSelected">删除</el-button>
  72. <el-button @click="confirmSelected">打开</el-button>
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. </el-main>
  78. </div>
  79. </template>
  80. <script setup>
  81. import myheader from '@/components/layout/header.vue'
  82. import { RouterView, RouterLink, useRouter, useRoute } from "vue-router"
  83. import { request, enPassword } from "@/utils/request";
  84. import { ElMessage, ElMessageBox } from 'element-plus'
  85. import { Close } from '@element-plus/icons-vue';
  86. import { useProjectStore } from '@/store/project'
  87. import bgback from "@/assets/img/project-bg.png"
  88. const router = useRouter();
  89. // 获取路由实例
  90. const route = useRoute()
  91. const projectStore = useProjectStore()
  92. const isnew = ref(true)
  93. const newproject = ref({
  94. name: '',
  95. remark: ''
  96. })
  97. let gd = ref({
  98. total: 1,
  99. currentPage: 1,
  100. pageSize:5,
  101. searchtag: ''
  102. })
  103. const projectlists = ref()
  104. const currentRow = ref()
  105. const titlename = ref('新建项目')
  106. const handleSizeChange = (newSize) => {
  107. gd.value.pageSize = newSize;
  108. gd.value.currentPage = 1;
  109. getprojectlist();
  110. }
  111. const handleCurrentChange=(val)=>{
  112. getprojectlist();
  113. }
  114. const handleRowChange = (val) => {
  115. console.log("当前行:",val)
  116. currentRow.value = val;
  117. }
  118. const getprojectlist = () => {
  119. const params = {
  120. transCode: 'AC00001',
  121. count: gd.value.pageSize,
  122. page: gd.value.currentPage,
  123. searchtag: gd.value.searchtag,
  124. }
  125. request(params)
  126. .then((res) => {
  127. // console.log(res);
  128. gd.value.total = res.total;
  129. projectlists.value=res.rows.map((item) =>({
  130. ...item,
  131. updateTime: item.updateTime.split(' +')[0],
  132. createTime: item.createTime.split(' +')[0],
  133. }))
  134. })
  135. .catch((err) => {
  136. console.error(err);
  137. ElMessage.error(err.returnMsg)
  138. })
  139. };
  140. const opProject = () => {
  141. if(titlename.value ==='新建项目'){
  142. addProject();
  143. }else {
  144. editProject();
  145. }
  146. }
  147. // 新增
  148. const addone = () => {
  149. isnew.value = true;
  150. titlename.value = '新建项目';
  151. }
  152. const addProject = () => {
  153. const params = {
  154. transCode: 'AC00002',
  155. name: newproject.value.name,
  156. remark: newproject.value.remark,
  157. };
  158. request(params)
  159. .then((res) => {
  160. console.log(res);
  161. ElMessage.success('添加成功');
  162. // isnew.value = false;
  163. getprojectlist();
  164. })
  165. .catch((err) => {
  166. ElMessage.error(err.returnMsg);
  167. });
  168. };
  169. // 编辑选中行
  170. const editSelected = () => {
  171. if (!currentRow.value) {
  172. ElMessage.warning("请选择一个项目")
  173. return
  174. }
  175. isnew.value = true;
  176. titlename.value = '编辑项目';
  177. }
  178. const editProject = () => {
  179. const pid = currentRow.value.pid
  180. const params = {
  181. transCode: 'AC00002',
  182. pid:pid,
  183. name: newproject.value.name,
  184. remark: newproject.value.remark,
  185. };
  186. request(params)
  187. .then((res) => {
  188. console.log(res);
  189. ElMessage.success('编辑成功');
  190. // isnew.value = false;
  191. getprojectlist();
  192. })
  193. .catch((err) => {
  194. ElMessage.error(err.returnMsg);
  195. });
  196. }
  197. // 删除选中行
  198. const deleteSelected = () => {
  199. ElMessageBox.confirm(
  200. "确定要删除选中的项目吗?", // "确定要删除选中的项目吗?"
  201. "提示", // "提示"
  202. {
  203. confirmButtonText: "确定", // "确定"
  204. cancelButtonText: "取消", // "取消"
  205. type: 'warning'
  206. }
  207. ).then(() => {
  208. const selectedIds = currentRow.value.pid;
  209. // console.log('删除的项目ID:', selectedIds)
  210. const params = {
  211. transCode: 'AC00003',
  212. pid: selectedIds
  213. }
  214. request(params)
  215. .then((res) => {
  216. ElMessage.success("删除成功") // "删除成功"
  217. currentRow.value = ''
  218. getprojectlist()
  219. })
  220. .catch((err) => {
  221. ElMessage.error(err.returnMsg || "删除失败") // "删除失败"
  222. console.log(err)
  223. })
  224. }).catch(() => {
  225. ElMessage.info("已取消删除") // "已取消删除"
  226. })
  227. }
  228. const confirmSelected = () => {
  229. if (!currentRow.value) {
  230. ElMessage.warning("请选择一个项目")
  231. return
  232. }
  233. // 获取选中项的pid
  234. const pid = currentRow.value.pid
  235. // console.log('选中的项目:', currentRow.value)
  236. projectStore.setpid(pid)
  237. projectStore.setProjectInfo({
  238. name: currentRow.value.name,
  239. remark: currentRow.value.remark,
  240. })
  241. router.push({
  242. path: '/',
  243. })
  244. }
  245. onMounted(() => {
  246. getprojectlist();
  247. });
  248. </script>
  249. <style scoped>
  250. .project-page {
  251. width: 100%;
  252. min-width: 1400px;
  253. min-height: 700px;
  254. height: 100vh;
  255. overflow: hidden;
  256. position: relative;
  257. /* 关键:为子元素绝对定位提供参照 */
  258. }
  259. .background-image {
  260. position: absolute;
  261. /* 脱离文档流 */
  262. top: 0;
  263. left: 0;
  264. width: 100%;
  265. height: 100%;
  266. object-fit: fill;
  267. /* 或 contain,根据需求选择 */
  268. object-position: center;
  269. z-index: 0;
  270. /* 置于底层 */
  271. }
  272. .project-container {
  273. position: relative;
  274. /* 关键:确保内容在背景上方 */
  275. z-index: 1;
  276. /* 高于背景图的层级 */
  277. display: flex;
  278. justify-content: center;
  279. align-items: center;
  280. width: 100%;
  281. height: calc(100vh - 70px);
  282. min-height: 630px;
  283. }
  284. .project-content {
  285. width: 80%;
  286. height: 70%;
  287. position: relative;
  288. border: 1px solid transparent;
  289. border-image: linear-gradient(to right, #0075FF, #00FFD8, #00FFD8) 1;
  290. }
  291. .newproject {
  292. width: 100%;
  293. height: 15%;
  294. padding: 24px;
  295. .newproject-header{
  296. font-size: 20px;
  297. color: #2CFFFF;
  298. padding-bottom: 10px;
  299. display: flex;
  300. justify-content: space-between; /* 标题和图标两端对齐 */
  301. align-items: center; /* 垂直居中 */
  302. }
  303. .newproject-body {
  304. width: 100%;
  305. padding-left: 5px;
  306. :deep(.el-form-item__label) {
  307. color: #2CFFFF;
  308. }
  309. .el-button {
  310. width: 100%;
  311. background: linear-gradient( 355deg, #00ABFF 0%, #023187 100%);
  312. border-radius: 0px 0px 0px 0px;
  313. border: 2px solid #52C6FF;
  314. color: #FFFFFF;
  315. }
  316. }
  317. }
  318. .close-icon {
  319. cursor: pointer; /* 鼠标悬停时显示手型 */
  320. transition: color 0.3s;
  321. }
  322. .close-icon:hover {
  323. color: #ff4d4f; /* 悬停时红色 */
  324. }
  325. .project-table {
  326. width: 100%;
  327. height: 85%;
  328. display: flex;
  329. flex-direction: column;
  330. overflow: auto;
  331. padding: 24px;
  332. }
  333. .project-table-header {
  334. font-size: 20px;
  335. color: #2CFFFF;
  336. padding-bottom: 10px;
  337. }
  338. .table-container {
  339. width: 100%;
  340. height: 85%;
  341. }
  342. .project-footer {
  343. width: 100%;
  344. padding:10px;
  345. display: flex;
  346. justify-content: space-between;
  347. }
  348. </style>