You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

390 lines
11 KiB

5 months ago
  1. <script setup>
  2. import { ref } from "vue";
  3. import { ElMessage } from "element-plus";
  4. import { ElMessageBox } from "element-plus";
  5. import axios from "axios";
  6. import moment from "moment";
  7. const titleEdit = ref(false);
  8. const raiseEdit = ref(false);
  9. const addInfo = ref(false);
  10. const deleteInfo = ref(false);
  11. //这是查询的接口
  12. const info = ref({});
  13. const getInfo = async function () {
  14. try {
  15. const result = await axios.get("http://192.168.9.117:8092/page");
  16. info.value.title = result.data.data.title;
  17. info.value.targetNumber = result.data.data.targetNumber;
  18. } catch (error) {
  19. console.log("请求失败", error);
  20. }
  21. };
  22. getInfo();
  23. //这是修改标题的接口
  24. const titleNew = ref({});
  25. const putTitle = async function () {
  26. try {
  27. // 创建一个FormData对象
  28. const formData = new FormData();
  29. // 将titleNew中的数据添加到FormData对象中
  30. for (const key in titleNew.value) {
  31. formData.append(key, titleNew.value[key]);
  32. }
  33. const result = await axios.put(
  34. "http://192.168.9.117:8092/title",
  35. formData,
  36. {
  37. headers: {
  38. "Content-Type": "multipart/form-data",
  39. },
  40. }
  41. );
  42. if (result.data.code == 10000) {
  43. ElMessage.success("修改成功");
  44. titleEdit.value = false;
  45. titleNew.value = {};
  46. getInfo(); //刷新页面
  47. }
  48. if (result.data.code == 10001) {
  49. ElMessage.error(result.data.msg);
  50. titleNew.value = {};
  51. titleEdit.value = false;
  52. }
  53. } catch (error) {
  54. console.log("请求失败", error);
  55. }
  56. };
  57. //这是修改众筹人数的接口
  58. const targetNumberNew = ref({});
  59. const putTargetNumber = async function () {
  60. try {
  61. // 创建一个FormData对象
  62. const formData = new FormData();
  63. // 将titleNew中的数据添加到FormData对象中
  64. for (const key in targetNumberNew.value) {
  65. formData.append(key, targetNumberNew.value[key]);
  66. }
  67. const result = await axios.put(
  68. "http://192.168.9.117:8092/target",
  69. formData,
  70. {
  71. headers: {
  72. "Content-Type": "multipart/form-data",
  73. },
  74. }
  75. );
  76. if (result.data.code == 10000) {
  77. ElMessage.success("修改成功");
  78. raiseEdit.value = false;
  79. targetNumberNew.value = {};
  80. getInfo(); //刷新页面
  81. }
  82. if (result.data.code == 10001) {
  83. ElMessage.error(result.data.msg);
  84. targetNumberNew.value = {};
  85. raiseEdit.value = false;
  86. }
  87. } catch (error) {
  88. console.log("请求失败", error);
  89. }
  90. };
  91. //这是查询全部数据的接口
  92. const search = ref({
  93. jwcode: "",
  94. identity: "",
  95. });
  96. const tableData = ref([]);
  97. const get = async function () {
  98. try {
  99. const result = await axios.post(
  100. "http://192.168.9.117:8092/users",
  101. search.value
  102. );
  103. tableData.value = result.data.data;
  104. } catch (error) {
  105. console.log("请求失败", error);
  106. }
  107. };
  108. get();
  109. //这是添加的接口
  110. const add = ref({});
  111. const addUser = async function () {
  112. try {
  113. const result = await axios.post(
  114. "http://192.168.9.117:8092/addUser",
  115. add.value
  116. );
  117. if (result.data.code == 10000) {
  118. ElMessage.success("修改成功");
  119. addInfo.value = false;
  120. add.value = {};
  121. get(); //刷新页面
  122. }
  123. if (result.data.code == 10001) {
  124. ElMessage.error(result.data.msg);
  125. addInfo.value = false;
  126. add.value = {};
  127. }
  128. } catch (error) {
  129. console.log("请求失败", error);
  130. }
  131. };
  132. // 这是删除的接口
  133. const idname = ref("");
  134. function deleteRow(value) {
  135. deleteInfo.value = true;
  136. console.log(value);
  137. idname.value = value;
  138. }
  139. const tureDelete = async function () {
  140. try {
  141. const result = await axios.delete(
  142. "http://192.168.9.117:8092/delUser/" + idname.value
  143. );
  144. if (result.data.code == 10000) {
  145. ElMessage.success("修改成功");
  146. deleteInfo.value = false;
  147. idname.value = {};
  148. get(); //刷新页面
  149. }
  150. if (result.data.code == 10001) {
  151. ElMessage.error(result.data.msg);
  152. deleteInfo.value = false;
  153. idname.value = {};
  154. }
  155. } catch (error) {
  156. console.log("请求失败", error);
  157. }
  158. };
  159. // 这是条件查询的接口
  160. const searchBy = ref({
  161. jwcode: "",
  162. identity: "",
  163. });
  164. const searchByJwcodeAndIdentity = async function () {
  165. try {
  166. const result = await axios.post(
  167. "http://192.168.9.117:8092/users",
  168. searchBy.value
  169. );
  170. if (result.data.code == 10000) {
  171. ElMessage.success("查询成功");
  172. searchBy.value = {};
  173. }
  174. if (result.data.code == 10001) {
  175. ElMessage.error(result.data.msg);
  176. searchBy.value = {};
  177. }
  178. tableData.value = result.data.data;
  179. } catch (error) {
  180. console.log("请求失败", error);
  181. }
  182. };
  183. function Nono() {
  184. searchBy.value = {};
  185. get();
  186. }
  187. </script>
  188. <template>
  189. <el-container>
  190. <el-main style="width: 100%">
  191. <el-card style="min-width: 70%; margin: 0 auto">
  192. <h2 style="margin-top: 0%">众筹活动界面后台</h2>
  193. <h3>修改前台展示</h3>
  194. <el-divider style="margin-top: 0%" />
  195. <div style="display: flex; align-items: center">
  196. <h4 style="margin: 0%">当前标题:</h4>
  197. <span style="color: rgb(145, 145, 145); margin-left: 20px">{{
  198. info.title
  199. }}</span>
  200. <el-button
  201. class="xiugai"
  202. type="danger"
  203. style="
  204. display: inline-block;
  205. margin-left: 20px;
  206. color: rgb(245, 62, 62);
  207. "
  208. @click="titleEdit = true"
  209. >修改</el-button
  210. >
  211. </div>
  212. <div style="display: flex; align-items: center">
  213. <h4 style="margin-bottom: 0px; margin-top: 30px">众筹目标:</h4>
  214. <span
  215. style="
  216. margin-bottom: 0px;
  217. margin-top: 30px;
  218. margin-left: 20px;
  219. color: rgb(145, 145, 145);
  220. "
  221. >{{ info.targetNumber }}</span
  222. >
  223. <el-button
  224. class="xiugai"
  225. type="danger"
  226. style="
  227. display: inline-block;
  228. margin-left: 20px;
  229. margin-top: 30px;
  230. color: rgb(245, 62, 62);
  231. "
  232. @click="raiseEdit = true"
  233. >修改</el-button
  234. >
  235. </div>
  236. </el-card>
  237. <el-card style="min-width: 70%; margin: 0 auto; margin-top: 20px">
  238. <h3>众筹用户列表</h3>
  239. <el-button type="danger" @click="addInfo = true">添加</el-button>
  240. <el-input
  241. v-model="searchBy.jwcode"
  242. style="width: 150px; margin-left: 200px"
  243. placeholder="精网号"
  244. ></el-input>
  245. <el-select
  246. v-model="searchBy.identity"
  247. style="width: 100px; margin-left: 60px"
  248. placeholder="身份"
  249. >
  250. <el-option label="真实" value="1"></el-option>
  251. <el-option label="虚拟" value="0"></el-option>
  252. </el-select>
  253. <el-button type="" @click="Nono()" style="margin-left: 40px"
  254. >重置</el-button
  255. >
  256. <el-button type="danger" @click="searchByJwcodeAndIdentity()"
  257. >查询</el-button
  258. >
  259. <el-table :data="tableData">
  260. <el-table-column
  261. prop="id"
  262. label="序号"
  263. width="300px"
  264. ></el-table-column>
  265. <el-table-column
  266. prop="jwcode"
  267. label="编号"
  268. width="300px"
  269. ></el-table-column>
  270. <el-table-column prop="identity" label="身份" width="300px">
  271. <!-- 模板内容 -->
  272. <template #default="scope">
  273. <span v-if="scope.row.identity == 1">
  274. <span>真实</span>
  275. </span>
  276. <span v-if="scope.row.identity == 0">
  277. <span>虚拟</span>
  278. </span>
  279. </template>
  280. </el-table-column>
  281. <el-table-column prop="creatTime" label="参与时间" width="700px">
  282. <template #default="scope">
  283. {{ moment(scope.row.createTime).format("YYYY-MM-DD HH:mm:ss") }}
  284. </template>
  285. </el-table-column>
  286. <el-table-column label="操作" width="px">
  287. <template #default="scope">
  288. <el-button
  289. @click="deleteRow(scope.row.jwcode)"
  290. type="text"
  291. style="color: rgb(245, 62, 62)"
  292. >删除</el-button
  293. >
  294. </template>
  295. </el-table-column>
  296. </el-table>
  297. </el-card>
  298. </el-main>
  299. </el-container>
  300. <!-- 这是添加的弹窗 -->
  301. <el-dialog v-model="addInfo" width="500">
  302. <div>
  303. <h3 style="display: inline-block; margin-right: 20px">精网号</h3>
  304. <el-input
  305. v-model="add.jwcode"
  306. placeholder="请输入精网号"
  307. style="width: 300px; display: inline-block"
  308. />
  309. </div>
  310. <div>
  311. <h3 style="display: inline-block; margin-right: 20px">身份</h3>
  312. <el-radio-group v-model="add.identity">
  313. <el-radio value="1" size="large">真实</el-radio>
  314. <el-radio value="0" size="large">虚拟</el-radio>
  315. </el-radio-group>
  316. </div>
  317. <el-button type="danger" @click="addUser()" style="margin-left: 400px"
  318. >添加</el-button
  319. >
  320. </el-dialog>
  321. <!-- 这是修改表题的弹窗 -->
  322. <el-dialog v-model="titleEdit" width="500">
  323. <div>
  324. <h3 style="display: inline-block; margin-right: 20px">输入新标题</h3>
  325. <el-input
  326. v-model="titleNew.title"
  327. placeholder="请输入新标题"
  328. style="width: 300px; display: inline-block"
  329. />
  330. </div>
  331. <el-button type="danger" @click="putTitle()" style="margin-left: 400px"
  332. >确定</el-button
  333. >
  334. </el-dialog>
  335. <!-- 这是修改众筹目标的弹窗 -->
  336. <el-dialog v-model="raiseEdit" width="500">
  337. <div>
  338. <h3 style="display: inline-block; margin-right: 20px">
  339. 输入新众筹目标为
  340. </h3>
  341. <el-input
  342. v-model="targetNumberNew.targetNumber"
  343. placeholder="请输入阿拉伯数字"
  344. style="width: 300px; display: inline-block"
  345. />
  346. </div>
  347. <el-button
  348. type="danger"
  349. @click="putTargetNumber()"
  350. style="margin-left: 400px"
  351. >确定</el-button
  352. >
  353. </el-dialog>
  354. <!-- 这是删除的弹窗 -->
  355. <el-dialog v-model="deleteInfo" width="500">
  356. <div>
  357. <h3 style="display: inline-block; margin-right: 20px">
  358. 确认删除该条信息
  359. </h3>
  360. </div>
  361. <el-button type="danger" @click="tureDelete()" style="margin-left: 400px"
  362. >确定</el-button
  363. >
  364. </el-dialog>
  365. </template>
  366. <style scoped>
  367. /* 移除 el-button 的默认样式 */
  368. .xiugai {
  369. border: none;
  370. background-color: transparent;
  371. color: #409eff; /* Element Plus 默认的主题色 */
  372. padding: 0;
  373. font-size: inherit; /* 继承父元素的字体大小 */
  374. }
  375. </style>