fake_user.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: () => {
  4. const { reactive, onMounted } = Vue
  5. const { ElMessageBox } = ElementPlus
  6. const index = {
  7. setup() {
  8. const state = reactive({
  9. data: [],
  10. order: '',
  11. sort: '',
  12. filter: {
  13. drawer: false,
  14. data: {
  15. user: { field: 'id', value: '' },
  16. gender: 'all',
  17. },
  18. tools: {
  19. user: {
  20. type: 'tinputprepend',
  21. label: '用户信息',
  22. placeholder: '请输入查询内容',
  23. value: {
  24. field: 'id',
  25. value: '',
  26. },
  27. options: {
  28. data: [{
  29. label: '用户ID',
  30. value: 'id',
  31. },
  32. {
  33. label: '用户名',
  34. value: 'username',
  35. },
  36. {
  37. label: '用户昵称',
  38. value: 'nickname',
  39. },
  40. {
  41. label: '用户手机号',
  42. value: 'mobile',
  43. },
  44. {
  45. label: '邮箱',
  46. value: 'email',
  47. }],
  48. }
  49. },
  50. gender: {
  51. type: 'tselect',
  52. label: '用户性别',
  53. value: '',
  54. options: {
  55. data: [{
  56. label: '全部',
  57. value: 'all',
  58. },
  59. {
  60. label: '女',
  61. value: '0',
  62. },
  63. {
  64. label: '男',
  65. value: '1',
  66. }]
  67. },
  68. },
  69. },
  70. condition: {},
  71. }
  72. })
  73. function getData() {
  74. let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
  75. let search = composeFilter(tempSearch, {
  76. username: 'like',
  77. nickname: 'like',
  78. mobile: 'like',
  79. email: 'like',
  80. });
  81. Fast.api.ajax({
  82. url: 'shopro/data/fake_user',
  83. type: 'GET',
  84. data: {
  85. page: pagination.page,
  86. list_rows: pagination.list_rows,
  87. order: state.order,
  88. sort: state.sort,
  89. ...search,
  90. },
  91. }, function (ret, res) {
  92. state.data = res.data.data
  93. pagination.total = res.data.total
  94. return false
  95. }, function (ret, res) { })
  96. }
  97. function onChangeSort({ prop, order }) {
  98. state.order = order == 'ascending' ? 'asc' : 'desc';
  99. state.sort = prop;
  100. getData();
  101. }
  102. function onOpenFilter() {
  103. state.filter.drawer = true
  104. }
  105. function onChangeFilter() {
  106. pagination.page = 1
  107. getData()
  108. state.filter.drawer && (state.filter.drawer = false)
  109. }
  110. const pagination = reactive({
  111. page: 1,
  112. list_rows: 10,
  113. total: 0,
  114. })
  115. const batchHandle = reactive({
  116. data: [],
  117. })
  118. function onChangeSelection(val) {
  119. batchHandle.data = val
  120. }
  121. function onBatchHandle(type) {
  122. let ids = []
  123. batchHandle.data.forEach((item) => {
  124. ids.push(item.id)
  125. })
  126. switch (type) {
  127. case 'delete':
  128. ElMessageBox.confirm('此操作将删除, 是否继续?', '提示', {
  129. confirmButtonText: '确定',
  130. cancelButtonText: '取消',
  131. type: 'warning',
  132. }).then(() => {
  133. onDelete(ids.join(','))
  134. });
  135. break;
  136. }
  137. }
  138. function onAdd() {
  139. Fast.api.open("shopro/data/fake_user/add?type=add", "添加", {
  140. callback() {
  141. getData()
  142. }
  143. })
  144. }
  145. function onEdit(id) {
  146. Fast.api.open(`shopro/data/fake_user/edit?type=edit&id=${id}`, "编辑", {
  147. callback() {
  148. getData()
  149. }
  150. })
  151. }
  152. function onDelete(id) {
  153. Fast.api.ajax({
  154. url: `shopro/data/fake_user/delete/id/${id}`,
  155. type: 'DELETE',
  156. }, function (ret, res) {
  157. getData()
  158. }, function (ret, res) { })
  159. }
  160. function onRandom() {
  161. Fast.api.open('shopro/data/fake_user/random', "自动生成", {
  162. callback() {
  163. getData()
  164. }
  165. })
  166. }
  167. onMounted(() => {
  168. getData()
  169. })
  170. return {
  171. Fast,
  172. state,
  173. getData,
  174. onChangeSort,
  175. onOpenFilter,
  176. onChangeFilter,
  177. pagination,
  178. batchHandle,
  179. onChangeSelection,
  180. onBatchHandle,
  181. onAdd,
  182. onEdit,
  183. onDelete,
  184. onRandom
  185. }
  186. }
  187. }
  188. createApp('index', index);
  189. },
  190. add: () => {
  191. Controller.form();
  192. },
  193. edit: () => {
  194. Controller.form();
  195. },
  196. form: () => {
  197. const { reactive, onMounted, getCurrentInstance } = Vue
  198. const addEdit = {
  199. setup() {
  200. const { proxy } = getCurrentInstance();
  201. const state = reactive({
  202. type: new URLSearchParams(location.search).get('type'),
  203. id: new URLSearchParams(location.search).get('id')
  204. })
  205. const form = reactive({
  206. model: {
  207. avatar: '',
  208. username: '',
  209. nickname: '',
  210. email: '',
  211. mobile: '',
  212. password: '',
  213. gender: 0,
  214. },
  215. rules: {
  216. avatar: [{ required: true, message: '请选择用户头像', trigger: 'blur' }],
  217. username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
  218. nickname: [{ required: true, message: '请输入用户昵称', trigger: 'blur' }],
  219. email: [{ required: true, message: '请输入电子邮箱', trigger: 'blur' }],
  220. mobile: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
  221. },
  222. })
  223. function getDetail() {
  224. Fast.api.ajax({
  225. url: `shopro/data/fake_user/detail/id/${state.id}`,
  226. type: 'GET',
  227. }, function (ret, res) {
  228. form.model = res.data;
  229. form.model.password = '';
  230. return false
  231. }, function (ret, res) { })
  232. }
  233. function onConfirm() {
  234. proxy.$refs['formRef'].validate((valid) => {
  235. if (valid) {
  236. Fast.api.ajax({
  237. url: state.type == 'add' ? 'shopro/data/fake_user/add' : `shopro/data/fake_user/edit/id/${state.id}`,
  238. type: 'POST',
  239. data: form.model,
  240. }, function (ret, res) {
  241. Fast.api.close()
  242. }, function (ret, res) { })
  243. }
  244. });
  245. }
  246. onMounted(() => {
  247. state.type == 'edit' && getDetail()
  248. })
  249. return {
  250. state,
  251. form,
  252. onConfirm
  253. }
  254. }
  255. }
  256. createApp('addEdit', addEdit);
  257. },
  258. select: function () {
  259. const { reactive, onMounted } = Vue
  260. const select = {
  261. setup() {
  262. const state = reactive({
  263. data: [],
  264. })
  265. function getData() {
  266. Fast.api.ajax({
  267. url: 'shopro/data/fake_user/select',
  268. type: 'GET',
  269. data: {
  270. page: pagination.page,
  271. list_rows: pagination.list_rows,
  272. },
  273. }, function (ret, res) {
  274. state.data = res.data.data
  275. pagination.total = res.data.total
  276. return false
  277. }, function (ret, res) { })
  278. }
  279. const pagination = reactive({
  280. page: 1,
  281. list_rows: 10,
  282. total: 0,
  283. })
  284. function onSelect(item) {
  285. Fast.api.close(item)
  286. }
  287. onMounted(() => {
  288. getData()
  289. })
  290. return {
  291. state,
  292. getData,
  293. pagination,
  294. onSelect
  295. }
  296. }
  297. }
  298. createApp('select', select);
  299. },
  300. random: () => {
  301. const { reactive, getCurrentInstance } = Vue
  302. const random = {
  303. setup() {
  304. const { proxy } = getCurrentInstance();
  305. const form = reactive({
  306. model: {
  307. num: 1,
  308. },
  309. rules: {
  310. num: [{ required: true, message: '请输入生成虚拟人数', trigger: 'blur' }],
  311. },
  312. })
  313. function onConfirm() {
  314. proxy.$refs['formRef'].validate((valid) => {
  315. if (valid) {
  316. Fast.api.ajax({
  317. url: 'shopro/data/fake_user/random',
  318. type: 'POST',
  319. data: JSON.parse(JSON.stringify(form.model))
  320. }, function (ret, res) {
  321. Fast.api.close()
  322. }, function (ret, res) { })
  323. }
  324. });
  325. }
  326. return {
  327. form,
  328. onConfirm
  329. }
  330. }
  331. }
  332. createApp('random', random);
  333. },
  334. };
  335. return Controller;
  336. });