index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <div class="school-manage">
  3. <Block class="header-block tw-flex tw-items-center tw-justify-between">
  4. <a-form layout="inline">
  5. <a-form-item label="学校名称">
  6. <a-input v-model:value="query.name"></a-input>
  7. </a-form-item>
  8. <a-form-item>
  9. <a-button
  10. class="search-button"
  11. type="primary"
  12. @click="querySchoolList"
  13. >查询</a-button
  14. >
  15. </a-form-item>
  16. </a-form>
  17. <a-button
  18. type="primary"
  19. class="tw-flex tw-items-center operation-button"
  20. @click="toggleAddSchoolModal"
  21. >
  22. <template #icon>
  23. <PlusCircleOutlined />
  24. </template>
  25. 新增
  26. </a-button>
  27. </Block>
  28. <Block class="school-table">
  29. <a-table
  30. :columns="columns"
  31. :data-source="schoolTableData.result"
  32. emptyText="暂无学校信息"
  33. @change="currentPageChange"
  34. :pagination="{
  35. total: schoolTableData.totalCount,
  36. pageSize: query.pageSize,
  37. }"
  38. :row-class-name="
  39. (_:any, index:number) => (index % 2 === 1 ? 'table-striped' : null)
  40. "
  41. >
  42. <template #bodyCell="{ column, record, index, text }">
  43. <template v-if="column.dataIndex === 'index'">
  44. {{ index + 1 }}
  45. </template>
  46. <template v-else-if="column.dataIndex === 'enable'">
  47. <template v-if="record.enable">
  48. <CheckCircleFilled style="color: #30bf78" />
  49. </template>
  50. <template v-else>
  51. <CloseCircleFilled style="color: #f4664a" />
  52. </template>
  53. </template>
  54. <template v-else-if="column.dataIndex === 'updateTime'">
  55. {{ text || record["createTime"] }}
  56. </template>
  57. <template v-else-if="column.dataIndex === 'operation'">
  58. <div class="tw-flex tw-items-center">
  59. <span
  60. class="tw-cursor-pointer tw-p-2"
  61. @click="updateSchoolStatus(record)"
  62. >{{ record.enable ? "禁用" : "启用" }}</span
  63. >
  64. <span
  65. class="tw-cursor-pointer tw-p-2 tw-ml-1"
  66. @click="onEdit(record)"
  67. >编辑</span
  68. >
  69. <a-popover trigger="click">
  70. <template #content>
  71. <VueQrCode
  72. type="image/png"
  73. :margin="0"
  74. :color="{}"
  75. :quality="0.9"
  76. :value="record.qrCode"
  77. />
  78. </template>
  79. <span class="tw-cursor-pointer tw-p-2 tw-ml-1">二维码</span>
  80. </a-popover>
  81. </div>
  82. </template>
  83. </template>
  84. </a-table>
  85. </Block>
  86. <a-modal
  87. v-model:visible="showModal"
  88. :title="`${!schoolInfo.id ? '新增' : '编辑'}学校`"
  89. okText="确定"
  90. cancelText="取消"
  91. :maskClosable="false"
  92. @ok="onAddNewSchool"
  93. :afterClose="resetFields"
  94. >
  95. <a-form :labelCol="{ span: 6 }">
  96. <a-form-item label="学校编码" v-bind="validateInfos.code">
  97. <a-input v-model:value="schoolInfo.code"></a-input>
  98. </a-form-item>
  99. <a-form-item label="学校名称" v-bind="validateInfos.name">
  100. <a-input v-model:value="schoolInfo.name"></a-input>
  101. </a-form-item>
  102. <a-form-item label="负责人" v-bind="validateInfos.contacts">
  103. <a-input v-model:value="schoolInfo.contacts"></a-input>
  104. </a-form-item>
  105. <a-form-item label="联系方式" v-bind="validateInfos.telephone">
  106. <a-input
  107. v-model:value="schoolInfo.telephone"
  108. maxlength="11"
  109. ></a-input>
  110. </a-form-item>
  111. <a-form-item label="地区" v-bind="validateInfos.region">
  112. <a-input v-model:value="schoolInfo.region"></a-input>
  113. </a-form-item>
  114. <a-form-item label="状态">
  115. <a-radio-group v-model:value="schoolInfo.enable">
  116. <a-radio :value="true">启用</a-radio>
  117. <a-radio :value="false">禁用</a-radio>
  118. </a-radio-group>
  119. </a-form-item>
  120. </a-form>
  121. </a-modal>
  122. </div>
  123. </template>
  124. <script setup lang="ts" name="PageSchool">
  125. import { reactive, ref, watch } from "vue";
  126. import {
  127. PlusCircleOutlined,
  128. CheckCircleFilled,
  129. CloseCircleFilled,
  130. } from "@ant-design/icons-vue";
  131. import {
  132. getSchoolListHttp,
  133. updateSchoolStatusHttp,
  134. editSchoolInfoHttp,
  135. } from "@/apis/school";
  136. import Block from "@/components/block/index.vue";
  137. import { message, TableColumnType } from "ant-design-vue";
  138. import { Form } from "ant-design-vue";
  139. import VueQrCode from "vue-qrcode";
  140. const showModal = ref(false);
  141. const schoolInfo = reactive<BaseSchoolInfo>({
  142. code: "",
  143. contacts: "",
  144. name: "",
  145. region: "",
  146. telephone: "",
  147. enable: true,
  148. id: void 0,
  149. });
  150. const schoolRules = {
  151. code: [{ required: true, message: "请填写学校编码" }],
  152. name: [{ required: true, message: "请填写学校名称" }],
  153. contacts: [{ required: true, message: "请填写负责人" }],
  154. region: [{ required: true, message: "请填写学校地区" }],
  155. telephone: [
  156. { required: true, message: "请填写联系方式" },
  157. { pattern: /\d{11}/, message: "请填写正确联系方式" },
  158. ],
  159. };
  160. const { validate, validateInfos, resetFields } = Form.useForm(
  161. schoolInfo,
  162. schoolRules
  163. );
  164. /** 请求参数 */
  165. const query = reactive<FetchSchoolListQuery>({
  166. name: "",
  167. pageNumber: 1,
  168. pageSize: 10,
  169. });
  170. /** table配置 */
  171. const columns: TableColumnType[] = [
  172. { title: "序号", dataIndex: "index", align: "center" },
  173. { title: "学校ID", dataIndex: "id" },
  174. { title: "学校名称", dataIndex: "name", ellipsis: true },
  175. { title: "地区", dataIndex: "region",maxWidth: 300 },
  176. { title: "状态", dataIndex: "enable", align: "center" },
  177. { title: "负责人", dataIndex: "contacts", ellipsis: true },
  178. { title: "联系方式", dataIndex: "telephone" },
  179. { title: "更新时间", dataIndex: "updateTime", ellipsis: true },
  180. { title: "操作", dataIndex: "operation" },
  181. ];
  182. /** 学校列表信息 */
  183. const schoolTableData = reactive<MultiplePageData<SchoolListInfo>>({
  184. totalCount: 0,
  185. result: [],
  186. });
  187. /** 显示新增学校弹窗 */
  188. const toggleAddSchoolModal = (show: boolean = true) => {
  189. showModal.value = show;
  190. };
  191. const currentPageChange = ({ current }: { current: number }) => {
  192. query.pageNumber = current;
  193. };
  194. /** 查询学校列表 */
  195. const querySchoolList = async () => {
  196. try {
  197. const { result = [], totalCount } = await getSchoolListHttp(query);
  198. Object.assign(schoolTableData, { result, totalCount });
  199. } catch (error) {
  200. console.error(error);
  201. }
  202. };
  203. watch(() => query.pageNumber, querySchoolList);
  204. /* 启用/禁用 */
  205. const updateSchoolStatus = (record: SchoolListInfo) => {
  206. updateSchoolStatusHttp({ enable: !record.enable, ids: [record.id] }).then(
  207. querySchoolList
  208. );
  209. };
  210. /** 编辑学校 */
  211. const onEdit = (record: SchoolListInfo) => {
  212. Object.assign(schoolInfo, {
  213. code: record.code,
  214. contacts: record.contacts,
  215. name: record.name,
  216. region: record.region,
  217. telephone: record.telephone,
  218. enable: !!record.enable,
  219. id: record.id,
  220. });
  221. toggleAddSchoolModal(true);
  222. };
  223. /** 新增学校 */
  224. const onAddNewSchool = () => {
  225. validate().then((valid) => {
  226. if (valid) {
  227. editSchoolInfoHttp(schoolInfo).then(() => {
  228. message.success(`${schoolInfo.code ? "修改" : "添加"}成功`);
  229. toggleAddSchoolModal(false);
  230. querySchoolList();
  231. });
  232. }
  233. });
  234. };
  235. /** effect */
  236. querySchoolList();
  237. </script>
  238. <style scoped lang="less">
  239. .school-manage {
  240. .header-block {
  241. .search-button {
  242. background-color: @font-color;
  243. color: @white;
  244. border: none;
  245. width: 56px;
  246. padding: 0;
  247. &:after {
  248. display: none;
  249. opacity: 0;
  250. }
  251. }
  252. .operation-button {
  253. width: 72px;
  254. padding: 0;
  255. }
  256. }
  257. .school-table {
  258. }
  259. }
  260. </style>