index.vue 8.8 KB

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