richtext.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. keyword: '',
  16. },
  17. tools: {
  18. keyword: {
  19. type: 'tinput',
  20. label: '查询内容',
  21. placeholder: '请输入查询内容',
  22. value: '',
  23. },
  24. },
  25. condition: {},
  26. }
  27. })
  28. function getData() {
  29. let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
  30. let search = composeFilter(tempSearch, {
  31. keyword: 'like',
  32. });
  33. Fast.api.ajax({
  34. url: 'shopro/data/richtext',
  35. type: 'GET',
  36. data: {
  37. page: pagination.page,
  38. list_rows: pagination.list_rows,
  39. order: state.order,
  40. sort: state.sort,
  41. ...search,
  42. },
  43. }, function (ret, res) {
  44. state.data = res.data.data
  45. pagination.total = res.data.total
  46. return false
  47. }, function (ret, res) { })
  48. }
  49. function onChangeSort({ prop, order }) {
  50. state.order = order == 'ascending' ? 'asc' : 'desc';
  51. state.sort = prop;
  52. getData();
  53. }
  54. function onOpenFilter() {
  55. state.filter.drawer = true
  56. }
  57. function onChangeFilter() {
  58. pagination.page = 1
  59. getData()
  60. state.filter.drawer && (state.filter.drawer = false)
  61. }
  62. const pagination = reactive({
  63. page: 1,
  64. list_rows: 10,
  65. total: 0,
  66. })
  67. const batchHandle = reactive({
  68. data: [],
  69. })
  70. function onChangeSelection(val) {
  71. batchHandle.data = val
  72. }
  73. function onBatchHandle(type) {
  74. let ids = []
  75. batchHandle.data.forEach((item) => {
  76. ids.push(item.id)
  77. })
  78. switch (type) {
  79. case 'delete':
  80. ElMessageBox.confirm('此操作将删除, 是否继续?', '提示', {
  81. confirmButtonText: '确定',
  82. cancelButtonText: '取消',
  83. type: 'warning',
  84. }).then(() => {
  85. onDelete(ids.join(','))
  86. });
  87. break;
  88. }
  89. }
  90. function onAdd() {
  91. Fast.api.open("shopro/data/richtext/add?type=add", "添加", {
  92. callback() {
  93. getData()
  94. }
  95. })
  96. }
  97. function onEdit(id) {
  98. Fast.api.open(`shopro/data/richtext/edit?type=edit&id=${id}`, "编辑", {
  99. callback() {
  100. getData()
  101. }
  102. })
  103. }
  104. function onDelete(id) {
  105. Fast.api.ajax({
  106. url: `shopro/data/richtext/delete/id/${id}`,
  107. type: 'DELETE',
  108. }, function (ret, res) {
  109. getData()
  110. }, function (ret, res) { })
  111. }
  112. onMounted(() => {
  113. getData()
  114. })
  115. return {
  116. state,
  117. getData,
  118. onChangeSort,
  119. onOpenFilter,
  120. onChangeFilter,
  121. pagination,
  122. batchHandle,
  123. onChangeSelection,
  124. onBatchHandle,
  125. onAdd,
  126. onEdit,
  127. onDelete
  128. }
  129. }
  130. }
  131. createApp('index', index);
  132. },
  133. add: () => {
  134. Controller.form();
  135. },
  136. edit: () => {
  137. Controller.form();
  138. },
  139. form: () => {
  140. const { reactive, onMounted, getCurrentInstance, nextTick } = Vue
  141. const addEdit = {
  142. setup() {
  143. const { proxy } = getCurrentInstance();
  144. const state = reactive({
  145. type: new URLSearchParams(location.search).get('type'),
  146. id: new URLSearchParams(location.search).get('id')
  147. })
  148. const form = reactive({
  149. model: {
  150. title: '',
  151. content: '',
  152. },
  153. rules: {
  154. title: [{ required: true, message: '请输入标题', trigger: 'blur' }],
  155. content: [{ required: true, message: '请输入内容', trigger: 'blur' }],
  156. },
  157. })
  158. function getDetail() {
  159. Fast.api.ajax({
  160. url: `shopro/data/richtext/detail/id/${state.id}`,
  161. type: 'GET',
  162. }, function (ret, res) {
  163. form.model = res.data;
  164. nextTick(() => {
  165. Controller.api.bindevent();
  166. $('#richtextContent').html(form.model.content)
  167. })
  168. return false
  169. }, function (ret, res) { })
  170. }
  171. function onConfirm() {
  172. form.model.content = $("#richtextContent").val()
  173. proxy.$refs['formRef'].validate((valid) => {
  174. if (valid) {
  175. Fast.api.ajax({
  176. url: state.type == 'add' ? 'shopro/data/richtext/add' : `shopro/data/richtext/edit/id/${state.id}`,
  177. type: 'POST',
  178. data: form.model,
  179. }, function (ret, res) {
  180. Fast.api.close()
  181. }, function (ret, res) { })
  182. }
  183. });
  184. }
  185. onMounted(() => {
  186. if (state.type == 'add') {
  187. nextTick(() => {
  188. Controller.api.bindevent();
  189. })
  190. } else if (state.type == 'edit') {
  191. getDetail()
  192. }
  193. })
  194. return {
  195. state,
  196. form,
  197. onConfirm
  198. }
  199. }
  200. }
  201. createApp('addEdit', addEdit);
  202. },
  203. select: () => {
  204. const { reactive, onMounted } = Vue
  205. const select = {
  206. setup() {
  207. const state = reactive({
  208. data: [],
  209. order: '',
  210. sort: '',
  211. })
  212. function getData() {
  213. Fast.api.ajax({
  214. url: 'shopro/data/richtext/select',
  215. type: 'GET',
  216. data: {
  217. page: pagination.page,
  218. list_rows: pagination.list_rows,
  219. order: state.order,
  220. sort: state.sort,
  221. },
  222. }, function (ret, res) {
  223. state.data = res.data.data
  224. pagination.total = res.data.total
  225. return false
  226. }, function (ret, res) { })
  227. }
  228. function onChangeSort({ prop, order }) {
  229. state.order = order == 'ascending' ? 'asc' : 'desc';
  230. state.sort = prop;
  231. getData();
  232. }
  233. const pagination = reactive({
  234. page: 1,
  235. list_rows: 10,
  236. total: 0,
  237. })
  238. function onAdd() {
  239. Fast.api.open("shopro/data/richtext/add?type=add", "添加", {
  240. callback() {
  241. getData()
  242. }
  243. })
  244. }
  245. function onSelect(item) {
  246. Fast.api.close(item)
  247. }
  248. onMounted(() => {
  249. getData()
  250. })
  251. return {
  252. state,
  253. getData,
  254. onChangeSort,
  255. pagination,
  256. onAdd,
  257. onSelect
  258. }
  259. }
  260. }
  261. createApp('select', select);
  262. },
  263. api: {
  264. bindevent: function () {
  265. Form.api.bindevent($("form[role=form]"));
  266. }
  267. },
  268. };
  269. return Controller;
  270. });