index.vue 9.6 KB

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