组件.数据表格

12003

简单 Table

  1. <jh-toast />
  2. <jh-mask />
  3. <jh-confirm-dialog />
  4. <v-app mobile-breakpoint="sm">
  5. <!-- 头部内容 >>>>>>>>>>>>> -->
  6. <div class="jh-page-second-bar px-8">
  7. <v-row class="align-center" dense>
  8. <v-col cols="12" xs="12" sm="4" md="4" xl="3">
  9. <div class="py-4 text-body-1 font-weight-bold d-flex align-center">简单 Table</div>
  10. </v-col>
  11. <!-- 搜索条件表单 >>>>>>>> -->
  12. <v-col cols="12" xs="12" sm="8" md="8" xl="9">
  13. <v-row class="jh-backend-form-container justify-end ma-0 py-3">
  14. <div class="jh-backend-search-btn">
  15. <v-btn class="elevation-0 float-right mt-2 mt-md-0" color="success" small
  16. @click="doUiAction('getTableData')">
  17. 查询
  18. </v-btn>
  19. </div>
  20. </v-row>
  21. </v-col>
  22. <!-- <<<<<<<< 搜索条件表单 -->
  23. </v-row>
  24. </div>
  25. <!-- <<<<<<<<<<<<< 头部内容 -->
  26. <div class="jh-page-body-container px-8">
  27. <!-- 页面内容 >>>>>>>>>>>>> -->
  28. <v-card class="rounded-lg">
  29. <v-row class="ma-0 pa-3">
  30. <!-- 新增按钮 -->
  31. <v-btn v-if="tableSelected.length > 0" color="default" class="elevation-0 mr-2" small>{{
  32. tableSelected.length }}个选中</v-btn>
  33. <v-spacer></v-spacer>
  34. <!-- 搜索过滤 -->
  35. <v-col cols="12" xs="8" sm="4" md="3" xl="2" class="pa-0">
  36. <v-text-field color="success" v-model="searchInput" prefix="搜索:" class="jh-v-input" dense filled
  37. single-line></v-text-field>
  38. </v-col>
  39. </v-row>
  40. <v-data-table :headers="headers" :items="tableData" :search="searchInput"
  41. :footer-props="{ itemsPerPageOptions: [20, 50, -1], itemsPerPageText: '每页行数', itemsPerPageAllText: '所有'}"
  42. :items-per-page="-1" mobile-breakpoint="0" :loading="isTableLoading"
  43. :class="{'zebraLine': isTableZebraLineShown }" checkbox-color="success" fixed-header
  44. class="jh-fixed-table-height elevation-0 mt-0 mb-xs-4" show-select item-key="studentId"
  45. @item-selected="tableItemSelected" @toggle-select-all="tableToggleSelectAll" v-model="tableSelected">
  46. <!-- 性别 -->
  47. <template v-slot:item.gender="{ item }">
  48. {{ getDisplayText({displayObj: constantObj.gender, displayValue: item.gender}) }}
  49. </template>
  50. <!-- 年级 -->
  51. <template v-slot:item.level="{ item }">
  52. {{ getDisplayText({displayObj: constantObj.level, displayValue: item.level}) }}
  53. </template>
  54. <!-- 没有数据 -->
  55. <template v-slot:loading>
  56. <div class="jh-no-data">数据加载中</div>
  57. </template>
  58. <template v-slot:no-data>
  59. <div class="jh-no-data">暂无数据</div>
  60. </template>
  61. <template v-slot:no-results>
  62. <div class="jh-no-data">暂无数据</div>
  63. </template>
  64. <!-- 表格分页 -->
  65. <template v-slot:footer.page-text="pagination">
  66. <span>{{pagination.pageStart}}-{{pagination.pageStop}}</span>
  67. <span class="ml-1">共{{pagination.itemsLength}}条</span>
  68. </template>
  69. </v-data-table>
  70. </v-card>
  71. </div>
  72. </v-app>
  73. {% include 'common/jianghuJs/fixedTableHeightV4.html' %}
  74. <script type="module">
  75. new Vue({
  76. el: '#app',
  77. template: '#app-template',
  78. vueComponent: 'page',
  79. vuetify: new Vuetify(),
  80. data: {
  81. isTableZebraLineShown: true,
  82. constantObj: {
  83. gender: [{ "value": "male", "text": "男" }, { "value": "female", "text": "女" }],
  84. level: [{ "value": "01", "text": "一年级" }, { "value": "02", "text": "二年级" }, { "value": "03", "text": "三年级" }],
  85. },
  86. searchInput: null,
  87. isTableLoading: true,
  88. tableData: [],
  89. headers: [
  90. { text: "学生ID", value: "studentId", width: 80, class: 'fixed', cellClass: 'fixed' },
  91. { text: "班级ID", value: "classId", width: 140 },
  92. { text: "学生名字", value: "name", width: 120 },
  93. { text: "年级", value: "level", width: 120 },
  94. { text: "性别", value: "gender", width: 120 },
  95. { text: "出生日期", value: "dateOfBirth", width: 120 },
  96. { text: "身高", value: "bodyHeight", width: 120 },
  97. { text: "学生状态", value: "studentStatus", width: 120 },
  98. { text: "备注", value: "remarks", width: 120 },
  99. { text: "操作者", value: "operationByUser", width: 120 },
  100. { text: "操作时间", value: "operationAt", width: 250 },
  101. ],
  102. tableSelected: [],
  103. },
  104. watch: {},
  105. async created() {
  106. this.doUiAction('getTableData');
  107. },
  108. async mounted() {
  109. },
  110. methods: {
  111. async doUiAction(uiActionId, uiActionData) {
  112. try {
  113. switch (uiActionId) {
  114. case 'getTableData':
  115. await this.getTableData();
  116. break;
  117. default:
  118. console.error("[doUiAction] uiActionId not find", { uiActionId });
  119. break;
  120. }
  121. } catch (error) {
  122. throw error;
  123. } finally {
  124. window.jhMask && window.jhMask.hide();
  125. }
  126. },
  127. async getTableData() {
  128. this.isTableLoading = true;
  129. const result = await window.jianghuAxios({
  130. data: {
  131. appData: {
  132. pageId: 'playground-doUiAction',
  133. actionId: 'selectItemList',
  134. actionData: {},
  135. where: {},
  136. orderBy: [{ column: 'operationAt', order: 'desc' }]
  137. }
  138. }
  139. });
  140. this.tableData = result.data.appData.resultData.rows;
  141. this.isTableLoading = false;
  142. },
  143. // ---------- table selected >>>>>>>>>>>> --------
  144. tableItemSelected({ item, value }) {
  145. if (value) {
  146. this.tableSelected.push(item);
  147. } else {
  148. this.tableSelected = _.reject(this.tableSelected, ['studentId', item.studentId]);
  149. }
  150. },
  151. tableToggleSelectAll({ items, value }) {
  152. if (value) {
  153. this.tableSelected = items;
  154. } else {
  155. this.tableSelected = [];
  156. }
  157. },
  158. // ---------- <<<<<<<<<<< table selected --------
  159. }
  160. })
  161. </script>

CRUD Table

  1. <jh-toast />
  2. <jh-mask />
  3. <jh-confirm-dialog />
  4. <v-app mobile-breakpoint="sm">
  5. <!-- 头部内容 >>>>>>>>>>>>> -->
  6. <div class="jh-page-second-bar px-8">
  7. <v-row class="align-center" dense>
  8. <v-col cols="12" xs="12" sm="4" md="4" xl="3">
  9. <div class="py-4 text-body-1 font-weight-bold d-flex align-center">CRUD Table</div>
  10. </v-col>
  11. <!-- 搜索条件表单 >>>>>>>> -->
  12. <v-col cols="12" xs="12" sm="8" md="8" xl="9">
  13. <v-row class="jh-backend-form-container justify-end ma-0 py-3">
  14. <div class="jh-backend-search-btn">
  15. <v-btn class="elevation-0 float-right mt-2 mt-md-0" color="success" small
  16. @click="doUiAction('getTableData')">
  17. 查询
  18. </v-btn>
  19. </div>
  20. </v-row>
  21. </v-col>
  22. <!-- <<<<<<<< 搜索条件表单 -->
  23. </v-row>
  24. </div>
  25. <!-- <<<<<<<<<<<<< 头部内容 -->
  26. <div class="jh-page-body-container px-8">
  27. <!-- 页面内容 >>>>>>>>>>>>> -->
  28. <v-card class="rounded-lg">
  29. <v-row class="ma-0 pa-3">
  30. <!-- 新增按钮 -->
  31. <v-btn color="success" class="elevation-0 mr-2" @click="doUiAction('startCreateItem')" small>新增</v-btn>
  32. <v-btn class="red--text text--accent-2 elevation-0 mr-2" small outlined
  33. @click="doUiAction('deleteItemBatch')" :disabled="tableSelected.length === 0">批量删除</v-btn>
  34. <v-spacer></v-spacer>
  35. <!-- 搜索过滤 -->
  36. <v-col cols="12" xs="8" sm="4" md="3" xl="2" class="pa-0">
  37. <v-text-field color="success" v-model="searchInput" prefix="搜索:" class="jh-v-input" dense filled
  38. single-line></v-text-field>
  39. </v-col>
  40. </v-row>
  41. <!-- 表格 -->
  42. <v-data-table :headers="headers" :items="tableData" :search="searchInput"
  43. :footer-props="{ itemsPerPageOptions: [20, 50, -1], itemsPerPageText: '每页行数', itemsPerPageAllText: '所有'}"
  44. :items-per-page="-1" mobile-breakpoint="0" :loading="isTableLoading"
  45. :class="{'zebraLine': isTableZebraLineShown }" checkbox-color="success" fixed-header
  46. class="jh-fixed-table-height elevation-0 mt-0 mb-xs-4" show-select item-key="studentId"
  47. @item-selected="tableItemSelected" @toggle-select-all="tableToggleSelectAll" v-model="tableSelected">
  48. <!-- 表格行操作按钮 -->
  49. <template v-slot:item.action="{ item }">
  50. <template>
  51. <!-- pc端 -->
  52. <template v-if="!isMobile">
  53. <span role="button" class="success--text font-weight-medium font-size-2 mr-2"
  54. @click="doUiAction('startUpdateItem', item)">
  55. <v-icon size="16" class="success--text">mdi-note-edit-outline</v-icon>修改
  56. </span>
  57. <span role="button" class="red--text text--accent-2 font-weight-medium font-size-2"
  58. @click="doUiAction('deleteItem', item)">
  59. <v-icon size="16" class="red--text text--accent-2">mdi-trash-can-outline</v-icon>删除
  60. </span>
  61. </template>
  62. <!-- 手机端 -->
  63. <v-menu offset-y v-if="isMobile">
  64. <template v-slot:activator="{ on, attrs }">
  65. <span role="button" class="success--text font-weight-medium font-size-2" v-bind="attrs"
  66. v-on="on">
  67. 操作<v-icon size="14" class="success--text">mdi-chevron-down</v-icon>
  68. </span>
  69. </template>
  70. <v-list dense>
  71. <v-list-item @click="doUiAction('startUpdateItem', item)">
  72. <v-list-item-title>修改</v-list-item-title>
  73. </v-list-item>
  74. <v-list-item @click="doUiAction('deleteItem', item)">
  75. <v-list-item-title>删除</v-list-item-title>
  76. </v-list-item>
  77. </v-list>
  78. </v-menu>
  79. </template>
  80. </template>
  81. <!-- 性别 -->
  82. <template v-slot:item.gender="{ item }">
  83. {{ getDisplayText({displayObj: constantObj.gender, displayValue: item.gender}) }}
  84. </template>
  85. <!-- 年级 -->
  86. <template v-slot:item.level="{ item }">
  87. {{ getDisplayText({displayObj: constantObj.level, displayValue: item.level}) }}
  88. </template>
  89. <!-- 没有数据 -->
  90. <template v-slot:loading>
  91. <div class="jh-no-data">数据加载中</div>
  92. </template>
  93. <template v-slot:no-data>
  94. <div class="jh-no-data">暂无数据</div>
  95. </template>
  96. <template v-slot:no-results>
  97. <div class="jh-no-data">暂无数据</div>
  98. </template>
  99. <!-- 表格分页 -->
  100. <template v-slot:footer.page-text="pagination">
  101. <span>{{pagination.pageStart}}-{{pagination.pageStop}}</span>
  102. <span class="ml-1">共{{pagination.itemsLength}}条</span>
  103. </template>
  104. </v-data-table>
  105. </v-card>
  106. <!-- <<<<<<<<<<<<< 页面内容 -->
  107. <!-- 新增抽屉 -->
  108. <v-navigation-drawer v-model="isCreateDrawerShown" v-click-outside="drawerClickOutside" fixed temporary right
  109. width="80%" class="elevation-24">
  110. <v-form ref="createForm" lazy-validation>
  111. <!-- 抽屉标题 -->
  112. <v-row no-gutters>
  113. <span class="text-h7 font-weight-bold pa-4">添加信息</span>
  114. </v-row>
  115. <v-divider class="jh-divider"></v-divider>
  116. <!-- 抽屉表单主体 -->
  117. <v-row class="mt-0 px-4">
  118. <v-col cols="12" sm="12" md="4">
  119. <span class="jh-input-label">学生ID<span class="red--text text--accent-2 ml-1">*必填</span></span>
  120. <v-text-field class="jh-v-input" dense single-line filled label="学生ID"
  121. v-model="createItem.studentId" :rules="validationRules.requireRules"></v-text-field>
  122. </v-col>
  123. <v-col cols="12" sm="12" md="4">
  124. <span class="jh-input-label">班级ID</span>
  125. <v-select class="jh-v-input" dense single-line filled clearable label="班级ID"
  126. v-model="createItem.classId" :items="constantObj.classId"></v-select>
  127. </v-col>
  128. <v-col cols="12" sm="12" md="4">
  129. <span class="jh-input-label">学生名字</span>
  130. <v-text-field class="jh-v-input" dense single-line filled label="学生名字"
  131. v-model="createItem.name"></v-text-field>
  132. </v-col>
  133. <v-col cols="12" sm="12" md="4">
  134. <span class="jh-input-label">年级</span>
  135. <v-select class="jh-v-input" dense single-line filled clearable label="年级"
  136. v-model="createItem.level" :items="constantObj.level"></v-select>
  137. </v-col>
  138. <v-col cols="12" sm="12" md="4">
  139. <span class="jh-input-label">性别</span>
  140. <v-select class="jh-v-input" dense single-line filled clearable label="性别"
  141. v-model="createItem.gender" :items="constantObj.gender"></v-select>
  142. </v-col>
  143. <v-col cols="12" sm="12" md="4">
  144. <span class="jh-input-label">出生日期</span>
  145. <v-menu class="jh-v-input" transition="scale-transition" offset-y min-width="auto">
  146. <template v-slot:activator="{on, attrs}">
  147. <v-text-field v-bind="attrs" v-on="on" v-model="createItem.dateOfBirth"
  148. class="jh-v-input" dense single-line filled readonly label="出生日期"></v-text-field>
  149. </template>
  150. <v-date-picker color="success" elevation="20"
  151. v-model="createItem.dateOfBirth"></v-date-picker>
  152. </v-menu>
  153. </v-col>
  154. <v-col cols="12" sm="12" md="4">
  155. <span class="jh-input-label">身高</span>
  156. <v-text-field class="jh-v-input" dense single-line filled label="身高"
  157. v-model="createItem.bodyHeight"></v-text-field>
  158. </v-col>
  159. <v-col cols="12" sm="12" md="4">
  160. <span class="jh-input-label">学生状态</span>
  161. <v-select class="jh-v-input" dense single-line filled clearable label="学生状态"
  162. v-model="createItem.studentStatus" :items="constantObj.studentStatus"></v-select>
  163. </v-col>
  164. <v-col cols="12" sm="12" md="4">
  165. <span class="jh-input-label">备注</span>
  166. <v-text-field class="jh-v-input" dense single-line filled label="备注"
  167. v-model="createItem.remarks"></v-text-field>
  168. </v-col>
  169. </v-row>
  170. <!-- 抽屉操作按钮 -->
  171. <v-row class="justify-end mx-0 my-8 px-4">
  172. <v-btn color="success" @click="doUiAction('createItem')" small>保存</v-btn>
  173. <v-btn class="ml-2" @click="isCreateDrawerShown = false" small>取消</v-btn>
  174. </v-row>
  175. </v-form>
  176. <!-- 抽屉关闭按钮 -->
  177. <v-btn elevation="0" color="success" fab absolute top left small tile class="drawer-close-float-btn"
  178. @click="isCreateDrawerShown = false">
  179. <v-icon>mdi-close</v-icon>
  180. </v-btn>
  181. </v-navigation-drawer>
  182. <!-- 编辑抽屉 -->
  183. <v-navigation-drawer v-model="isUpdateDrawerShown" v-click-outside="drawerClickOutside" fixed temporary right
  184. width="80%" class="elevation-24">
  185. <v-form ref="updateForm" lazy-validation>
  186. <!-- 抽屉标题 -->
  187. <v-row no-gutters>
  188. <span class="text-h7 font-weight-bold pa-4">修改信息</span>
  189. </v-row>
  190. <v-divider class="jh-divider"></v-divider>
  191. <!-- 抽屉表单 -->
  192. <v-row class="mt-0 px-4">
  193. <v-col cols="12" sm="12" md="4">
  194. <span class="jh-input-label">学生ID<span class="red--text text--accent-2 ml-1">*必填</span></span>
  195. <v-text-field class="jh-v-input" disabled dense single-line filled label="学生ID"
  196. v-model="updateItem.studentId" :rules="validationRules.requireRules"></v-text-field>
  197. </v-col>
  198. <v-col cols="12" sm="12" md="4">
  199. <span class="jh-input-label">班级ID</span>
  200. <v-select class="jh-v-input" dense single-line filled clearable label="班级ID"
  201. v-model="updateItem.classId" :items="constantObj.classId"></v-select>
  202. </v-col>
  203. <v-col cols="12" sm="12" md="4">
  204. <span class="jh-input-label">学生名字</span>
  205. <v-text-field class="jh-v-input" dense single-line filled label="学生名字"
  206. v-model="updateItem.name"></v-text-field>
  207. </v-col>
  208. <v-col cols="12" sm="12" md="4">
  209. <span class="jh-input-label">年级</span>
  210. <v-select class="jh-v-input" dense single-line filled clearable label="年级"
  211. v-model="updateItem.level" :items="constantObj.level"></v-select>
  212. </v-col>
  213. <v-col cols="12" sm="12" md="4">
  214. <span class="jh-input-label">性别</span>
  215. <v-select class="jh-v-input" dense single-line filled clearable label="性别"
  216. v-model="updateItem.gender" :items="constantObj.gender"></v-select>
  217. </v-col>
  218. <v-col cols="12" sm="12" md="4">
  219. <span class="jh-input-label">出生日期</span>
  220. <v-menu class="jh-v-input" transition="scale-transition" offset-y min-width="auto">
  221. <template v-slot:activator="{on, attrs}">
  222. <v-text-field v-bind="attrs" v-on="on" v-model="updateItem.dateOfBirth"
  223. class="jh-v-input" dense single-line filled readonly label="出生日期"></v-text-field>
  224. </template>
  225. <v-date-picker color="success" elevation="20"
  226. v-model="updateItem.dateOfBirth"></v-date-picker>
  227. </v-menu>
  228. </v-col>
  229. <v-col cols="12" sm="12" md="4">
  230. <span class="jh-input-label">身高</span>
  231. <v-text-field class="jh-v-input" dense single-line filled label="身高"
  232. v-model="updateItem.bodyHeight"></v-text-field>
  233. </v-col>
  234. <v-col cols="12" sm="12" md="4">
  235. <span class="jh-input-label">学生状态</span>
  236. <v-select class="jh-v-input" dense single-line filled clearable label="学生状态"
  237. v-model="updateItem.studentStatus" :items="constantObj.studentStatus"></v-select>
  238. </v-col>
  239. <v-col cols="12" sm="12" md="4">
  240. <span class="jh-input-label">备注</span>
  241. <v-text-field class="jh-v-input" dense single-line filled label="备注"
  242. v-model="updateItem.remarks"></v-text-field>
  243. </v-col>
  244. </v-row>
  245. <!-- 抽屉操作按钮 -->
  246. <v-row class="justify-end mx-0 my-8 px-4">
  247. <v-btn color="success" small @click="doUiAction('updateItem')">保存</v-btn>
  248. <v-btn class="ml-2" small @click="isUpdateDrawerShown = false">取消
  249. </v-btn>
  250. </v-row>
  251. </v-form>
  252. <!-- 抽屉关闭按钮 -->
  253. <v-btn elevation="0" color="success" fab absolute top left small tile class="drawer-close-float-btn"
  254. @click="isUpdateDrawerShown = false">
  255. <v-icon>mdi-close</v-icon>
  256. </v-btn>
  257. </v-navigation-drawer>
  258. </div>
  259. <!-- 帮助页抽屉 >>>>>>>>>>>>> -->
  260. <v-navigation-drawer v-if="isHelpPageDrawerShown" v-model="isHelpPageDrawerShown"
  261. v-click-outside="drawerClickOutside" fixed temporary right width="80%" class="elevation-24">
  262. <iframe style="border: 0" :src="`/${appInfo.appId}/pageDoc#3.doUiAction.md`" width="100%"
  263. height="100%"></iframe>
  264. <v-btn elevation="0" color="success" fab absolute top left small tile class="drawer-close-float-btn"
  265. @click="isHelpPageDrawerShown = false">
  266. <v-icon>mdi-close</v-icon>
  267. </v-btn>
  268. </v-navigation-drawer>
  269. <!-- <<<<<<<<<<<<< 帮助页抽屉 -->
  270. </v-app>
  271. {% include 'common/jianghuJs/fixedTableHeightV4.html' %}
  272. <script type="module">
  273. new Vue({
  274. el: '#app',
  275. template: '#app-template',
  276. vueComponent: 'page',
  277. vuetify: new Vuetify(),
  278. data: {
  279. isHelpPageDrawerShown: false,
  280. isMobile: window.innerWidth < 500,
  281. // 表格相关数据
  282. isTableZebraLineShown: true,
  283. validationRules: {
  284. requireRules: [
  285. v => !!v || 'This is required',
  286. ],
  287. },
  288. // 下拉选项
  289. constantObj: {
  290. gender: [{ "value": "male", "text": "男" }, { "value": "female", "text": "女" }],
  291. classId: [
  292. { "value": "2021-01级-01班", "text": "2021-01级-01班" }, { "value": "2021-01级-02班", "text": "2021-01级-02班" },
  293. { "value": "2021-02级-01班", "text": "2021-02级-01班" }, { "value": "2021-02级-02班", "text": "2021-02级-02班" },
  294. { "value": "2021-03级-01班", "text": "2021-03级-01班" }, { "value": "2021-03级-02班", "text": "2021-03级-02班" }
  295. ],
  296. level: [{ "value": "01", "text": "一年级" }, { "value": "02", "text": "二年级" }, { "value": "03", "text": "三年级" }],
  297. studentStatus: [{ "value": "正常", "text": "正常" }, { "value": "退学", "text": "退学" }]
  298. },
  299. searchInput: null,
  300. isTableLoading: true,
  301. tableData: [],
  302. headers: [
  303. { text: "学生ID", value: "studentId", width: 80, class: window.innerWidth < 500 ? 'fixed' : '', cellClass: window.innerWidth < 500 ? 'fixed' : '' },
  304. { text: "班级ID", value: "classId", width: 140 },
  305. { text: "学生名字", value: "name", width: 120 },
  306. { text: "年级", value: "level", width: 120 },
  307. { text: "性别", value: "gender", width: 120 },
  308. { text: "出生日期", value: "dateOfBirth", width: 120 },
  309. { text: "身高", value: "bodyHeight", width: 120 },
  310. { text: "学生状态", value: "studentStatus", width: 120 },
  311. { text: "备注", value: "remarks", width: 120 },
  312. { text: "操作者", value: "operationByUser", width: 120 },
  313. { text: "操作时间", value: "operationAt", width: 250 },
  314. { text: '操作', value: 'action', align: 'center', sortable: false, width: window.innerWidth < 500 ? 80 : 120, class: 'fixed', cellClass: 'fixed' },
  315. ],
  316. tableSelected: [],
  317. isCreateDrawerShown: false,
  318. createItem: {},
  319. createActionData: {},
  320. isUpdateDrawerShown: false,
  321. updateItem: {},
  322. updateItemId: null,
  323. updateActionData: {},
  324. deleteItem: {},
  325. deleteItemId: null
  326. },
  327. watch: {},
  328. mounted() {
  329. this.doUiAction('getTableData');
  330. },
  331. methods: {
  332. async doUiAction(uiActionId, uiActionData) {
  333. try {
  334. switch (uiActionId) {
  335. case 'getTableData':
  336. await this.getTableData();
  337. break;
  338. case 'startCreateItem':
  339. await this.prepareCreateFormData();
  340. await this.openCreateDrawer();
  341. break;
  342. case 'createItem':
  343. await this.prepareCreateValidate();
  344. await this.confirmCreateItemDialog();
  345. await this.prepareDoCreateItem();
  346. await this.doCreateItem();
  347. await this.closeCreateDrawer();
  348. await this.getTableData();
  349. break;
  350. case 'startUpdateItem':
  351. await this.prepareUpdateFormData(uiActionData);
  352. await this.openUpdateDrawer();
  353. break;
  354. case 'updateItem':
  355. await this.prepareUpdateValidate();
  356. await this.confirmUpdateItemDialog();
  357. await this.prepareDoUpdateItem();
  358. await this.doUpdateItem();
  359. await this.closeUpdateDrawer();
  360. await this.getTableData();
  361. break;
  362. case 'deleteItem':
  363. await this.prepareDeleteFormData(uiActionData);
  364. await this.confirmDeleteItemDialog();
  365. await this.prepareDoDeleteItem();
  366. await this.doDeleteItem();
  367. await this.clearDeleteItem();
  368. await this.getTableData();
  369. break;
  370. case 'deleteItemBatch':
  371. await this.confirmDeleteItemDialog();
  372. await this.doDeleteItemBatch();
  373. await this.clearTableSelected();
  374. await this.getTableData();
  375. break;
  376. default:
  377. console.error("[doUiAction] uiActionId not find", { uiActionId });
  378. break;
  379. }
  380. } catch (error) {
  381. throw error;
  382. } finally {
  383. window.jhMask && window.jhMask.hide();
  384. }
  385. },
  386. async getTableData() {
  387. this.isTableLoading = true;
  388. const result = await window.jianghuAxios({
  389. data: {
  390. appData: {
  391. pageId: 'playground-doUiAction',
  392. actionId: 'selectItemList',
  393. actionData: {},
  394. where: {},
  395. orderBy: [{ column: 'operationAt', order: 'desc' }]
  396. }
  397. }
  398. });
  399. this.tableData = result.data.appData.resultData.rows;
  400. this.isTableLoading = false;
  401. },
  402. // ---------- 新增数据 uiAction >>>>>>>>>> --------
  403. async prepareCreateFormData() {
  404. this.createItem = {};
  405. },
  406. async openCreateDrawer() {
  407. this.isCreateDrawerShown = true;
  408. },
  409. async prepareCreateValidate() {
  410. if (await this.$refs.createForm.validate()) {
  411. return true;
  412. }
  413. throw new Error("请完善表单信息")
  414. },
  415. async confirmCreateItemDialog() {
  416. if (await window.confirmDialog({ title: "新增", content: "确定新增吗?" }) === false) {
  417. throw new Error("[confirmCreateFormDialog] 否");
  418. }
  419. },
  420. prepareDoCreateItem() {
  421. const { id, ...data } = this.createItem;
  422. this.createActionData = data;
  423. },
  424. async doCreateItem() {
  425. await window.jhMask.show();
  426. await window.vtoast.loading("新增学生");
  427. await window.jianghuAxios({
  428. data: {
  429. appData: {
  430. pageId: 'playground-doUiAction',
  431. actionId: 'insertItem',
  432. actionData: this.createActionData
  433. }
  434. }
  435. })
  436. await window.jhMask.hide();
  437. await window.vtoast.success("新增学生成功");
  438. },
  439. async closeCreateDrawer() {
  440. this.isCreateDrawerShown = false;
  441. this.createItem = {};
  442. this.createActionData = null;
  443. },
  444. // ---------- <<<<<<<<<<< 新增数据 uiAction ---------
  445. // ---------- 修改数据 uiAction >>>>>>>>>>>> --------
  446. async prepareUpdateFormData(funObj) {
  447. this.updateItem = _.cloneDeep(funObj);
  448. },
  449. async openUpdateDrawer() {
  450. this.isUpdateDrawerShown = true;
  451. },
  452. async prepareUpdateValidate() {
  453. if (await this.$refs.updateForm.validate()) {
  454. return true;
  455. }
  456. throw new Error("请完善表单信息")
  457. },
  458. async confirmUpdateItemDialog() {
  459. if (await window.confirmDialog({ title: "修改", content: "确定修改吗?" }) === false) {
  460. throw new Error("[confirmUpdateItemDialog] 否");
  461. }
  462. },
  463. async prepareDoUpdateItem() {
  464. const { id, ...data } = this.updateItem;
  465. this.updateItemId = id;
  466. this.updateActionData = data;
  467. },
  468. async doUpdateItem() {
  469. await window.jhMask.show();
  470. await window.vtoast.loading("修改学生");
  471. await window.jianghuAxios({
  472. data: {
  473. appData: {
  474. pageId: 'playground-doUiAction',
  475. actionId: 'updateItem',
  476. actionData: this.updateActionData,
  477. where: { id: this.updateItemId }
  478. }
  479. }
  480. })
  481. await window.jhMask.hide();
  482. await window.vtoast.success("修改学生成功");
  483. },
  484. async closeUpdateDrawer() {
  485. this.isUpdateDrawerShown = false;
  486. this.updateItem = {};
  487. this.updateActionData = null;
  488. this.updateItemId = null;
  489. },
  490. // ---------- <<<<<<<<<<< 修改数据 uiAction ---------
  491. // ---------- 删除数据 uiAction >>>>>>>>>>>> --------
  492. async prepareDeleteFormData(funObj) {
  493. this.deleteItem = _.cloneDeep(funObj);
  494. },
  495. async confirmDeleteItemDialog() {
  496. if (await window.confirmDialog({ title: "删除", content: "确定删除吗?" }) === false) {
  497. throw new Error("[confirmDeleteItemDialog] 否");
  498. }
  499. },
  500. async prepareDoDeleteItem() {
  501. const { id } = this.deleteItem;
  502. this.deleteItemId = id;
  503. },
  504. async doDeleteItem() {
  505. await window.vtoast.loading("删除学生");
  506. await window.jianghuAxios({
  507. data: {
  508. appData: {
  509. pageId: 'playground-doUiAction',
  510. actionId: 'deleteItem',
  511. actionData: {},
  512. where: { id: this.deleteItemId }
  513. }
  514. }
  515. });
  516. await window.vtoast.success("删除学生成功");
  517. },
  518. async clearDeleteItem() {
  519. this.deleteItem = {};
  520. this.deleteItemId = null;
  521. },
  522. // ---------- <<<<<<<<<<< 删除数据 uiAction ---------
  523. // ---------- 批量删除数据 uiAction >>>>>>>>>>>> --------
  524. async doDeleteItemBatch() {
  525. await window.vtoast.loading("批量删除");
  526. for (const item of this.tableSelected) {
  527. await window.jianghuAxios({
  528. data: {
  529. appData: {
  530. pageId: 'playground-doUiAction',
  531. actionId: 'deleteItem',
  532. actionData: {},
  533. where: { id: item.id }
  534. }
  535. }
  536. });
  537. }
  538. await window.vtoast.success("批量删除");
  539. },
  540. async clearTableSelected() {
  541. this.tableSelected = [];
  542. },
  543. // ---------- <<<<<<<<<<< 批量删除数据 uiAction ---------
  544. // ---------- table selected >>>>>>>>>>>> --------
  545. tableItemSelected({ item, value }) {
  546. if (value) {
  547. this.tableSelected.push(item);
  548. } else {
  549. this.tableSelected = _.reject(this.tableSelected, ['studentId', item.studentId]);
  550. }
  551. },
  552. tableToggleSelectAll({ items, value }) {
  553. if (value) {
  554. this.tableSelected = items;
  555. } else {
  556. this.tableSelected = [];
  557. }
  558. },
  559. // ---------- <<<<<<<<<<< table selected --------
  560. }
  561. })
  562. </script>