page.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. })
  13. function getData() {
  14. Fast.api.ajax({
  15. url: 'shopro/data/page',
  16. type: 'GET',
  17. data: {
  18. page: pagination.page,
  19. list_rows: pagination.list_rows,
  20. order: state.order,
  21. sort: state.sort,
  22. },
  23. }, function (ret, res) {
  24. state.data = res.data.data
  25. pagination.total = res.data.total
  26. return false
  27. }, function (ret, res) { })
  28. }
  29. function onChangeSort({ prop, order }) {
  30. state.order = order == 'ascending' ? 'asc' : 'desc';
  31. state.sort = prop;
  32. getData();
  33. }
  34. const pagination = reactive({
  35. page: 1,
  36. list_rows: 10,
  37. total: 0,
  38. })
  39. const batchHandle = reactive({
  40. data: [],
  41. })
  42. function onChangeSelection(val) {
  43. batchHandle.data = val
  44. }
  45. function onBatchHandle(type) {
  46. let ids = []
  47. batchHandle.data.forEach((item) => {
  48. ids.push(item.id)
  49. })
  50. switch (type) {
  51. case 'delete':
  52. ElMessageBox.confirm('此操作将删除, 是否继续?', '提示', {
  53. confirmButtonText: '确定',
  54. cancelButtonText: '取消',
  55. type: 'warning',
  56. }).then(() => {
  57. onDelete(ids.join(','))
  58. });
  59. break;
  60. }
  61. }
  62. function onAdd() {
  63. Fast.api.open("shopro/data/page/add?type=add", "添加", {
  64. callback() {
  65. getData()
  66. }
  67. })
  68. }
  69. function onEdit(id) {
  70. Fast.api.open(`shopro/data/page/edit?type=edit&id=${id}`, "编辑", {
  71. callback() {
  72. getData()
  73. }
  74. })
  75. }
  76. function onDelete(id) {
  77. Fast.api.ajax({
  78. url: `shopro/data/page/delete/id/${id}`,
  79. type: 'DELETE',
  80. }, function (ret, res) {
  81. getData()
  82. }, function (ret, res) { })
  83. }
  84. onMounted(() => {
  85. getData()
  86. })
  87. return {
  88. state,
  89. getData,
  90. onChangeSort,
  91. pagination,
  92. batchHandle,
  93. onChangeSelection,
  94. onBatchHandle,
  95. onAdd,
  96. onEdit,
  97. onDelete
  98. }
  99. }
  100. }
  101. createApp('index', index);
  102. },
  103. add: () => {
  104. Controller.form();
  105. },
  106. edit: () => {
  107. Controller.form();
  108. },
  109. form: () => {
  110. const { reactive, onMounted, getCurrentInstance } = Vue
  111. const addEdit = {
  112. setup() {
  113. const { proxy } = getCurrentInstance();
  114. const state = reactive({
  115. type: new URLSearchParams(location.search).get('type'),
  116. id: new URLSearchParams(location.search).get('id')
  117. })
  118. const form = reactive({
  119. model: {
  120. name: '',
  121. path: '',
  122. group: '',
  123. },
  124. rules: {
  125. name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
  126. path: [{ required: true, message: '请输入路径', trigger: 'blur' }],
  127. group: [{ required: true, message: '请输入分组', trigger: 'blur' }],
  128. },
  129. })
  130. function getDetail() {
  131. Fast.api.ajax({
  132. url: `shopro/data/page/detail/id/${state.id}`,
  133. type: 'GET',
  134. }, function (ret, res) {
  135. form.model = res.data;
  136. return false
  137. }, function (ret, res) { })
  138. }
  139. function onConfirm() {
  140. proxy.$refs['formRef'].validate((valid) => {
  141. if (valid) {
  142. Fast.api.ajax({
  143. url: state.type == 'add' ? 'shopro/data/page/add' : `shopro/data/page/edit/id/${state.id}`,
  144. type: 'POST',
  145. data: form.model
  146. }, function (ret, res) {
  147. Fast.api.close()
  148. }, function (ret, res) { })
  149. }
  150. });
  151. }
  152. onMounted(() => {
  153. state.type == 'edit' && getDetail()
  154. })
  155. return {
  156. state,
  157. form,
  158. onConfirm
  159. }
  160. }
  161. }
  162. createApp('addEdit', addEdit);
  163. },
  164. select: () => {
  165. const { ref, reactive, onMounted, getCurrentInstance, nextTick } = Vue
  166. const select = {
  167. setup() {
  168. const { proxy } = getCurrentInstance();
  169. const state = reactive({
  170. data: [],
  171. height: [],
  172. currentIndex: 0,
  173. selected: {},
  174. });
  175. async function getSelect() {
  176. Fast.api.ajax({
  177. url: 'shopro/data/page/select',
  178. type: 'GET',
  179. }, function (ret, res) {
  180. state.data = res.data;
  181. nextTick(() => {
  182. getHeight();
  183. });
  184. return false
  185. }, function (ret, res) { })
  186. }
  187. function onChangeIndex(index) {
  188. proxy.$refs.rightScrollRef.setScrollTop(state.height[index]);
  189. state.currentIndex = index;
  190. }
  191. function onRightScroll(e) {
  192. let index = state.height.findIndex((item) => {
  193. return item > e.scrollTop;
  194. });
  195. if (index > 0) {
  196. state.currentIndex = index - 1;
  197. } else if (index == -1) {
  198. state.currentIndex = state.height.length - 1;
  199. }
  200. }
  201. function onSelect(link) {
  202. state.selected = { ...link };
  203. if (link.path == '/pages/index/page') {
  204. Fast.api.open('shopro/decorate/template/select', "选择自定义页面", {
  205. callback(data) {
  206. state.selected.path += (!isEmpty(data.id) ? '?id=' + data.id : '');
  207. }
  208. })
  209. } else if (link.path == '/pages/goods/index') {
  210. Fast.api.open('shopro/goods/goods/select', "选择商品", {
  211. callback(data) {
  212. state.selected.path += (!isEmpty(data.id) ? '?id=' + data.id : '');
  213. }
  214. })
  215. } else if (link.path == '/pages/index/category') {
  216. Fast.api.open('shopro/category/select?from=page-category', "选择分类", {
  217. callback(data) {
  218. state.selected.path += (!isEmpty(data.ids) ? '?id=' + data.ids : '');
  219. }
  220. })
  221. } else if (link.path == '/pages/goods/list') {
  222. Fast.api.open('shopro/category/select?from=page-goods', "选择分类", {
  223. callback(data) {
  224. state.selected.path += (!isEmpty(data.ids) ? '?categoryId=' + data.ids : '');
  225. }
  226. })
  227. } else if (link.path == '/pages/public/richtext') {
  228. Fast.api.open('shopro/data/richtext/select', "选择富文本", {
  229. callback(data) {
  230. state.selected.path += (!isEmpty(data.id) ? '?id=' + data.id : '');
  231. }
  232. })
  233. } else if (
  234. link.path == '/pages/activity/groupon/list' ||
  235. link.path == '/pages/activity/seckill/list'
  236. ) {
  237. let activityType = {
  238. groupon: 'groupon,groupon_ladder',
  239. seckill: 'seckill',
  240. };
  241. Fast.api.open(`shopro/activity/activity/select?type=${activityType[link.path.split('/')[3]]}`, "选择活动", {
  242. callback(data) {
  243. state.selected.path += (!isEmpty(data.id) ? '?id=' + data.id : '');
  244. }
  245. })
  246. } else if (link.path == '/pages/goods/groupon' || link.path == '/pages/goods/seckill') {
  247. let activityType = {
  248. groupon: 'groupon,groupon_ladder',
  249. seckill: 'seckill',
  250. };
  251. Fast.api.open(`shopro/activity/activity/select?type=${activityType[link.path.split('/').pop()]}`, "选择活动", {
  252. callback(data) {
  253. state.selected.path += (!isEmpty(data.id) ? '?activity_id=' + data.id : '');
  254. Fast.api.open(`shopro/goods/goods/select?goods_ids=${data.goods_ids}`, "选择商品", {
  255. callback(data) {
  256. state.selected.path += (!isEmpty(data.id) ? '&id=' + data.id : '');
  257. }
  258. })
  259. }
  260. })
  261. } else if (link.path == '/pages/goods/score') {
  262. Fast.api.open(`shopro/app/score_shop/select`, "选择积分商品", {
  263. callback(data) {
  264. state.selected.path += (!isEmpty(data.id) ? '?id=' + data.id : '');
  265. }
  266. })
  267. } else if (link.path == '/pages/coupon/detail') {
  268. Fast.api.open(`shopro/coupon/select?status=normal`, "选择优惠券", {
  269. callback(data) {
  270. state.selected.path += (!isEmpty(data.id) ? '?id=' + data.id : '');
  271. }
  272. })
  273. }
  274. }
  275. const rightRef = {};
  276. function setRightRef(el, item, index) {
  277. rightRef[item.group + index] = el;
  278. }
  279. function getHeight() {
  280. state.height = [];
  281. for (let e in rightRef) {
  282. state.height.push(rightRef[e].offsetTop);
  283. }
  284. }
  285. const platformUrl = ref({});
  286. function getPlatformUrl() {
  287. Fast.api.ajax({
  288. url: 'shopro/config/getPlatformUrl',
  289. type: 'GET',
  290. }, function (ret, res) {
  291. platformUrl.value = res.data
  292. return false
  293. }, function (ret, res) { })
  294. }
  295. async function onConfirm() {
  296. state.selected.fullPath = {
  297. url: `${platformUrl.value.url.endsWith('/')
  298. ? platformUrl.value.url.substr(0, platformUrl.value.url.length - 1)
  299. : platformUrl.value.url
  300. }${state.selected.path}`,
  301. appid: platformUrl.value.appid,
  302. pagepath: state.selected.path
  303. ? '/pages/index/index?page=' + encodeURIComponent(state.selected.path)
  304. : '/pages/index/index',
  305. };
  306. Fast.api.close(state.selected)
  307. }
  308. onMounted(() => {
  309. getSelect();
  310. getPlatformUrl();
  311. });
  312. return {
  313. state,
  314. getSelect,
  315. onRightScroll,
  316. onChangeIndex,
  317. onSelect,
  318. rightRef,
  319. setRightRef,
  320. getHeight,
  321. platformUrl,
  322. getPlatformUrl,
  323. onConfirm,
  324. }
  325. }
  326. }
  327. createApp('select', select);
  328. }
  329. };
  330. return Controller;
  331. });